metadata: erddap_precip.yml

Published

2026-01-08 19:47 UTC

Code
# dir_extractr = "/share/github/marinebon/extractr"
# dir_extractr = "~/Github/marinebon/extractr" # DEBUG
# devtools::load_all(dir_extractr)
# devtools::install_local(dir_extractr, force = T)
# devtools::install_github("marinebon/extractr", force = T)
librarian::shelf(
  dplyr, DT, fs, glue, here, logger, lubridate, mapview, purrr, RColorBrewer, readr, 
  sf, stringr, terra, tibble, tidyr, units, yaml,
  marinebon/extractr,
  quiet = T)

options(readr.show_col_types = F)
mapviewOptions(
  basemaps       = "Esri.OceanBasemap",
  vector.palette = colorRampPalette(brewer.pal(n=5, name="Spectral")))

if (!exists("params"))
  # params <- list(yml = here("meta/erddap_sst.yml")) # DEBUG
  params <- list(yml = here("meta/erddap_precip.yml")) # DEBUG

1 Polygons

Code
sanctuaries_rds <- here("../climate-dashboard/data/sanctuaries.rds")
buf_pct         <- 0.20 # 20% of area

ply_sanctuaries <- readRDS(sanctuaries_rds)

# buffer polygon and get bounding boxes
ply_sanctuaries <- ply_sanctuaries |>
  mutate(
    area_km2  = st_area(geom) |> 
      set_units("km^2") |> 
      as.numeric() |> 
      round(2),
    buf_km    = (sqrt(area_km2) * buf_pct) |> 
      round(2),
    bbox_geom = map2(geom, area_km2, \(g,a) {
      st_sfc(g, crs = 4326) |> 
        st_buffer(buf_km * 1000) |> 
        st_bbox() |>
        round(2) |> 
        st_as_sfc() }),
    bbox_chr  = map_chr(bbox_geom, \(x) {  # xmin, ymin, xmax and ymax
      st_bbox(x) |> 
        as.numeric() |> 
        paste(collapse = ",") } ) ) |> 
  unnest(bbox_geom)
bb_sanctuaries <- st_set_geometry(ply_sanctuaries, "bbox_geom") |> 
  select(-geom)
ply_sanctuaries <- select(ply_sanctuaries, -bbox_geom)

# show map
mapView(ply_sanctuaries, zcol = "nms") +
  mapView(bb_sanctuaries, zcol = "nms", legend = F)
Code
ply_sanctuaries |>
  st_drop_geometry() |>
  datatable()

2 Dataset

2.1 Metadata

Contents of erddap_precip.yml:

Code
cat(
  "```yaml",
  readLines(params$yml),
  "```",
  sep = "\n")
erddap_url: https://erddap.marine.usf.edu/erddap/griddap/IMERG_monthly_global_precip.html
erddap_variable: precipitation
# [iterate_ed_extract]
# 001: CBNMS, 1998-01-01 to 1998-12-01
# ERROR: [raster,matrix(xyz)] x cell sizes are not regular

2.2 Information

Code
meta <- read_yaml(params$yml) 
proc_prod <- path_ext_remove(basename(params$yml))

is_server <- Sys.info()["sysname"] == "Linux"
dir_out <- ifelse(
  is_server,
  glue("/share/data/noaa-onms/climate-dashboard-app/{proc_prod}"),
  here(glue("data_local/{proc_prod}")))
dir_create(dir_out)

v     <- meta$erddap_variable
(ed   <- ed_info(meta$erddap_url))
<ERDDAP info> IMERG_monthly_global_precip 
 Base URL: https://erddap.marine.usf.edu/erddap 
 Dataset Type: griddap 
 Dimensions (range):  
     time: (1998-01-01T00:00:00Z, 2025-07-01T00:00:00Z) 
     latitude: (-89.95, 89.95) 
     longitude: (-179.95, 179.95) 
 Variables:  
     precipitation: 
         Units: mm 
     precipitationQualityIndex: 
         Units: none 
     randomError: 
         Units: mm 
Code
times <- ed_dim(ed, "time")

3 Polygon years

Code
d_nms_yr_todo <- ply_sanctuaries |> 
  st_drop_geometry() |> 
  arrange(nms) |> 
  select(nms) |> 
  cross_join(
    tibble(
      year = year(min(times)):year(max(times)))) |> 
  mutate(
    d = map2(nms, year, \(nms, year) { # nms = "CBNMS"; year = 2025
      
      times_yr <- times[year(times) == year]
      tif      <- glue("{dir_out}/{nms}/{year}.tif")
      
      # if missing tif,return all times
      if (!file.exists(tif))
        return(list(
          time_min = min(times_yr),
          time_max = max(times_yr),
          n_times  = length(times_yr)))
      
      # get times from tif
      r <- rast(tif)
      times_tif <- time(r)
      
      # if all times done, return NAs
      if (all(times_yr %in% times_tif))
        return(list(
          n_times  = 0,
          time_min = NA,
          time_max= NA)) 
      
      # otherwise, return time range missing
      i <- !times_yr %in% times_tif
      list(
          n_times  = sum(i),
          time_min = min(times_yr[i]),
          time_max = max(times_yr[i])) 
      }),
    time_min = map_vec(d, pluck, "time_min"),
    time_max = map_vec(d, pluck, "time_max"),
    n_times  = map_int(d, pluck, "n_times") ) |> 
  select(-d) |> 
  filter(n_times > 0) |> 
  rowid_to_column("i") |>
  relocate(i)

d_nms_yr_todo |> 
  group_by(nms) %>%
  {if (nrow(.) > 0)
    summarize(
      .,
      time_min = min(time_min, na.rm = T),
      time_max = max(time_max, na.rm = T),
      n_times  = sum(n_times)) else .} |>
  datatable(
    caption  = "Sanctuaries missing available ERDDAP times.",
    rownames = F,
    options  = list(
      pageLength = 5,
      lengthMenu = c(5, 50, nrow(d_nms_yr_todo))))

4 Extract dataset per polygon year

Using extractr::ed_extract(), .

Code
# rerddap::cache_delete_all()

fxn <- function(i, nms, time_min, time_max, ...){ 
  #  i = 1; nms = "CBNMS"; time_min = as.POSIXct("1998-01-01 UTC");  time_max = as.POSIXct("1998-12-01 UTC")
  
  err <- tryCatch({
    
    log_info("{sprintf('%03d', i)}: {nms}, {time_min} to {time_max}")
    
    yr <- year(time_min)

    ply <- ply_sanctuaries |>
      filter(nms == !!nms)
    bb <- bb_sanctuaries |>
      filter(nms == !!nms) |> 
      st_bbox()
    
    # browser()
    # devtools::load_all("~/Github/marinebon/extractr")
    
    extractr::ed_extract(
      ed,
      var       = v,
      sf_zones  = ply,
      bbox      = bb,
      mask_tif  = F,
      rast_tif  = glue("{dir_out}/{nms}/{yr}.tif"),
      zonal_fun = "mean",
      zonal_csv = glue("{dir_out}/{nms}/{yr}.csv"),
      dir_nc    = glue("{dir_out}/{nms}/{yr}_nc"),
      keep_nc   = F,
      n_max_vals_per_req = 1e+05,
      time_min  = time_min,
      time_max  = time_max,
      verbose   = T)
    
    return(NA)
  }, error = function(e) {
    
    log_error(conditionMessage(e))
    return(conditionMessage(e))
  })
  
  err
} 

res <- d_nms_yr_todo |> 
  mutate(
    error = pmap_chr(list(i, nms, time_min, time_max), fxn))
Downloading 1 requests, up to 490 time slices each
Called from: extractr::ed_extract(ed, var = v, sf_zones = ply, bbox = bb, 
    mask_tif = F, rast_tif = glue("{dir_out}/{nms}/{yr}.tif"), 
    zonal_fun = "mean", zonal_csv = glue("{dir_out}/{nms}/{yr}.csv"), 
    dir_nc = glue("{dir_out}/{nms}/{yr}_nc"), keep_nc = F, n_max_vals_per_req = 1e+05, 
    time_min = time_min, time_max = time_max, verbose = T)
debug: while (i_req <= n_reqs) {
    i_t_beg <- (i_req - 1) * n_t_per_req + 1
    i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
    t_req <- times_todo[c(i_t_beg, i_t_end)]
    t_req_str <- format_ISO8601(t_req, usetz = "Z")
    if (verbose) 
        message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
    ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
        ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
        0), nc)
    unlink(ncs0)
    nc_retry <- T
    nc_n_try <- 1
    n_max_retries
    while (nc_retry) {
        res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
            url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
                bbox[["xmax"]]), latitude = c(bbox[["ymin"]], 
                bbox[["ymax"]]), time = t_req_str, fmt = "nc", 
            store = rerddap::disk(path = dir_nc)))
        if (inherits(res, "try-error")) {
            err <- attr(res, "condition")
            msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
            nc_n_try <- nc_n_try + 1
            if (nc_n_try > n_max_retries) {
                stop(msg)
            }
            else {
                message(msg, "\nRETRYing...")
                Sys.sleep(1)
            }
        }
        else {
            nc_retry <- F
        }
    }
    i_req <- i_req + 1
}
debug: i_t_beg <- (i_req - 1) * n_t_per_req + 1
debug: i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
debug: t_req <- times_todo[c(i_t_beg, i_t_end)]
debug: t_req_str <- format_ISO8601(t_req, usetz = "Z")
debug: if (verbose) message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
debug: message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
Fetching request 1 of 1 (1998-01-01 to 1998-12-01) ~ 19:31:06 UTC
debug: ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
    0), nc)
debug: unlink(ncs0)
debug: nc_retry <- T
debug: nc_n_try <- 1
debug: n_max_retries
debug: while (nc_retry) {
    res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
        url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
            bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
        time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
    if (inherits(res, "try-error")) {
        err <- attr(res, "condition")
        msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
        nc_n_try <- nc_n_try + 1
        if (nc_n_try > n_max_retries) {
            stop(msg)
        }
        else {
            message(msg, "\nRETRYing...")
            Sys.sleep(1)
        }
    }
    else {
        nc_retry <- F
    }
}
debug: res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
    url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
        bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
    time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
debug: if (inherits(res, "try-error")) {
    err <- attr(res, "condition")
    msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
    nc_n_try <- nc_n_try + 1
    if (nc_n_try > n_max_retries) {
        stop(msg)
    }
    else {
        message(msg, "\nRETRYing...")
        Sys.sleep(1)
    }
} else {
    nc_retry <- F
}
debug: nc_retry <- F
debug: (while) nc_retry
debug: i_req <- i_req + 1
debug: (while) i_req <= n_reqs
debug: ncs <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size > 
    0), nc)
debug: r <- terra::rast(ncs)
debug: stopifnot(all(class(terra::time(r)) %in% c("POSIXct", "POSIXt")))
debug: idx <- dplyr::pull(dplyr::filter(dplyr::arrange(dplyr::tibble(idx = 1:terra::nlyr(r), 
    time = terra::time(r)), time), !duplicated(time)), idx)
debug: r <- terra::subset(r, idx)
debug: stopifnot(terra::crs(r, proj = T) == wgs84)
debug: if (mask_tif) r <- terra::mask(r, sf_zones)
debug: lyrs <- glue("{var}|{terra::time(r)}")
debug: if (length(dims_other) > 0 && !all(length(dims[dims_other]) == 
    1)) stop(glue("Other dimensions not yet supported: {paste(dims_other, collapse = ',')}"))
debug: names(r) <- lyrs
debug: if (!is.null(rast_tif)) {
    if (fs::file_exists(rast_tif)) {
        r_tmp_tif <- tempfile(fileext = ".tif")
        r_tmp <- c(rast(rast_tif), r)
        r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
        terra::writeRaster(r_tmp, r_tmp_tif)
        fs::file_delete(rast_tif)
        fs::file_move(r_tmp_tif, rast_tif)
        rm(r)
        rm(r_tmp)
    }
    else {
        terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
    }
    r <- terra::rast(rast_tif)
}
debug: if (fs::file_exists(rast_tif)) {
    r_tmp_tif <- tempfile(fileext = ".tif")
    r_tmp <- c(rast(rast_tif), r)
    r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
    terra::writeRaster(r_tmp, r_tmp_tif)
    fs::file_delete(rast_tif)
    fs::file_move(r_tmp_tif, rast_tif)
    rm(r)
    rm(r_tmp)
} else {
    terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
}
debug: terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
debug: r <- terra::rast(rast_tif)
debug: d_r <- mutate(tidyr::pivot_longer(sf::st_drop_geometry(sf::st_as_sf(terra::zonal(x = r, 
    z = terra::vect(dplyr::select(sf_zones, dplyr::all_of(fld_zones))), 
    fun = zonal_fun, exact = T, na.rm = T, as.polygons = T))), 
    cols = -dplyr::any_of(fld_zones), names_to = "lyr", values_to = zonal_fun), 
    time = readr::parse_datetime(str_replace(lyr, glue("{var}\\|(.*)"), 
        "\\1")))
debug: if (!is.null(zonal_csv)) write_csv(d_r, zonal_csv)
debug: write_csv(d_r, zonal_csv)
debug: if (!keep_nc) unlink(dir_nc, recursive = T)
debug: unlink(dir_nc, recursive = T)
debug: return(d_r)
Downloading 1 requests, up to 490 time slices each
Called from: extractr::ed_extract(ed, var = v, sf_zones = ply, bbox = bb, 
    mask_tif = F, rast_tif = glue("{dir_out}/{nms}/{yr}.tif"), 
    zonal_fun = "mean", zonal_csv = glue("{dir_out}/{nms}/{yr}.csv"), 
    dir_nc = glue("{dir_out}/{nms}/{yr}_nc"), keep_nc = F, n_max_vals_per_req = 1e+05, 
    time_min = time_min, time_max = time_max, verbose = T)
debug: while (i_req <= n_reqs) {
    i_t_beg <- (i_req - 1) * n_t_per_req + 1
    i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
    t_req <- times_todo[c(i_t_beg, i_t_end)]
    t_req_str <- format_ISO8601(t_req, usetz = "Z")
    if (verbose) 
        message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
    ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
        ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
        0), nc)
    unlink(ncs0)
    nc_retry <- T
    nc_n_try <- 1
    n_max_retries
    while (nc_retry) {
        res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
            url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
                bbox[["xmax"]]), latitude = c(bbox[["ymin"]], 
                bbox[["ymax"]]), time = t_req_str, fmt = "nc", 
            store = rerddap::disk(path = dir_nc)))
        if (inherits(res, "try-error")) {
            err <- attr(res, "condition")
            msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
            nc_n_try <- nc_n_try + 1
            if (nc_n_try > n_max_retries) {
                stop(msg)
            }
            else {
                message(msg, "\nRETRYing...")
                Sys.sleep(1)
            }
        }
        else {
            nc_retry <- F
        }
    }
    i_req <- i_req + 1
}
debug: i_t_beg <- (i_req - 1) * n_t_per_req + 1
debug: i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
debug: t_req <- times_todo[c(i_t_beg, i_t_end)]
debug: t_req_str <- format_ISO8601(t_req, usetz = "Z")
debug: if (verbose) message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
debug: message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
Fetching request 1 of 1 (1999-01-01 to 1999-12-01) ~ 19:31:09 UTC
debug: ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
    0), nc)
debug: unlink(ncs0)
debug: nc_retry <- T
debug: nc_n_try <- 1
debug: n_max_retries
debug: while (nc_retry) {
    res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
        url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
            bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
        time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
    if (inherits(res, "try-error")) {
        err <- attr(res, "condition")
        msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
        nc_n_try <- nc_n_try + 1
        if (nc_n_try > n_max_retries) {
            stop(msg)
        }
        else {
            message(msg, "\nRETRYing...")
            Sys.sleep(1)
        }
    }
    else {
        nc_retry <- F
    }
}
debug: res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
    url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
        bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
    time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
debug: if (inherits(res, "try-error")) {
    err <- attr(res, "condition")
    msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
    nc_n_try <- nc_n_try + 1
    if (nc_n_try > n_max_retries) {
        stop(msg)
    }
    else {
        message(msg, "\nRETRYing...")
        Sys.sleep(1)
    }
} else {
    nc_retry <- F
}
debug: nc_retry <- F
debug: (while) nc_retry
debug: i_req <- i_req + 1
debug: (while) i_req <= n_reqs
debug: ncs <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size > 
    0), nc)
debug: r <- terra::rast(ncs)
debug: stopifnot(all(class(terra::time(r)) %in% c("POSIXct", "POSIXt")))
debug: idx <- dplyr::pull(dplyr::filter(dplyr::arrange(dplyr::tibble(idx = 1:terra::nlyr(r), 
    time = terra::time(r)), time), !duplicated(time)), idx)
debug: r <- terra::subset(r, idx)
debug: stopifnot(terra::crs(r, proj = T) == wgs84)
debug: if (mask_tif) r <- terra::mask(r, sf_zones)
debug: lyrs <- glue("{var}|{terra::time(r)}")
debug: if (length(dims_other) > 0 && !all(length(dims[dims_other]) == 
    1)) stop(glue("Other dimensions not yet supported: {paste(dims_other, collapse = ',')}"))
debug: names(r) <- lyrs
debug: if (!is.null(rast_tif)) {
    if (fs::file_exists(rast_tif)) {
        r_tmp_tif <- tempfile(fileext = ".tif")
        r_tmp <- c(rast(rast_tif), r)
        r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
        terra::writeRaster(r_tmp, r_tmp_tif)
        fs::file_delete(rast_tif)
        fs::file_move(r_tmp_tif, rast_tif)
        rm(r)
        rm(r_tmp)
    }
    else {
        terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
    }
    r <- terra::rast(rast_tif)
}
debug: if (fs::file_exists(rast_tif)) {
    r_tmp_tif <- tempfile(fileext = ".tif")
    r_tmp <- c(rast(rast_tif), r)
    r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
    terra::writeRaster(r_tmp, r_tmp_tif)
    fs::file_delete(rast_tif)
    fs::file_move(r_tmp_tif, rast_tif)
    rm(r)
    rm(r_tmp)
} else {
    terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
}
debug: terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
debug: r <- terra::rast(rast_tif)
debug: d_r <- mutate(tidyr::pivot_longer(sf::st_drop_geometry(sf::st_as_sf(terra::zonal(x = r, 
    z = terra::vect(dplyr::select(sf_zones, dplyr::all_of(fld_zones))), 
    fun = zonal_fun, exact = T, na.rm = T, as.polygons = T))), 
    cols = -dplyr::any_of(fld_zones), names_to = "lyr", values_to = zonal_fun), 
    time = readr::parse_datetime(str_replace(lyr, glue("{var}\\|(.*)"), 
        "\\1")))
debug: if (!is.null(zonal_csv)) write_csv(d_r, zonal_csv)
debug: write_csv(d_r, zonal_csv)
debug: if (!keep_nc) unlink(dir_nc, recursive = T)
debug: unlink(dir_nc, recursive = T)
debug: return(d_r)
Downloading 1 requests, up to 490 time slices each
Called from: extractr::ed_extract(ed, var = v, sf_zones = ply, bbox = bb, 
    mask_tif = F, rast_tif = glue("{dir_out}/{nms}/{yr}.tif"), 
    zonal_fun = "mean", zonal_csv = glue("{dir_out}/{nms}/{yr}.csv"), 
    dir_nc = glue("{dir_out}/{nms}/{yr}_nc"), keep_nc = F, n_max_vals_per_req = 1e+05, 
    time_min = time_min, time_max = time_max, verbose = T)
debug: while (i_req <= n_reqs) {
    i_t_beg <- (i_req - 1) * n_t_per_req + 1
    i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
    t_req <- times_todo[c(i_t_beg, i_t_end)]
    t_req_str <- format_ISO8601(t_req, usetz = "Z")
    if (verbose) 
        message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
    ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
        ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
        0), nc)
    unlink(ncs0)
    nc_retry <- T
    nc_n_try <- 1
    n_max_retries
    while (nc_retry) {
        res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
            url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
                bbox[["xmax"]]), latitude = c(bbox[["ymin"]], 
                bbox[["ymax"]]), time = t_req_str, fmt = "nc", 
            store = rerddap::disk(path = dir_nc)))
        if (inherits(res, "try-error")) {
            err <- attr(res, "condition")
            msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
            nc_n_try <- nc_n_try + 1
            if (nc_n_try > n_max_retries) {
                stop(msg)
            }
            else {
                message(msg, "\nRETRYing...")
                Sys.sleep(1)
            }
        }
        else {
            nc_retry <- F
        }
    }
    i_req <- i_req + 1
}
debug: i_t_beg <- (i_req - 1) * n_t_per_req + 1
debug: i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
debug: t_req <- times_todo[c(i_t_beg, i_t_end)]
debug: t_req_str <- format_ISO8601(t_req, usetz = "Z")
debug: if (verbose) message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
debug: message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
Fetching request 1 of 1 (2000-01-01 to 2000-12-01) ~ 19:31:11 UTC
debug: ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
    0), nc)
debug: unlink(ncs0)
debug: nc_retry <- T
debug: nc_n_try <- 1
debug: n_max_retries
debug: while (nc_retry) {
    res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
        url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
            bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
        time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
    if (inherits(res, "try-error")) {
        err <- attr(res, "condition")
        msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
        nc_n_try <- nc_n_try + 1
        if (nc_n_try > n_max_retries) {
            stop(msg)
        }
        else {
            message(msg, "\nRETRYing...")
            Sys.sleep(1)
        }
    }
    else {
        nc_retry <- F
    }
}
debug: res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
    url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
        bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
    time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
debug: if (inherits(res, "try-error")) {
    err <- attr(res, "condition")
    msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
    nc_n_try <- nc_n_try + 1
    if (nc_n_try > n_max_retries) {
        stop(msg)
    }
    else {
        message(msg, "\nRETRYing...")
        Sys.sleep(1)
    }
} else {
    nc_retry <- F
}
debug: nc_retry <- F
debug: (while) nc_retry
debug: i_req <- i_req + 1
debug: (while) i_req <= n_reqs
debug: ncs <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size > 
    0), nc)
debug: r <- terra::rast(ncs)
debug: stopifnot(all(class(terra::time(r)) %in% c("POSIXct", "POSIXt")))
debug: idx <- dplyr::pull(dplyr::filter(dplyr::arrange(dplyr::tibble(idx = 1:terra::nlyr(r), 
    time = terra::time(r)), time), !duplicated(time)), idx)
debug: r <- terra::subset(r, idx)
debug: stopifnot(terra::crs(r, proj = T) == wgs84)
debug: if (mask_tif) r <- terra::mask(r, sf_zones)
debug: lyrs <- glue("{var}|{terra::time(r)}")
debug: if (length(dims_other) > 0 && !all(length(dims[dims_other]) == 
    1)) stop(glue("Other dimensions not yet supported: {paste(dims_other, collapse = ',')}"))
debug: names(r) <- lyrs
debug: if (!is.null(rast_tif)) {
    if (fs::file_exists(rast_tif)) {
        r_tmp_tif <- tempfile(fileext = ".tif")
        r_tmp <- c(rast(rast_tif), r)
        r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
        terra::writeRaster(r_tmp, r_tmp_tif)
        fs::file_delete(rast_tif)
        fs::file_move(r_tmp_tif, rast_tif)
        rm(r)
        rm(r_tmp)
    }
    else {
        terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
    }
    r <- terra::rast(rast_tif)
}
debug: if (fs::file_exists(rast_tif)) {
    r_tmp_tif <- tempfile(fileext = ".tif")
    r_tmp <- c(rast(rast_tif), r)
    r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
    terra::writeRaster(r_tmp, r_tmp_tif)
    fs::file_delete(rast_tif)
    fs::file_move(r_tmp_tif, rast_tif)
    rm(r)
    rm(r_tmp)
} else {
    terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
}
debug: terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
debug: r <- terra::rast(rast_tif)
debug: d_r <- mutate(tidyr::pivot_longer(sf::st_drop_geometry(sf::st_as_sf(terra::zonal(x = r, 
    z = terra::vect(dplyr::select(sf_zones, dplyr::all_of(fld_zones))), 
    fun = zonal_fun, exact = T, na.rm = T, as.polygons = T))), 
    cols = -dplyr::any_of(fld_zones), names_to = "lyr", values_to = zonal_fun), 
    time = readr::parse_datetime(str_replace(lyr, glue("{var}\\|(.*)"), 
        "\\1")))
debug: if (!is.null(zonal_csv)) write_csv(d_r, zonal_csv)
debug: write_csv(d_r, zonal_csv)
debug: if (!keep_nc) unlink(dir_nc, recursive = T)
debug: unlink(dir_nc, recursive = T)
debug: return(d_r)
Downloading 1 requests, up to 490 time slices each
Called from: extractr::ed_extract(ed, var = v, sf_zones = ply, bbox = bb, 
    mask_tif = F, rast_tif = glue("{dir_out}/{nms}/{yr}.tif"), 
    zonal_fun = "mean", zonal_csv = glue("{dir_out}/{nms}/{yr}.csv"), 
    dir_nc = glue("{dir_out}/{nms}/{yr}_nc"), keep_nc = F, n_max_vals_per_req = 1e+05, 
    time_min = time_min, time_max = time_max, verbose = T)
debug: while (i_req <= n_reqs) {
    i_t_beg <- (i_req - 1) * n_t_per_req + 1
    i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
    t_req <- times_todo[c(i_t_beg, i_t_end)]
    t_req_str <- format_ISO8601(t_req, usetz = "Z")
    if (verbose) 
        message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
    ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
        ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
        0), nc)
    unlink(ncs0)
    nc_retry <- T
    nc_n_try <- 1
    n_max_retries
    while (nc_retry) {
        res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
            url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
                bbox[["xmax"]]), latitude = c(bbox[["ymin"]], 
                bbox[["ymax"]]), time = t_req_str, fmt = "nc", 
            store = rerddap::disk(path = dir_nc)))
        if (inherits(res, "try-error")) {
            err <- attr(res, "condition")
            msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
            nc_n_try <- nc_n_try + 1
            if (nc_n_try > n_max_retries) {
                stop(msg)
            }
            else {
                message(msg, "\nRETRYing...")
                Sys.sleep(1)
            }
        }
        else {
            nc_retry <- F
        }
    }
    i_req <- i_req + 1
}
debug: i_t_beg <- (i_req - 1) * n_t_per_req + 1
debug: i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
debug: t_req <- times_todo[c(i_t_beg, i_t_end)]
debug: t_req_str <- format_ISO8601(t_req, usetz = "Z")
debug: if (verbose) message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
debug: message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
Fetching request 1 of 1 (2001-01-01 to 2001-12-01) ~ 19:31:13 UTC
debug: ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
    0), nc)
debug: unlink(ncs0)
debug: nc_retry <- T
debug: nc_n_try <- 1
debug: n_max_retries
debug: while (nc_retry) {
    res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
        url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
            bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
        time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
    if (inherits(res, "try-error")) {
        err <- attr(res, "condition")
        msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
        nc_n_try <- nc_n_try + 1
        if (nc_n_try > n_max_retries) {
            stop(msg)
        }
        else {
            message(msg, "\nRETRYing...")
            Sys.sleep(1)
        }
    }
    else {
        nc_retry <- F
    }
}
debug: res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
    url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
        bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
    time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
debug: if (inherits(res, "try-error")) {
    err <- attr(res, "condition")
    msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
    nc_n_try <- nc_n_try + 1
    if (nc_n_try > n_max_retries) {
        stop(msg)
    }
    else {
        message(msg, "\nRETRYing...")
        Sys.sleep(1)
    }
} else {
    nc_retry <- F
}
debug: nc_retry <- F
debug: (while) nc_retry
debug: i_req <- i_req + 1
debug: (while) i_req <= n_reqs
debug: ncs <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size > 
    0), nc)
debug: r <- terra::rast(ncs)
debug: stopifnot(all(class(terra::time(r)) %in% c("POSIXct", "POSIXt")))
debug: idx <- dplyr::pull(dplyr::filter(dplyr::arrange(dplyr::tibble(idx = 1:terra::nlyr(r), 
    time = terra::time(r)), time), !duplicated(time)), idx)
debug: r <- terra::subset(r, idx)
debug: stopifnot(terra::crs(r, proj = T) == wgs84)
debug: if (mask_tif) r <- terra::mask(r, sf_zones)
debug: lyrs <- glue("{var}|{terra::time(r)}")
debug: if (length(dims_other) > 0 && !all(length(dims[dims_other]) == 
    1)) stop(glue("Other dimensions not yet supported: {paste(dims_other, collapse = ',')}"))
debug: names(r) <- lyrs
debug: if (!is.null(rast_tif)) {
    if (fs::file_exists(rast_tif)) {
        r_tmp_tif <- tempfile(fileext = ".tif")
        r_tmp <- c(rast(rast_tif), r)
        r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
        terra::writeRaster(r_tmp, r_tmp_tif)
        fs::file_delete(rast_tif)
        fs::file_move(r_tmp_tif, rast_tif)
        rm(r)
        rm(r_tmp)
    }
    else {
        terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
    }
    r <- terra::rast(rast_tif)
}
debug: if (fs::file_exists(rast_tif)) {
    r_tmp_tif <- tempfile(fileext = ".tif")
    r_tmp <- c(rast(rast_tif), r)
    r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
    terra::writeRaster(r_tmp, r_tmp_tif)
    fs::file_delete(rast_tif)
    fs::file_move(r_tmp_tif, rast_tif)
    rm(r)
    rm(r_tmp)
} else {
    terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
}
debug: terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
debug: r <- terra::rast(rast_tif)
debug: d_r <- mutate(tidyr::pivot_longer(sf::st_drop_geometry(sf::st_as_sf(terra::zonal(x = r, 
    z = terra::vect(dplyr::select(sf_zones, dplyr::all_of(fld_zones))), 
    fun = zonal_fun, exact = T, na.rm = T, as.polygons = T))), 
    cols = -dplyr::any_of(fld_zones), names_to = "lyr", values_to = zonal_fun), 
    time = readr::parse_datetime(str_replace(lyr, glue("{var}\\|(.*)"), 
        "\\1")))
debug: if (!is.null(zonal_csv)) write_csv(d_r, zonal_csv)
debug: write_csv(d_r, zonal_csv)
debug: if (!keep_nc) unlink(dir_nc, recursive = T)
debug: unlink(dir_nc, recursive = T)
debug: return(d_r)
Downloading 1 requests, up to 490 time slices each
Called from: extractr::ed_extract(ed, var = v, sf_zones = ply, bbox = bb, 
    mask_tif = F, rast_tif = glue("{dir_out}/{nms}/{yr}.tif"), 
    zonal_fun = "mean", zonal_csv = glue("{dir_out}/{nms}/{yr}.csv"), 
    dir_nc = glue("{dir_out}/{nms}/{yr}_nc"), keep_nc = F, n_max_vals_per_req = 1e+05, 
    time_min = time_min, time_max = time_max, verbose = T)
debug: while (i_req <= n_reqs) {
    i_t_beg <- (i_req - 1) * n_t_per_req + 1
    i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
    t_req <- times_todo[c(i_t_beg, i_t_end)]
    t_req_str <- format_ISO8601(t_req, usetz = "Z")
    if (verbose) 
        message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
    ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
        ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
        0), nc)
    unlink(ncs0)
    nc_retry <- T
    nc_n_try <- 1
    n_max_retries
    while (nc_retry) {
        res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
            url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
                bbox[["xmax"]]), latitude = c(bbox[["ymin"]], 
                bbox[["ymax"]]), time = t_req_str, fmt = "nc", 
            store = rerddap::disk(path = dir_nc)))
        if (inherits(res, "try-error")) {
            err <- attr(res, "condition")
            msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
            nc_n_try <- nc_n_try + 1
            if (nc_n_try > n_max_retries) {
                stop(msg)
            }
            else {
                message(msg, "\nRETRYing...")
                Sys.sleep(1)
            }
        }
        else {
            nc_retry <- F
        }
    }
    i_req <- i_req + 1
}
debug: i_t_beg <- (i_req - 1) * n_t_per_req + 1
debug: i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
debug: t_req <- times_todo[c(i_t_beg, i_t_end)]
debug: t_req_str <- format_ISO8601(t_req, usetz = "Z")
debug: if (verbose) message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
debug: message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
Fetching request 1 of 1 (2002-01-01 to 2002-12-01) ~ 19:31:15 UTC
debug: ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
    0), nc)
debug: unlink(ncs0)
debug: nc_retry <- T
debug: nc_n_try <- 1
debug: n_max_retries
debug: while (nc_retry) {
    res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
        url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
            bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
        time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
    if (inherits(res, "try-error")) {
        err <- attr(res, "condition")
        msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
        nc_n_try <- nc_n_try + 1
        if (nc_n_try > n_max_retries) {
            stop(msg)
        }
        else {
            message(msg, "\nRETRYing...")
            Sys.sleep(1)
        }
    }
    else {
        nc_retry <- F
    }
}
debug: res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
    url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
        bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
    time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
debug: if (inherits(res, "try-error")) {
    err <- attr(res, "condition")
    msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
    nc_n_try <- nc_n_try + 1
    if (nc_n_try > n_max_retries) {
        stop(msg)
    }
    else {
        message(msg, "\nRETRYing...")
        Sys.sleep(1)
    }
} else {
    nc_retry <- F
}
debug: nc_retry <- F
debug: (while) nc_retry
debug: i_req <- i_req + 1
debug: (while) i_req <= n_reqs
debug: ncs <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size > 
    0), nc)
debug: r <- terra::rast(ncs)
debug: stopifnot(all(class(terra::time(r)) %in% c("POSIXct", "POSIXt")))
debug: idx <- dplyr::pull(dplyr::filter(dplyr::arrange(dplyr::tibble(idx = 1:terra::nlyr(r), 
    time = terra::time(r)), time), !duplicated(time)), idx)
debug: r <- terra::subset(r, idx)
debug: stopifnot(terra::crs(r, proj = T) == wgs84)
debug: if (mask_tif) r <- terra::mask(r, sf_zones)
debug: lyrs <- glue("{var}|{terra::time(r)}")
debug: if (length(dims_other) > 0 && !all(length(dims[dims_other]) == 
    1)) stop(glue("Other dimensions not yet supported: {paste(dims_other, collapse = ',')}"))
debug: names(r) <- lyrs
debug: if (!is.null(rast_tif)) {
    if (fs::file_exists(rast_tif)) {
        r_tmp_tif <- tempfile(fileext = ".tif")
        r_tmp <- c(rast(rast_tif), r)
        r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
        terra::writeRaster(r_tmp, r_tmp_tif)
        fs::file_delete(rast_tif)
        fs::file_move(r_tmp_tif, rast_tif)
        rm(r)
        rm(r_tmp)
    }
    else {
        terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
    }
    r <- terra::rast(rast_tif)
}
debug: if (fs::file_exists(rast_tif)) {
    r_tmp_tif <- tempfile(fileext = ".tif")
    r_tmp <- c(rast(rast_tif), r)
    r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
    terra::writeRaster(r_tmp, r_tmp_tif)
    fs::file_delete(rast_tif)
    fs::file_move(r_tmp_tif, rast_tif)
    rm(r)
    rm(r_tmp)
} else {
    terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
}
debug: terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
debug: r <- terra::rast(rast_tif)
debug: d_r <- mutate(tidyr::pivot_longer(sf::st_drop_geometry(sf::st_as_sf(terra::zonal(x = r, 
    z = terra::vect(dplyr::select(sf_zones, dplyr::all_of(fld_zones))), 
    fun = zonal_fun, exact = T, na.rm = T, as.polygons = T))), 
    cols = -dplyr::any_of(fld_zones), names_to = "lyr", values_to = zonal_fun), 
    time = readr::parse_datetime(str_replace(lyr, glue("{var}\\|(.*)"), 
        "\\1")))
debug: if (!is.null(zonal_csv)) write_csv(d_r, zonal_csv)
debug: write_csv(d_r, zonal_csv)
debug: if (!keep_nc) unlink(dir_nc, recursive = T)
debug: unlink(dir_nc, recursive = T)
debug: return(d_r)
Downloading 1 requests, up to 490 time slices each
Called from: extractr::ed_extract(ed, var = v, sf_zones = ply, bbox = bb, 
    mask_tif = F, rast_tif = glue("{dir_out}/{nms}/{yr}.tif"), 
    zonal_fun = "mean", zonal_csv = glue("{dir_out}/{nms}/{yr}.csv"), 
    dir_nc = glue("{dir_out}/{nms}/{yr}_nc"), keep_nc = F, n_max_vals_per_req = 1e+05, 
    time_min = time_min, time_max = time_max, verbose = T)
debug: while (i_req <= n_reqs) {
    i_t_beg <- (i_req - 1) * n_t_per_req + 1
    i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
    t_req <- times_todo[c(i_t_beg, i_t_end)]
    t_req_str <- format_ISO8601(t_req, usetz = "Z")
    if (verbose) 
        message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
    ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
        ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
        0), nc)
    unlink(ncs0)
    nc_retry <- T
    nc_n_try <- 1
    n_max_retries
    while (nc_retry) {
        res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
            url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
                bbox[["xmax"]]), latitude = c(bbox[["ymin"]], 
                bbox[["ymax"]]), time = t_req_str, fmt = "nc", 
            store = rerddap::disk(path = dir_nc)))
        if (inherits(res, "try-error")) {
            err <- attr(res, "condition")
            msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
            nc_n_try <- nc_n_try + 1
            if (nc_n_try > n_max_retries) {
                stop(msg)
            }
            else {
                message(msg, "\nRETRYing...")
                Sys.sleep(1)
            }
        }
        else {
            nc_retry <- F
        }
    }
    i_req <- i_req + 1
}
debug: i_t_beg <- (i_req - 1) * n_t_per_req + 1
debug: i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
debug: t_req <- times_todo[c(i_t_beg, i_t_end)]
debug: t_req_str <- format_ISO8601(t_req, usetz = "Z")
debug: if (verbose) message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
debug: message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
Fetching request 1 of 1 (2003-01-01 to 2003-12-01) ~ 19:31:17 UTC
debug: ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
    0), nc)
debug: unlink(ncs0)
debug: nc_retry <- T
debug: nc_n_try <- 1
debug: n_max_retries
debug: while (nc_retry) {
    res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
        url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
            bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
        time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
    if (inherits(res, "try-error")) {
        err <- attr(res, "condition")
        msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
        nc_n_try <- nc_n_try + 1
        if (nc_n_try > n_max_retries) {
            stop(msg)
        }
        else {
            message(msg, "\nRETRYing...")
            Sys.sleep(1)
        }
    }
    else {
        nc_retry <- F
    }
}
debug: res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
    url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
        bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
    time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
debug: if (inherits(res, "try-error")) {
    err <- attr(res, "condition")
    msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
    nc_n_try <- nc_n_try + 1
    if (nc_n_try > n_max_retries) {
        stop(msg)
    }
    else {
        message(msg, "\nRETRYing...")
        Sys.sleep(1)
    }
} else {
    nc_retry <- F
}
debug: nc_retry <- F
debug: (while) nc_retry
debug: i_req <- i_req + 1
debug: (while) i_req <= n_reqs
debug: ncs <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size > 
    0), nc)
debug: r <- terra::rast(ncs)
debug: stopifnot(all(class(terra::time(r)) %in% c("POSIXct", "POSIXt")))
debug: idx <- dplyr::pull(dplyr::filter(dplyr::arrange(dplyr::tibble(idx = 1:terra::nlyr(r), 
    time = terra::time(r)), time), !duplicated(time)), idx)
debug: r <- terra::subset(r, idx)
debug: stopifnot(terra::crs(r, proj = T) == wgs84)
debug: if (mask_tif) r <- terra::mask(r, sf_zones)
debug: lyrs <- glue("{var}|{terra::time(r)}")
debug: if (length(dims_other) > 0 && !all(length(dims[dims_other]) == 
    1)) stop(glue("Other dimensions not yet supported: {paste(dims_other, collapse = ',')}"))
debug: names(r) <- lyrs
debug: if (!is.null(rast_tif)) {
    if (fs::file_exists(rast_tif)) {
        r_tmp_tif <- tempfile(fileext = ".tif")
        r_tmp <- c(rast(rast_tif), r)
        r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
        terra::writeRaster(r_tmp, r_tmp_tif)
        fs::file_delete(rast_tif)
        fs::file_move(r_tmp_tif, rast_tif)
        rm(r)
        rm(r_tmp)
    }
    else {
        terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
    }
    r <- terra::rast(rast_tif)
}
debug: if (fs::file_exists(rast_tif)) {
    r_tmp_tif <- tempfile(fileext = ".tif")
    r_tmp <- c(rast(rast_tif), r)
    r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
    terra::writeRaster(r_tmp, r_tmp_tif)
    fs::file_delete(rast_tif)
    fs::file_move(r_tmp_tif, rast_tif)
    rm(r)
    rm(r_tmp)
} else {
    terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
}
debug: terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
debug: r <- terra::rast(rast_tif)
debug: d_r <- mutate(tidyr::pivot_longer(sf::st_drop_geometry(sf::st_as_sf(terra::zonal(x = r, 
    z = terra::vect(dplyr::select(sf_zones, dplyr::all_of(fld_zones))), 
    fun = zonal_fun, exact = T, na.rm = T, as.polygons = T))), 
    cols = -dplyr::any_of(fld_zones), names_to = "lyr", values_to = zonal_fun), 
    time = readr::parse_datetime(str_replace(lyr, glue("{var}\\|(.*)"), 
        "\\1")))
debug: if (!is.null(zonal_csv)) write_csv(d_r, zonal_csv)
debug: write_csv(d_r, zonal_csv)
debug: if (!keep_nc) unlink(dir_nc, recursive = T)
debug: unlink(dir_nc, recursive = T)
debug: return(d_r)
Downloading 1 requests, up to 490 time slices each
Called from: extractr::ed_extract(ed, var = v, sf_zones = ply, bbox = bb, 
    mask_tif = F, rast_tif = glue("{dir_out}/{nms}/{yr}.tif"), 
    zonal_fun = "mean", zonal_csv = glue("{dir_out}/{nms}/{yr}.csv"), 
    dir_nc = glue("{dir_out}/{nms}/{yr}_nc"), keep_nc = F, n_max_vals_per_req = 1e+05, 
    time_min = time_min, time_max = time_max, verbose = T)
debug: while (i_req <= n_reqs) {
    i_t_beg <- (i_req - 1) * n_t_per_req + 1
    i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
    t_req <- times_todo[c(i_t_beg, i_t_end)]
    t_req_str <- format_ISO8601(t_req, usetz = "Z")
    if (verbose) 
        message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
    ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
        ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
        0), nc)
    unlink(ncs0)
    nc_retry <- T
    nc_n_try <- 1
    n_max_retries
    while (nc_retry) {
        res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
            url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
                bbox[["xmax"]]), latitude = c(bbox[["ymin"]], 
                bbox[["ymax"]]), time = t_req_str, fmt = "nc", 
            store = rerddap::disk(path = dir_nc)))
        if (inherits(res, "try-error")) {
            err <- attr(res, "condition")
            msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
            nc_n_try <- nc_n_try + 1
            if (nc_n_try > n_max_retries) {
                stop(msg)
            }
            else {
                message(msg, "\nRETRYing...")
                Sys.sleep(1)
            }
        }
        else {
            nc_retry <- F
        }
    }
    i_req <- i_req + 1
}
debug: i_t_beg <- (i_req - 1) * n_t_per_req + 1
debug: i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
debug: t_req <- times_todo[c(i_t_beg, i_t_end)]
debug: t_req_str <- format_ISO8601(t_req, usetz = "Z")
debug: if (verbose) message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
debug: message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
Fetching request 1 of 1 (2004-01-01 to 2004-12-01) ~ 19:31:19 UTC
debug: ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
    0), nc)
debug: unlink(ncs0)
debug: nc_retry <- T
debug: nc_n_try <- 1
debug: n_max_retries
debug: while (nc_retry) {
    res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
        url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
            bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
        time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
    if (inherits(res, "try-error")) {
        err <- attr(res, "condition")
        msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
        nc_n_try <- nc_n_try + 1
        if (nc_n_try > n_max_retries) {
            stop(msg)
        }
        else {
            message(msg, "\nRETRYing...")
            Sys.sleep(1)
        }
    }
    else {
        nc_retry <- F
    }
}
debug: res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
    url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
        bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
    time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
debug: if (inherits(res, "try-error")) {
    err <- attr(res, "condition")
    msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
    nc_n_try <- nc_n_try + 1
    if (nc_n_try > n_max_retries) {
        stop(msg)
    }
    else {
        message(msg, "\nRETRYing...")
        Sys.sleep(1)
    }
} else {
    nc_retry <- F
}
debug: nc_retry <- F
debug: (while) nc_retry
debug: i_req <- i_req + 1
debug: (while) i_req <= n_reqs
debug: ncs <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size > 
    0), nc)
debug: r <- terra::rast(ncs)
debug: stopifnot(all(class(terra::time(r)) %in% c("POSIXct", "POSIXt")))
debug: idx <- dplyr::pull(dplyr::filter(dplyr::arrange(dplyr::tibble(idx = 1:terra::nlyr(r), 
    time = terra::time(r)), time), !duplicated(time)), idx)
debug: r <- terra::subset(r, idx)
debug: stopifnot(terra::crs(r, proj = T) == wgs84)
debug: if (mask_tif) r <- terra::mask(r, sf_zones)
debug: lyrs <- glue("{var}|{terra::time(r)}")
debug: if (length(dims_other) > 0 && !all(length(dims[dims_other]) == 
    1)) stop(glue("Other dimensions not yet supported: {paste(dims_other, collapse = ',')}"))
debug: names(r) <- lyrs
debug: if (!is.null(rast_tif)) {
    if (fs::file_exists(rast_tif)) {
        r_tmp_tif <- tempfile(fileext = ".tif")
        r_tmp <- c(rast(rast_tif), r)
        r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
        terra::writeRaster(r_tmp, r_tmp_tif)
        fs::file_delete(rast_tif)
        fs::file_move(r_tmp_tif, rast_tif)
        rm(r)
        rm(r_tmp)
    }
    else {
        terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
    }
    r <- terra::rast(rast_tif)
}
debug: if (fs::file_exists(rast_tif)) {
    r_tmp_tif <- tempfile(fileext = ".tif")
    r_tmp <- c(rast(rast_tif), r)
    r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
    terra::writeRaster(r_tmp, r_tmp_tif)
    fs::file_delete(rast_tif)
    fs::file_move(r_tmp_tif, rast_tif)
    rm(r)
    rm(r_tmp)
} else {
    terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
}
debug: terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
debug: r <- terra::rast(rast_tif)
debug: d_r <- mutate(tidyr::pivot_longer(sf::st_drop_geometry(sf::st_as_sf(terra::zonal(x = r, 
    z = terra::vect(dplyr::select(sf_zones, dplyr::all_of(fld_zones))), 
    fun = zonal_fun, exact = T, na.rm = T, as.polygons = T))), 
    cols = -dplyr::any_of(fld_zones), names_to = "lyr", values_to = zonal_fun), 
    time = readr::parse_datetime(str_replace(lyr, glue("{var}\\|(.*)"), 
        "\\1")))
debug: if (!is.null(zonal_csv)) write_csv(d_r, zonal_csv)
debug: write_csv(d_r, zonal_csv)
debug: if (!keep_nc) unlink(dir_nc, recursive = T)
debug: unlink(dir_nc, recursive = T)
debug: return(d_r)
Downloading 1 requests, up to 490 time slices each
Called from: extractr::ed_extract(ed, var = v, sf_zones = ply, bbox = bb, 
    mask_tif = F, rast_tif = glue("{dir_out}/{nms}/{yr}.tif"), 
    zonal_fun = "mean", zonal_csv = glue("{dir_out}/{nms}/{yr}.csv"), 
    dir_nc = glue("{dir_out}/{nms}/{yr}_nc"), keep_nc = F, n_max_vals_per_req = 1e+05, 
    time_min = time_min, time_max = time_max, verbose = T)
debug: while (i_req <= n_reqs) {
    i_t_beg <- (i_req - 1) * n_t_per_req + 1
    i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
    t_req <- times_todo[c(i_t_beg, i_t_end)]
    t_req_str <- format_ISO8601(t_req, usetz = "Z")
    if (verbose) 
        message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
    ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
        ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
        0), nc)
    unlink(ncs0)
    nc_retry <- T
    nc_n_try <- 1
    n_max_retries
    while (nc_retry) {
        res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
            url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
                bbox[["xmax"]]), latitude = c(bbox[["ymin"]], 
                bbox[["ymax"]]), time = t_req_str, fmt = "nc", 
            store = rerddap::disk(path = dir_nc)))
        if (inherits(res, "try-error")) {
            err <- attr(res, "condition")
            msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
            nc_n_try <- nc_n_try + 1
            if (nc_n_try > n_max_retries) {
                stop(msg)
            }
            else {
                message(msg, "\nRETRYing...")
                Sys.sleep(1)
            }
        }
        else {
            nc_retry <- F
        }
    }
    i_req <- i_req + 1
}
debug: i_t_beg <- (i_req - 1) * n_t_per_req + 1
debug: i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
debug: t_req <- times_todo[c(i_t_beg, i_t_end)]
debug: t_req_str <- format_ISO8601(t_req, usetz = "Z")
debug: if (verbose) message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
debug: message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
Fetching request 1 of 1 (2005-01-01 to 2005-12-01) ~ 19:31:20 UTC
debug: ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
    0), nc)
debug: unlink(ncs0)
debug: nc_retry <- T
debug: nc_n_try <- 1
debug: n_max_retries
debug: while (nc_retry) {
    res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
        url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
            bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
        time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
    if (inherits(res, "try-error")) {
        err <- attr(res, "condition")
        msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
        nc_n_try <- nc_n_try + 1
        if (nc_n_try > n_max_retries) {
            stop(msg)
        }
        else {
            message(msg, "\nRETRYing...")
            Sys.sleep(1)
        }
    }
    else {
        nc_retry <- F
    }
}
debug: res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
    url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
        bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
    time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
debug: if (inherits(res, "try-error")) {
    err <- attr(res, "condition")
    msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
    nc_n_try <- nc_n_try + 1
    if (nc_n_try > n_max_retries) {
        stop(msg)
    }
    else {
        message(msg, "\nRETRYing...")
        Sys.sleep(1)
    }
} else {
    nc_retry <- F
}
debug: nc_retry <- F
debug: (while) nc_retry
debug: i_req <- i_req + 1
debug: (while) i_req <= n_reqs
debug: ncs <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size > 
    0), nc)
debug: r <- terra::rast(ncs)
debug: stopifnot(all(class(terra::time(r)) %in% c("POSIXct", "POSIXt")))
debug: idx <- dplyr::pull(dplyr::filter(dplyr::arrange(dplyr::tibble(idx = 1:terra::nlyr(r), 
    time = terra::time(r)), time), !duplicated(time)), idx)
debug: r <- terra::subset(r, idx)
debug: stopifnot(terra::crs(r, proj = T) == wgs84)
debug: if (mask_tif) r <- terra::mask(r, sf_zones)
debug: lyrs <- glue("{var}|{terra::time(r)}")
debug: if (length(dims_other) > 0 && !all(length(dims[dims_other]) == 
    1)) stop(glue("Other dimensions not yet supported: {paste(dims_other, collapse = ',')}"))
debug: names(r) <- lyrs
debug: if (!is.null(rast_tif)) {
    if (fs::file_exists(rast_tif)) {
        r_tmp_tif <- tempfile(fileext = ".tif")
        r_tmp <- c(rast(rast_tif), r)
        r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
        terra::writeRaster(r_tmp, r_tmp_tif)
        fs::file_delete(rast_tif)
        fs::file_move(r_tmp_tif, rast_tif)
        rm(r)
        rm(r_tmp)
    }
    else {
        terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
    }
    r <- terra::rast(rast_tif)
}
debug: if (fs::file_exists(rast_tif)) {
    r_tmp_tif <- tempfile(fileext = ".tif")
    r_tmp <- c(rast(rast_tif), r)
    r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
    terra::writeRaster(r_tmp, r_tmp_tif)
    fs::file_delete(rast_tif)
    fs::file_move(r_tmp_tif, rast_tif)
    rm(r)
    rm(r_tmp)
} else {
    terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
}
debug: terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
debug: r <- terra::rast(rast_tif)
debug: d_r <- mutate(tidyr::pivot_longer(sf::st_drop_geometry(sf::st_as_sf(terra::zonal(x = r, 
    z = terra::vect(dplyr::select(sf_zones, dplyr::all_of(fld_zones))), 
    fun = zonal_fun, exact = T, na.rm = T, as.polygons = T))), 
    cols = -dplyr::any_of(fld_zones), names_to = "lyr", values_to = zonal_fun), 
    time = readr::parse_datetime(str_replace(lyr, glue("{var}\\|(.*)"), 
        "\\1")))
debug: if (!is.null(zonal_csv)) write_csv(d_r, zonal_csv)
debug: write_csv(d_r, zonal_csv)
debug: if (!keep_nc) unlink(dir_nc, recursive = T)
debug: unlink(dir_nc, recursive = T)
debug: return(d_r)
Downloading 1 requests, up to 490 time slices each
Called from: extractr::ed_extract(ed, var = v, sf_zones = ply, bbox = bb, 
    mask_tif = F, rast_tif = glue("{dir_out}/{nms}/{yr}.tif"), 
    zonal_fun = "mean", zonal_csv = glue("{dir_out}/{nms}/{yr}.csv"), 
    dir_nc = glue("{dir_out}/{nms}/{yr}_nc"), keep_nc = F, n_max_vals_per_req = 1e+05, 
    time_min = time_min, time_max = time_max, verbose = T)
debug: while (i_req <= n_reqs) {
    i_t_beg <- (i_req - 1) * n_t_per_req + 1
    i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
    t_req <- times_todo[c(i_t_beg, i_t_end)]
    t_req_str <- format_ISO8601(t_req, usetz = "Z")
    if (verbose) 
        message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
    ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
        ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
        0), nc)
    unlink(ncs0)
    nc_retry <- T
    nc_n_try <- 1
    n_max_retries
    while (nc_retry) {
        res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
            url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
                bbox[["xmax"]]), latitude = c(bbox[["ymin"]], 
                bbox[["ymax"]]), time = t_req_str, fmt = "nc", 
            store = rerddap::disk(path = dir_nc)))
        if (inherits(res, "try-error")) {
            err <- attr(res, "condition")
            msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
            nc_n_try <- nc_n_try + 1
            if (nc_n_try > n_max_retries) {
                stop(msg)
            }
            else {
                message(msg, "\nRETRYing...")
                Sys.sleep(1)
            }
        }
        else {
            nc_retry <- F
        }
    }
    i_req <- i_req + 1
}
debug: i_t_beg <- (i_req - 1) * n_t_per_req + 1
debug: i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
debug: t_req <- times_todo[c(i_t_beg, i_t_end)]
debug: t_req_str <- format_ISO8601(t_req, usetz = "Z")
debug: if (verbose) message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
debug: message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
Fetching request 1 of 1 (2006-01-01 to 2006-12-01) ~ 19:31:22 UTC
debug: ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
    0), nc)
debug: unlink(ncs0)
debug: nc_retry <- T
debug: nc_n_try <- 1
debug: n_max_retries
debug: while (nc_retry) {
    res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
        url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
            bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
        time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
    if (inherits(res, "try-error")) {
        err <- attr(res, "condition")
        msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
        nc_n_try <- nc_n_try + 1
        if (nc_n_try > n_max_retries) {
            stop(msg)
        }
        else {
            message(msg, "\nRETRYing...")
            Sys.sleep(1)
        }
    }
    else {
        nc_retry <- F
    }
}
debug: res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
    url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
        bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
    time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
debug: if (inherits(res, "try-error")) {
    err <- attr(res, "condition")
    msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
    nc_n_try <- nc_n_try + 1
    if (nc_n_try > n_max_retries) {
        stop(msg)
    }
    else {
        message(msg, "\nRETRYing...")
        Sys.sleep(1)
    }
} else {
    nc_retry <- F
}
debug: nc_retry <- F
debug: (while) nc_retry
debug: i_req <- i_req + 1
debug: (while) i_req <= n_reqs
debug: ncs <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size > 
    0), nc)
debug: r <- terra::rast(ncs)
debug: stopifnot(all(class(terra::time(r)) %in% c("POSIXct", "POSIXt")))
debug: idx <- dplyr::pull(dplyr::filter(dplyr::arrange(dplyr::tibble(idx = 1:terra::nlyr(r), 
    time = terra::time(r)), time), !duplicated(time)), idx)
debug: r <- terra::subset(r, idx)
debug: stopifnot(terra::crs(r, proj = T) == wgs84)
debug: if (mask_tif) r <- terra::mask(r, sf_zones)
debug: lyrs <- glue("{var}|{terra::time(r)}")
debug: if (length(dims_other) > 0 && !all(length(dims[dims_other]) == 
    1)) stop(glue("Other dimensions not yet supported: {paste(dims_other, collapse = ',')}"))
debug: names(r) <- lyrs
debug: if (!is.null(rast_tif)) {
    if (fs::file_exists(rast_tif)) {
        r_tmp_tif <- tempfile(fileext = ".tif")
        r_tmp <- c(rast(rast_tif), r)
        r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
        terra::writeRaster(r_tmp, r_tmp_tif)
        fs::file_delete(rast_tif)
        fs::file_move(r_tmp_tif, rast_tif)
        rm(r)
        rm(r_tmp)
    }
    else {
        terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
    }
    r <- terra::rast(rast_tif)
}
debug: if (fs::file_exists(rast_tif)) {
    r_tmp_tif <- tempfile(fileext = ".tif")
    r_tmp <- c(rast(rast_tif), r)
    r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
    terra::writeRaster(r_tmp, r_tmp_tif)
    fs::file_delete(rast_tif)
    fs::file_move(r_tmp_tif, rast_tif)
    rm(r)
    rm(r_tmp)
} else {
    terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
}
debug: terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
debug: r <- terra::rast(rast_tif)
debug: d_r <- mutate(tidyr::pivot_longer(sf::st_drop_geometry(sf::st_as_sf(terra::zonal(x = r, 
    z = terra::vect(dplyr::select(sf_zones, dplyr::all_of(fld_zones))), 
    fun = zonal_fun, exact = T, na.rm = T, as.polygons = T))), 
    cols = -dplyr::any_of(fld_zones), names_to = "lyr", values_to = zonal_fun), 
    time = readr::parse_datetime(str_replace(lyr, glue("{var}\\|(.*)"), 
        "\\1")))
debug: if (!is.null(zonal_csv)) write_csv(d_r, zonal_csv)
debug: write_csv(d_r, zonal_csv)
debug: if (!keep_nc) unlink(dir_nc, recursive = T)
debug: unlink(dir_nc, recursive = T)
debug: return(d_r)
Downloading 1 requests, up to 490 time slices each
Called from: extractr::ed_extract(ed, var = v, sf_zones = ply, bbox = bb, 
    mask_tif = F, rast_tif = glue("{dir_out}/{nms}/{yr}.tif"), 
    zonal_fun = "mean", zonal_csv = glue("{dir_out}/{nms}/{yr}.csv"), 
    dir_nc = glue("{dir_out}/{nms}/{yr}_nc"), keep_nc = F, n_max_vals_per_req = 1e+05, 
    time_min = time_min, time_max = time_max, verbose = T)
debug: while (i_req <= n_reqs) {
    i_t_beg <- (i_req - 1) * n_t_per_req + 1
    i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
    t_req <- times_todo[c(i_t_beg, i_t_end)]
    t_req_str <- format_ISO8601(t_req, usetz = "Z")
    if (verbose) 
        message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
    ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
        ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
        0), nc)
    unlink(ncs0)
    nc_retry <- T
    nc_n_try <- 1
    n_max_retries
    while (nc_retry) {
        res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
            url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
                bbox[["xmax"]]), latitude = c(bbox[["ymin"]], 
                bbox[["ymax"]]), time = t_req_str, fmt = "nc", 
            store = rerddap::disk(path = dir_nc)))
        if (inherits(res, "try-error")) {
            err <- attr(res, "condition")
            msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
            nc_n_try <- nc_n_try + 1
            if (nc_n_try > n_max_retries) {
                stop(msg)
            }
            else {
                message(msg, "\nRETRYing...")
                Sys.sleep(1)
            }
        }
        else {
            nc_retry <- F
        }
    }
    i_req <- i_req + 1
}
debug: i_t_beg <- (i_req - 1) * n_t_per_req + 1
debug: i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
debug: t_req <- times_todo[c(i_t_beg, i_t_end)]
debug: t_req_str <- format_ISO8601(t_req, usetz = "Z")
debug: if (verbose) message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
debug: message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
Fetching request 1 of 1 (2007-01-01 to 2007-12-01) ~ 19:31:24 UTC
debug: ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
    0), nc)
debug: unlink(ncs0)
debug: nc_retry <- T
debug: nc_n_try <- 1
debug: n_max_retries
debug: while (nc_retry) {
    res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
        url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
            bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
        time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
    if (inherits(res, "try-error")) {
        err <- attr(res, "condition")
        msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
        nc_n_try <- nc_n_try + 1
        if (nc_n_try > n_max_retries) {
            stop(msg)
        }
        else {
            message(msg, "\nRETRYing...")
            Sys.sleep(1)
        }
    }
    else {
        nc_retry <- F
    }
}
debug: res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
    url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
        bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
    time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
debug: if (inherits(res, "try-error")) {
    err <- attr(res, "condition")
    msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
    nc_n_try <- nc_n_try + 1
    if (nc_n_try > n_max_retries) {
        stop(msg)
    }
    else {
        message(msg, "\nRETRYing...")
        Sys.sleep(1)
    }
} else {
    nc_retry <- F
}
debug: nc_retry <- F
debug: (while) nc_retry
debug: i_req <- i_req + 1
debug: (while) i_req <= n_reqs
debug: ncs <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size > 
    0), nc)
debug: r <- terra::rast(ncs)
debug: stopifnot(all(class(terra::time(r)) %in% c("POSIXct", "POSIXt")))
debug: idx <- dplyr::pull(dplyr::filter(dplyr::arrange(dplyr::tibble(idx = 1:terra::nlyr(r), 
    time = terra::time(r)), time), !duplicated(time)), idx)
debug: r <- terra::subset(r, idx)
debug: stopifnot(terra::crs(r, proj = T) == wgs84)
debug: if (mask_tif) r <- terra::mask(r, sf_zones)
debug: lyrs <- glue("{var}|{terra::time(r)}")
debug: if (length(dims_other) > 0 && !all(length(dims[dims_other]) == 
    1)) stop(glue("Other dimensions not yet supported: {paste(dims_other, collapse = ',')}"))
debug: names(r) <- lyrs
debug: if (!is.null(rast_tif)) {
    if (fs::file_exists(rast_tif)) {
        r_tmp_tif <- tempfile(fileext = ".tif")
        r_tmp <- c(rast(rast_tif), r)
        r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
        terra::writeRaster(r_tmp, r_tmp_tif)
        fs::file_delete(rast_tif)
        fs::file_move(r_tmp_tif, rast_tif)
        rm(r)
        rm(r_tmp)
    }
    else {
        terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
    }
    r <- terra::rast(rast_tif)
}
debug: if (fs::file_exists(rast_tif)) {
    r_tmp_tif <- tempfile(fileext = ".tif")
    r_tmp <- c(rast(rast_tif), r)
    r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
    terra::writeRaster(r_tmp, r_tmp_tif)
    fs::file_delete(rast_tif)
    fs::file_move(r_tmp_tif, rast_tif)
    rm(r)
    rm(r_tmp)
} else {
    terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
}
debug: terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
debug: r <- terra::rast(rast_tif)
debug: d_r <- mutate(tidyr::pivot_longer(sf::st_drop_geometry(sf::st_as_sf(terra::zonal(x = r, 
    z = terra::vect(dplyr::select(sf_zones, dplyr::all_of(fld_zones))), 
    fun = zonal_fun, exact = T, na.rm = T, as.polygons = T))), 
    cols = -dplyr::any_of(fld_zones), names_to = "lyr", values_to = zonal_fun), 
    time = readr::parse_datetime(str_replace(lyr, glue("{var}\\|(.*)"), 
        "\\1")))
debug: if (!is.null(zonal_csv)) write_csv(d_r, zonal_csv)
debug: write_csv(d_r, zonal_csv)
debug: if (!keep_nc) unlink(dir_nc, recursive = T)
debug: unlink(dir_nc, recursive = T)
debug: return(d_r)
Downloading 1 requests, up to 490 time slices each
Called from: extractr::ed_extract(ed, var = v, sf_zones = ply, bbox = bb, 
    mask_tif = F, rast_tif = glue("{dir_out}/{nms}/{yr}.tif"), 
    zonal_fun = "mean", zonal_csv = glue("{dir_out}/{nms}/{yr}.csv"), 
    dir_nc = glue("{dir_out}/{nms}/{yr}_nc"), keep_nc = F, n_max_vals_per_req = 1e+05, 
    time_min = time_min, time_max = time_max, verbose = T)
debug: while (i_req <= n_reqs) {
    i_t_beg <- (i_req - 1) * n_t_per_req + 1
    i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
    t_req <- times_todo[c(i_t_beg, i_t_end)]
    t_req_str <- format_ISO8601(t_req, usetz = "Z")
    if (verbose) 
        message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
    ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
        ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
        0), nc)
    unlink(ncs0)
    nc_retry <- T
    nc_n_try <- 1
    n_max_retries
    while (nc_retry) {
        res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
            url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
                bbox[["xmax"]]), latitude = c(bbox[["ymin"]], 
                bbox[["ymax"]]), time = t_req_str, fmt = "nc", 
            store = rerddap::disk(path = dir_nc)))
        if (inherits(res, "try-error")) {
            err <- attr(res, "condition")
            msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
            nc_n_try <- nc_n_try + 1
            if (nc_n_try > n_max_retries) {
                stop(msg)
            }
            else {
                message(msg, "\nRETRYing...")
                Sys.sleep(1)
            }
        }
        else {
            nc_retry <- F
        }
    }
    i_req <- i_req + 1
}
debug: i_t_beg <- (i_req - 1) * n_t_per_req + 1
debug: i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
debug: t_req <- times_todo[c(i_t_beg, i_t_end)]
debug: t_req_str <- format_ISO8601(t_req, usetz = "Z")
debug: if (verbose) message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
debug: message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
Fetching request 1 of 1 (2008-01-01 to 2008-12-01) ~ 19:31:26 UTC
debug: ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
    0), nc)
debug: unlink(ncs0)
debug: nc_retry <- T
debug: nc_n_try <- 1
debug: n_max_retries
debug: while (nc_retry) {
    res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
        url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
            bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
        time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
    if (inherits(res, "try-error")) {
        err <- attr(res, "condition")
        msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
        nc_n_try <- nc_n_try + 1
        if (nc_n_try > n_max_retries) {
            stop(msg)
        }
        else {
            message(msg, "\nRETRYing...")
            Sys.sleep(1)
        }
    }
    else {
        nc_retry <- F
    }
}
debug: res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
    url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
        bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
    time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
debug: if (inherits(res, "try-error")) {
    err <- attr(res, "condition")
    msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
    nc_n_try <- nc_n_try + 1
    if (nc_n_try > n_max_retries) {
        stop(msg)
    }
    else {
        message(msg, "\nRETRYing...")
        Sys.sleep(1)
    }
} else {
    nc_retry <- F
}
debug: nc_retry <- F
debug: (while) nc_retry
debug: i_req <- i_req + 1
debug: (while) i_req <= n_reqs
debug: ncs <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size > 
    0), nc)
debug: r <- terra::rast(ncs)
debug: stopifnot(all(class(terra::time(r)) %in% c("POSIXct", "POSIXt")))
debug: idx <- dplyr::pull(dplyr::filter(dplyr::arrange(dplyr::tibble(idx = 1:terra::nlyr(r), 
    time = terra::time(r)), time), !duplicated(time)), idx)
debug: r <- terra::subset(r, idx)
debug: stopifnot(terra::crs(r, proj = T) == wgs84)
debug: if (mask_tif) r <- terra::mask(r, sf_zones)
debug: lyrs <- glue("{var}|{terra::time(r)}")
debug: if (length(dims_other) > 0 && !all(length(dims[dims_other]) == 
    1)) stop(glue("Other dimensions not yet supported: {paste(dims_other, collapse = ',')}"))
debug: names(r) <- lyrs
debug: if (!is.null(rast_tif)) {
    if (fs::file_exists(rast_tif)) {
        r_tmp_tif <- tempfile(fileext = ".tif")
        r_tmp <- c(rast(rast_tif), r)
        r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
        terra::writeRaster(r_tmp, r_tmp_tif)
        fs::file_delete(rast_tif)
        fs::file_move(r_tmp_tif, rast_tif)
        rm(r)
        rm(r_tmp)
    }
    else {
        terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
    }
    r <- terra::rast(rast_tif)
}
debug: if (fs::file_exists(rast_tif)) {
    r_tmp_tif <- tempfile(fileext = ".tif")
    r_tmp <- c(rast(rast_tif), r)
    r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
    terra::writeRaster(r_tmp, r_tmp_tif)
    fs::file_delete(rast_tif)
    fs::file_move(r_tmp_tif, rast_tif)
    rm(r)
    rm(r_tmp)
} else {
    terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
}
debug: terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
debug: r <- terra::rast(rast_tif)
debug: d_r <- mutate(tidyr::pivot_longer(sf::st_drop_geometry(sf::st_as_sf(terra::zonal(x = r, 
    z = terra::vect(dplyr::select(sf_zones, dplyr::all_of(fld_zones))), 
    fun = zonal_fun, exact = T, na.rm = T, as.polygons = T))), 
    cols = -dplyr::any_of(fld_zones), names_to = "lyr", values_to = zonal_fun), 
    time = readr::parse_datetime(str_replace(lyr, glue("{var}\\|(.*)"), 
        "\\1")))
debug: if (!is.null(zonal_csv)) write_csv(d_r, zonal_csv)
debug: write_csv(d_r, zonal_csv)
debug: if (!keep_nc) unlink(dir_nc, recursive = T)
debug: unlink(dir_nc, recursive = T)
debug: return(d_r)
Downloading 1 requests, up to 490 time slices each
Called from: extractr::ed_extract(ed, var = v, sf_zones = ply, bbox = bb, 
    mask_tif = F, rast_tif = glue("{dir_out}/{nms}/{yr}.tif"), 
    zonal_fun = "mean", zonal_csv = glue("{dir_out}/{nms}/{yr}.csv"), 
    dir_nc = glue("{dir_out}/{nms}/{yr}_nc"), keep_nc = F, n_max_vals_per_req = 1e+05, 
    time_min = time_min, time_max = time_max, verbose = T)
debug: while (i_req <= n_reqs) {
    i_t_beg <- (i_req - 1) * n_t_per_req + 1
    i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
    t_req <- times_todo[c(i_t_beg, i_t_end)]
    t_req_str <- format_ISO8601(t_req, usetz = "Z")
    if (verbose) 
        message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
    ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
        ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
        0), nc)
    unlink(ncs0)
    nc_retry <- T
    nc_n_try <- 1
    n_max_retries
    while (nc_retry) {
        res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
            url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
                bbox[["xmax"]]), latitude = c(bbox[["ymin"]], 
                bbox[["ymax"]]), time = t_req_str, fmt = "nc", 
            store = rerddap::disk(path = dir_nc)))
        if (inherits(res, "try-error")) {
            err <- attr(res, "condition")
            msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
            nc_n_try <- nc_n_try + 1
            if (nc_n_try > n_max_retries) {
                stop(msg)
            }
            else {
                message(msg, "\nRETRYing...")
                Sys.sleep(1)
            }
        }
        else {
            nc_retry <- F
        }
    }
    i_req <- i_req + 1
}
debug: i_t_beg <- (i_req - 1) * n_t_per_req + 1
debug: i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
debug: t_req <- times_todo[c(i_t_beg, i_t_end)]
debug: t_req_str <- format_ISO8601(t_req, usetz = "Z")
debug: if (verbose) message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
debug: message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
Fetching request 1 of 1 (2009-01-01 to 2009-12-01) ~ 19:31:27 UTC
debug: ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
    0), nc)
debug: unlink(ncs0)
debug: nc_retry <- T
debug: nc_n_try <- 1
debug: n_max_retries
debug: while (nc_retry) {
    res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
        url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
            bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
        time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
    if (inherits(res, "try-error")) {
        err <- attr(res, "condition")
        msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
        nc_n_try <- nc_n_try + 1
        if (nc_n_try > n_max_retries) {
            stop(msg)
        }
        else {
            message(msg, "\nRETRYing...")
            Sys.sleep(1)
        }
    }
    else {
        nc_retry <- F
    }
}
debug: res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
    url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
        bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
    time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
debug: if (inherits(res, "try-error")) {
    err <- attr(res, "condition")
    msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
    nc_n_try <- nc_n_try + 1
    if (nc_n_try > n_max_retries) {
        stop(msg)
    }
    else {
        message(msg, "\nRETRYing...")
        Sys.sleep(1)
    }
} else {
    nc_retry <- F
}
debug: nc_retry <- F
debug: (while) nc_retry
debug: i_req <- i_req + 1
debug: (while) i_req <= n_reqs
debug: ncs <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size > 
    0), nc)
debug: r <- terra::rast(ncs)
debug: stopifnot(all(class(terra::time(r)) %in% c("POSIXct", "POSIXt")))
debug: idx <- dplyr::pull(dplyr::filter(dplyr::arrange(dplyr::tibble(idx = 1:terra::nlyr(r), 
    time = terra::time(r)), time), !duplicated(time)), idx)
debug: r <- terra::subset(r, idx)
debug: stopifnot(terra::crs(r, proj = T) == wgs84)
debug: if (mask_tif) r <- terra::mask(r, sf_zones)
debug: lyrs <- glue("{var}|{terra::time(r)}")
debug: if (length(dims_other) > 0 && !all(length(dims[dims_other]) == 
    1)) stop(glue("Other dimensions not yet supported: {paste(dims_other, collapse = ',')}"))
debug: names(r) <- lyrs
debug: if (!is.null(rast_tif)) {
    if (fs::file_exists(rast_tif)) {
        r_tmp_tif <- tempfile(fileext = ".tif")
        r_tmp <- c(rast(rast_tif), r)
        r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
        terra::writeRaster(r_tmp, r_tmp_tif)
        fs::file_delete(rast_tif)
        fs::file_move(r_tmp_tif, rast_tif)
        rm(r)
        rm(r_tmp)
    }
    else {
        terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
    }
    r <- terra::rast(rast_tif)
}
debug: if (fs::file_exists(rast_tif)) {
    r_tmp_tif <- tempfile(fileext = ".tif")
    r_tmp <- c(rast(rast_tif), r)
    r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
    terra::writeRaster(r_tmp, r_tmp_tif)
    fs::file_delete(rast_tif)
    fs::file_move(r_tmp_tif, rast_tif)
    rm(r)
    rm(r_tmp)
} else {
    terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
}
debug: terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
debug: r <- terra::rast(rast_tif)
debug: d_r <- mutate(tidyr::pivot_longer(sf::st_drop_geometry(sf::st_as_sf(terra::zonal(x = r, 
    z = terra::vect(dplyr::select(sf_zones, dplyr::all_of(fld_zones))), 
    fun = zonal_fun, exact = T, na.rm = T, as.polygons = T))), 
    cols = -dplyr::any_of(fld_zones), names_to = "lyr", values_to = zonal_fun), 
    time = readr::parse_datetime(str_replace(lyr, glue("{var}\\|(.*)"), 
        "\\1")))
debug: if (!is.null(zonal_csv)) write_csv(d_r, zonal_csv)
debug: write_csv(d_r, zonal_csv)
debug: if (!keep_nc) unlink(dir_nc, recursive = T)
debug: unlink(dir_nc, recursive = T)
debug: return(d_r)
Downloading 1 requests, up to 490 time slices each
Called from: extractr::ed_extract(ed, var = v, sf_zones = ply, bbox = bb, 
    mask_tif = F, rast_tif = glue("{dir_out}/{nms}/{yr}.tif"), 
    zonal_fun = "mean", zonal_csv = glue("{dir_out}/{nms}/{yr}.csv"), 
    dir_nc = glue("{dir_out}/{nms}/{yr}_nc"), keep_nc = F, n_max_vals_per_req = 1e+05, 
    time_min = time_min, time_max = time_max, verbose = T)
debug: while (i_req <= n_reqs) {
    i_t_beg <- (i_req - 1) * n_t_per_req + 1
    i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
    t_req <- times_todo[c(i_t_beg, i_t_end)]
    t_req_str <- format_ISO8601(t_req, usetz = "Z")
    if (verbose) 
        message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
    ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
        ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
        0), nc)
    unlink(ncs0)
    nc_retry <- T
    nc_n_try <- 1
    n_max_retries
    while (nc_retry) {
        res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
            url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
                bbox[["xmax"]]), latitude = c(bbox[["ymin"]], 
                bbox[["ymax"]]), time = t_req_str, fmt = "nc", 
            store = rerddap::disk(path = dir_nc)))
        if (inherits(res, "try-error")) {
            err <- attr(res, "condition")
            msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
            nc_n_try <- nc_n_try + 1
            if (nc_n_try > n_max_retries) {
                stop(msg)
            }
            else {
                message(msg, "\nRETRYing...")
                Sys.sleep(1)
            }
        }
        else {
            nc_retry <- F
        }
    }
    i_req <- i_req + 1
}
debug: i_t_beg <- (i_req - 1) * n_t_per_req + 1
debug: i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
debug: t_req <- times_todo[c(i_t_beg, i_t_end)]
debug: t_req_str <- format_ISO8601(t_req, usetz = "Z")
debug: if (verbose) message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
debug: message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
Fetching request 1 of 1 (2010-01-01 to 2010-12-01) ~ 19:31:30 UTC
debug: ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
    0), nc)
debug: unlink(ncs0)
debug: nc_retry <- T
debug: nc_n_try <- 1
debug: n_max_retries
debug: while (nc_retry) {
    res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
        url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
            bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
        time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
    if (inherits(res, "try-error")) {
        err <- attr(res, "condition")
        msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
        nc_n_try <- nc_n_try + 1
        if (nc_n_try > n_max_retries) {
            stop(msg)
        }
        else {
            message(msg, "\nRETRYing...")
            Sys.sleep(1)
        }
    }
    else {
        nc_retry <- F
    }
}
debug: res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
    url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
        bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
    time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
debug: if (inherits(res, "try-error")) {
    err <- attr(res, "condition")
    msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
    nc_n_try <- nc_n_try + 1
    if (nc_n_try > n_max_retries) {
        stop(msg)
    }
    else {
        message(msg, "\nRETRYing...")
        Sys.sleep(1)
    }
} else {
    nc_retry <- F
}
debug: nc_retry <- F
debug: (while) nc_retry
debug: i_req <- i_req + 1
debug: (while) i_req <= n_reqs
debug: ncs <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size > 
    0), nc)
debug: r <- terra::rast(ncs)
debug: stopifnot(all(class(terra::time(r)) %in% c("POSIXct", "POSIXt")))
debug: idx <- dplyr::pull(dplyr::filter(dplyr::arrange(dplyr::tibble(idx = 1:terra::nlyr(r), 
    time = terra::time(r)), time), !duplicated(time)), idx)
debug: r <- terra::subset(r, idx)
debug: stopifnot(terra::crs(r, proj = T) == wgs84)
debug: if (mask_tif) r <- terra::mask(r, sf_zones)
debug: lyrs <- glue("{var}|{terra::time(r)}")
debug: if (length(dims_other) > 0 && !all(length(dims[dims_other]) == 
    1)) stop(glue("Other dimensions not yet supported: {paste(dims_other, collapse = ',')}"))
debug: names(r) <- lyrs
debug: if (!is.null(rast_tif)) {
    if (fs::file_exists(rast_tif)) {
        r_tmp_tif <- tempfile(fileext = ".tif")
        r_tmp <- c(rast(rast_tif), r)
        r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
        terra::writeRaster(r_tmp, r_tmp_tif)
        fs::file_delete(rast_tif)
        fs::file_move(r_tmp_tif, rast_tif)
        rm(r)
        rm(r_tmp)
    }
    else {
        terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
    }
    r <- terra::rast(rast_tif)
}
debug: if (fs::file_exists(rast_tif)) {
    r_tmp_tif <- tempfile(fileext = ".tif")
    r_tmp <- c(rast(rast_tif), r)
    r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
    terra::writeRaster(r_tmp, r_tmp_tif)
    fs::file_delete(rast_tif)
    fs::file_move(r_tmp_tif, rast_tif)
    rm(r)
    rm(r_tmp)
} else {
    terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
}
debug: terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
debug: r <- terra::rast(rast_tif)
debug: d_r <- mutate(tidyr::pivot_longer(sf::st_drop_geometry(sf::st_as_sf(terra::zonal(x = r, 
    z = terra::vect(dplyr::select(sf_zones, dplyr::all_of(fld_zones))), 
    fun = zonal_fun, exact = T, na.rm = T, as.polygons = T))), 
    cols = -dplyr::any_of(fld_zones), names_to = "lyr", values_to = zonal_fun), 
    time = readr::parse_datetime(str_replace(lyr, glue("{var}\\|(.*)"), 
        "\\1")))
debug: if (!is.null(zonal_csv)) write_csv(d_r, zonal_csv)
debug: write_csv(d_r, zonal_csv)
debug: if (!keep_nc) unlink(dir_nc, recursive = T)
debug: unlink(dir_nc, recursive = T)
debug: return(d_r)
Downloading 1 requests, up to 490 time slices each
Called from: extractr::ed_extract(ed, var = v, sf_zones = ply, bbox = bb, 
    mask_tif = F, rast_tif = glue("{dir_out}/{nms}/{yr}.tif"), 
    zonal_fun = "mean", zonal_csv = glue("{dir_out}/{nms}/{yr}.csv"), 
    dir_nc = glue("{dir_out}/{nms}/{yr}_nc"), keep_nc = F, n_max_vals_per_req = 1e+05, 
    time_min = time_min, time_max = time_max, verbose = T)
debug: while (i_req <= n_reqs) {
    i_t_beg <- (i_req - 1) * n_t_per_req + 1
    i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
    t_req <- times_todo[c(i_t_beg, i_t_end)]
    t_req_str <- format_ISO8601(t_req, usetz = "Z")
    if (verbose) 
        message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
    ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
        ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
        0), nc)
    unlink(ncs0)
    nc_retry <- T
    nc_n_try <- 1
    n_max_retries
    while (nc_retry) {
        res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
            url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
                bbox[["xmax"]]), latitude = c(bbox[["ymin"]], 
                bbox[["ymax"]]), time = t_req_str, fmt = "nc", 
            store = rerddap::disk(path = dir_nc)))
        if (inherits(res, "try-error")) {
            err <- attr(res, "condition")
            msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
            nc_n_try <- nc_n_try + 1
            if (nc_n_try > n_max_retries) {
                stop(msg)
            }
            else {
                message(msg, "\nRETRYing...")
                Sys.sleep(1)
            }
        }
        else {
            nc_retry <- F
        }
    }
    i_req <- i_req + 1
}
debug: i_t_beg <- (i_req - 1) * n_t_per_req + 1
debug: i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
debug: t_req <- times_todo[c(i_t_beg, i_t_end)]
debug: t_req_str <- format_ISO8601(t_req, usetz = "Z")
debug: if (verbose) message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
debug: message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
Fetching request 1 of 1 (2011-01-01 to 2011-12-01) ~ 19:31:32 UTC
debug: ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
    0), nc)
debug: unlink(ncs0)
debug: nc_retry <- T
debug: nc_n_try <- 1
debug: n_max_retries
debug: while (nc_retry) {
    res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
        url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
            bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
        time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
    if (inherits(res, "try-error")) {
        err <- attr(res, "condition")
        msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
        nc_n_try <- nc_n_try + 1
        if (nc_n_try > n_max_retries) {
            stop(msg)
        }
        else {
            message(msg, "\nRETRYing...")
            Sys.sleep(1)
        }
    }
    else {
        nc_retry <- F
    }
}
debug: res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
    url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
        bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
    time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
debug: if (inherits(res, "try-error")) {
    err <- attr(res, "condition")
    msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
    nc_n_try <- nc_n_try + 1
    if (nc_n_try > n_max_retries) {
        stop(msg)
    }
    else {
        message(msg, "\nRETRYing...")
        Sys.sleep(1)
    }
} else {
    nc_retry <- F
}
debug: nc_retry <- F
debug: (while) nc_retry
debug: i_req <- i_req + 1
debug: (while) i_req <= n_reqs
debug: ncs <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size > 
    0), nc)
debug: r <- terra::rast(ncs)
debug: stopifnot(all(class(terra::time(r)) %in% c("POSIXct", "POSIXt")))
debug: idx <- dplyr::pull(dplyr::filter(dplyr::arrange(dplyr::tibble(idx = 1:terra::nlyr(r), 
    time = terra::time(r)), time), !duplicated(time)), idx)
debug: r <- terra::subset(r, idx)
debug: stopifnot(terra::crs(r, proj = T) == wgs84)
debug: if (mask_tif) r <- terra::mask(r, sf_zones)
debug: lyrs <- glue("{var}|{terra::time(r)}")
debug: if (length(dims_other) > 0 && !all(length(dims[dims_other]) == 
    1)) stop(glue("Other dimensions not yet supported: {paste(dims_other, collapse = ',')}"))
debug: names(r) <- lyrs
debug: if (!is.null(rast_tif)) {
    if (fs::file_exists(rast_tif)) {
        r_tmp_tif <- tempfile(fileext = ".tif")
        r_tmp <- c(rast(rast_tif), r)
        r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
        terra::writeRaster(r_tmp, r_tmp_tif)
        fs::file_delete(rast_tif)
        fs::file_move(r_tmp_tif, rast_tif)
        rm(r)
        rm(r_tmp)
    }
    else {
        terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
    }
    r <- terra::rast(rast_tif)
}
debug: if (fs::file_exists(rast_tif)) {
    r_tmp_tif <- tempfile(fileext = ".tif")
    r_tmp <- c(rast(rast_tif), r)
    r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
    terra::writeRaster(r_tmp, r_tmp_tif)
    fs::file_delete(rast_tif)
    fs::file_move(r_tmp_tif, rast_tif)
    rm(r)
    rm(r_tmp)
} else {
    terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
}
debug: terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
debug: r <- terra::rast(rast_tif)
debug: d_r <- mutate(tidyr::pivot_longer(sf::st_drop_geometry(sf::st_as_sf(terra::zonal(x = r, 
    z = terra::vect(dplyr::select(sf_zones, dplyr::all_of(fld_zones))), 
    fun = zonal_fun, exact = T, na.rm = T, as.polygons = T))), 
    cols = -dplyr::any_of(fld_zones), names_to = "lyr", values_to = zonal_fun), 
    time = readr::parse_datetime(str_replace(lyr, glue("{var}\\|(.*)"), 
        "\\1")))
debug: if (!is.null(zonal_csv)) write_csv(d_r, zonal_csv)
debug: write_csv(d_r, zonal_csv)
debug: if (!keep_nc) unlink(dir_nc, recursive = T)
debug: unlink(dir_nc, recursive = T)
debug: return(d_r)
Downloading 1 requests, up to 490 time slices each
Called from: extractr::ed_extract(ed, var = v, sf_zones = ply, bbox = bb, 
    mask_tif = F, rast_tif = glue("{dir_out}/{nms}/{yr}.tif"), 
    zonal_fun = "mean", zonal_csv = glue("{dir_out}/{nms}/{yr}.csv"), 
    dir_nc = glue("{dir_out}/{nms}/{yr}_nc"), keep_nc = F, n_max_vals_per_req = 1e+05, 
    time_min = time_min, time_max = time_max, verbose = T)
debug: while (i_req <= n_reqs) {
    i_t_beg <- (i_req - 1) * n_t_per_req + 1
    i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
    t_req <- times_todo[c(i_t_beg, i_t_end)]
    t_req_str <- format_ISO8601(t_req, usetz = "Z")
    if (verbose) 
        message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
    ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
        ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
        0), nc)
    unlink(ncs0)
    nc_retry <- T
    nc_n_try <- 1
    n_max_retries
    while (nc_retry) {
        res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
            url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
                bbox[["xmax"]]), latitude = c(bbox[["ymin"]], 
                bbox[["ymax"]]), time = t_req_str, fmt = "nc", 
            store = rerddap::disk(path = dir_nc)))
        if (inherits(res, "try-error")) {
            err <- attr(res, "condition")
            msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
            nc_n_try <- nc_n_try + 1
            if (nc_n_try > n_max_retries) {
                stop(msg)
            }
            else {
                message(msg, "\nRETRYing...")
                Sys.sleep(1)
            }
        }
        else {
            nc_retry <- F
        }
    }
    i_req <- i_req + 1
}
debug: i_t_beg <- (i_req - 1) * n_t_per_req + 1
debug: i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
debug: t_req <- times_todo[c(i_t_beg, i_t_end)]
debug: t_req_str <- format_ISO8601(t_req, usetz = "Z")
debug: if (verbose) message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
debug: message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
Fetching request 1 of 1 (2012-01-01 to 2012-12-01) ~ 19:31:33 UTC
debug: ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
    0), nc)
debug: unlink(ncs0)
debug: nc_retry <- T
debug: nc_n_try <- 1
debug: n_max_retries
debug: while (nc_retry) {
    res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
        url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
            bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
        time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
    if (inherits(res, "try-error")) {
        err <- attr(res, "condition")
        msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
        nc_n_try <- nc_n_try + 1
        if (nc_n_try > n_max_retries) {
            stop(msg)
        }
        else {
            message(msg, "\nRETRYing...")
            Sys.sleep(1)
        }
    }
    else {
        nc_retry <- F
    }
}
debug: res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
    url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
        bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
    time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
debug: if (inherits(res, "try-error")) {
    err <- attr(res, "condition")
    msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
    nc_n_try <- nc_n_try + 1
    if (nc_n_try > n_max_retries) {
        stop(msg)
    }
    else {
        message(msg, "\nRETRYing...")
        Sys.sleep(1)
    }
} else {
    nc_retry <- F
}
debug: nc_retry <- F
debug: (while) nc_retry
debug: i_req <- i_req + 1
debug: (while) i_req <= n_reqs
debug: ncs <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size > 
    0), nc)
debug: r <- terra::rast(ncs)
debug: stopifnot(all(class(terra::time(r)) %in% c("POSIXct", "POSIXt")))
debug: idx <- dplyr::pull(dplyr::filter(dplyr::arrange(dplyr::tibble(idx = 1:terra::nlyr(r), 
    time = terra::time(r)), time), !duplicated(time)), idx)
debug: r <- terra::subset(r, idx)
debug: stopifnot(terra::crs(r, proj = T) == wgs84)
debug: if (mask_tif) r <- terra::mask(r, sf_zones)
debug: lyrs <- glue("{var}|{terra::time(r)}")
debug: if (length(dims_other) > 0 && !all(length(dims[dims_other]) == 
    1)) stop(glue("Other dimensions not yet supported: {paste(dims_other, collapse = ',')}"))
debug: names(r) <- lyrs
debug: if (!is.null(rast_tif)) {
    if (fs::file_exists(rast_tif)) {
        r_tmp_tif <- tempfile(fileext = ".tif")
        r_tmp <- c(rast(rast_tif), r)
        r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
        terra::writeRaster(r_tmp, r_tmp_tif)
        fs::file_delete(rast_tif)
        fs::file_move(r_tmp_tif, rast_tif)
        rm(r)
        rm(r_tmp)
    }
    else {
        terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
    }
    r <- terra::rast(rast_tif)
}
debug: if (fs::file_exists(rast_tif)) {
    r_tmp_tif <- tempfile(fileext = ".tif")
    r_tmp <- c(rast(rast_tif), r)
    r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
    terra::writeRaster(r_tmp, r_tmp_tif)
    fs::file_delete(rast_tif)
    fs::file_move(r_tmp_tif, rast_tif)
    rm(r)
    rm(r_tmp)
} else {
    terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
}
debug: terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
debug: r <- terra::rast(rast_tif)
debug: d_r <- mutate(tidyr::pivot_longer(sf::st_drop_geometry(sf::st_as_sf(terra::zonal(x = r, 
    z = terra::vect(dplyr::select(sf_zones, dplyr::all_of(fld_zones))), 
    fun = zonal_fun, exact = T, na.rm = T, as.polygons = T))), 
    cols = -dplyr::any_of(fld_zones), names_to = "lyr", values_to = zonal_fun), 
    time = readr::parse_datetime(str_replace(lyr, glue("{var}\\|(.*)"), 
        "\\1")))
debug: if (!is.null(zonal_csv)) write_csv(d_r, zonal_csv)
debug: write_csv(d_r, zonal_csv)
debug: if (!keep_nc) unlink(dir_nc, recursive = T)
debug: unlink(dir_nc, recursive = T)
debug: return(d_r)
Downloading 1 requests, up to 490 time slices each
Called from: extractr::ed_extract(ed, var = v, sf_zones = ply, bbox = bb, 
    mask_tif = F, rast_tif = glue("{dir_out}/{nms}/{yr}.tif"), 
    zonal_fun = "mean", zonal_csv = glue("{dir_out}/{nms}/{yr}.csv"), 
    dir_nc = glue("{dir_out}/{nms}/{yr}_nc"), keep_nc = F, n_max_vals_per_req = 1e+05, 
    time_min = time_min, time_max = time_max, verbose = T)
debug: while (i_req <= n_reqs) {
    i_t_beg <- (i_req - 1) * n_t_per_req + 1
    i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
    t_req <- times_todo[c(i_t_beg, i_t_end)]
    t_req_str <- format_ISO8601(t_req, usetz = "Z")
    if (verbose) 
        message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
    ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
        ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
        0), nc)
    unlink(ncs0)
    nc_retry <- T
    nc_n_try <- 1
    n_max_retries
    while (nc_retry) {
        res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
            url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
                bbox[["xmax"]]), latitude = c(bbox[["ymin"]], 
                bbox[["ymax"]]), time = t_req_str, fmt = "nc", 
            store = rerddap::disk(path = dir_nc)))
        if (inherits(res, "try-error")) {
            err <- attr(res, "condition")
            msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
            nc_n_try <- nc_n_try + 1
            if (nc_n_try > n_max_retries) {
                stop(msg)
            }
            else {
                message(msg, "\nRETRYing...")
                Sys.sleep(1)
            }
        }
        else {
            nc_retry <- F
        }
    }
    i_req <- i_req + 1
}
debug: i_t_beg <- (i_req - 1) * n_t_per_req + 1
debug: i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
debug: t_req <- times_todo[c(i_t_beg, i_t_end)]
debug: t_req_str <- format_ISO8601(t_req, usetz = "Z")
debug: if (verbose) message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
debug: message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
Fetching request 1 of 1 (2013-01-01 to 2013-12-01) ~ 19:31:35 UTC
debug: ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
    0), nc)
debug: unlink(ncs0)
debug: nc_retry <- T
debug: nc_n_try <- 1
debug: n_max_retries
debug: while (nc_retry) {
    res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
        url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
            bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
        time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
    if (inherits(res, "try-error")) {
        err <- attr(res, "condition")
        msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
        nc_n_try <- nc_n_try + 1
        if (nc_n_try > n_max_retries) {
            stop(msg)
        }
        else {
            message(msg, "\nRETRYing...")
            Sys.sleep(1)
        }
    }
    else {
        nc_retry <- F
    }
}
debug: res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
    url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
        bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
    time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
debug: if (inherits(res, "try-error")) {
    err <- attr(res, "condition")
    msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
    nc_n_try <- nc_n_try + 1
    if (nc_n_try > n_max_retries) {
        stop(msg)
    }
    else {
        message(msg, "\nRETRYing...")
        Sys.sleep(1)
    }
} else {
    nc_retry <- F
}
debug: nc_retry <- F
debug: (while) nc_retry
debug: i_req <- i_req + 1
debug: (while) i_req <= n_reqs
debug: ncs <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size > 
    0), nc)
debug: r <- terra::rast(ncs)
debug: stopifnot(all(class(terra::time(r)) %in% c("POSIXct", "POSIXt")))
debug: idx <- dplyr::pull(dplyr::filter(dplyr::arrange(dplyr::tibble(idx = 1:terra::nlyr(r), 
    time = terra::time(r)), time), !duplicated(time)), idx)
debug: r <- terra::subset(r, idx)
debug: stopifnot(terra::crs(r, proj = T) == wgs84)
debug: if (mask_tif) r <- terra::mask(r, sf_zones)
debug: lyrs <- glue("{var}|{terra::time(r)}")
debug: if (length(dims_other) > 0 && !all(length(dims[dims_other]) == 
    1)) stop(glue("Other dimensions not yet supported: {paste(dims_other, collapse = ',')}"))
debug: names(r) <- lyrs
debug: if (!is.null(rast_tif)) {
    if (fs::file_exists(rast_tif)) {
        r_tmp_tif <- tempfile(fileext = ".tif")
        r_tmp <- c(rast(rast_tif), r)
        r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
        terra::writeRaster(r_tmp, r_tmp_tif)
        fs::file_delete(rast_tif)
        fs::file_move(r_tmp_tif, rast_tif)
        rm(r)
        rm(r_tmp)
    }
    else {
        terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
    }
    r <- terra::rast(rast_tif)
}
debug: if (fs::file_exists(rast_tif)) {
    r_tmp_tif <- tempfile(fileext = ".tif")
    r_tmp <- c(rast(rast_tif), r)
    r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
    terra::writeRaster(r_tmp, r_tmp_tif)
    fs::file_delete(rast_tif)
    fs::file_move(r_tmp_tif, rast_tif)
    rm(r)
    rm(r_tmp)
} else {
    terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
}
debug: terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
debug: r <- terra::rast(rast_tif)
debug: d_r <- mutate(tidyr::pivot_longer(sf::st_drop_geometry(sf::st_as_sf(terra::zonal(x = r, 
    z = terra::vect(dplyr::select(sf_zones, dplyr::all_of(fld_zones))), 
    fun = zonal_fun, exact = T, na.rm = T, as.polygons = T))), 
    cols = -dplyr::any_of(fld_zones), names_to = "lyr", values_to = zonal_fun), 
    time = readr::parse_datetime(str_replace(lyr, glue("{var}\\|(.*)"), 
        "\\1")))
debug: if (!is.null(zonal_csv)) write_csv(d_r, zonal_csv)
debug: write_csv(d_r, zonal_csv)
debug: if (!keep_nc) unlink(dir_nc, recursive = T)
debug: unlink(dir_nc, recursive = T)
debug: return(d_r)
Downloading 1 requests, up to 490 time slices each
Called from: extractr::ed_extract(ed, var = v, sf_zones = ply, bbox = bb, 
    mask_tif = F, rast_tif = glue("{dir_out}/{nms}/{yr}.tif"), 
    zonal_fun = "mean", zonal_csv = glue("{dir_out}/{nms}/{yr}.csv"), 
    dir_nc = glue("{dir_out}/{nms}/{yr}_nc"), keep_nc = F, n_max_vals_per_req = 1e+05, 
    time_min = time_min, time_max = time_max, verbose = T)
debug: while (i_req <= n_reqs) {
    i_t_beg <- (i_req - 1) * n_t_per_req + 1
    i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
    t_req <- times_todo[c(i_t_beg, i_t_end)]
    t_req_str <- format_ISO8601(t_req, usetz = "Z")
    if (verbose) 
        message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
    ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
        ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
        0), nc)
    unlink(ncs0)
    nc_retry <- T
    nc_n_try <- 1
    n_max_retries
    while (nc_retry) {
        res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
            url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
                bbox[["xmax"]]), latitude = c(bbox[["ymin"]], 
                bbox[["ymax"]]), time = t_req_str, fmt = "nc", 
            store = rerddap::disk(path = dir_nc)))
        if (inherits(res, "try-error")) {
            err <- attr(res, "condition")
            msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
            nc_n_try <- nc_n_try + 1
            if (nc_n_try > n_max_retries) {
                stop(msg)
            }
            else {
                message(msg, "\nRETRYing...")
                Sys.sleep(1)
            }
        }
        else {
            nc_retry <- F
        }
    }
    i_req <- i_req + 1
}
debug: i_t_beg <- (i_req - 1) * n_t_per_req + 1
debug: i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
debug: t_req <- times_todo[c(i_t_beg, i_t_end)]
debug: t_req_str <- format_ISO8601(t_req, usetz = "Z")
debug: if (verbose) message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
debug: message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
Fetching request 1 of 1 (2014-01-01 to 2014-12-01) ~ 19:31:37 UTC
debug: ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
    0), nc)
debug: unlink(ncs0)
debug: nc_retry <- T
debug: nc_n_try <- 1
debug: n_max_retries
debug: while (nc_retry) {
    res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
        url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
            bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
        time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
    if (inherits(res, "try-error")) {
        err <- attr(res, "condition")
        msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
        nc_n_try <- nc_n_try + 1
        if (nc_n_try > n_max_retries) {
            stop(msg)
        }
        else {
            message(msg, "\nRETRYing...")
            Sys.sleep(1)
        }
    }
    else {
        nc_retry <- F
    }
}
debug: res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
    url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
        bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
    time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
debug: if (inherits(res, "try-error")) {
    err <- attr(res, "condition")
    msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
    nc_n_try <- nc_n_try + 1
    if (nc_n_try > n_max_retries) {
        stop(msg)
    }
    else {
        message(msg, "\nRETRYing...")
        Sys.sleep(1)
    }
} else {
    nc_retry <- F
}
debug: nc_retry <- F
debug: (while) nc_retry
debug: i_req <- i_req + 1
debug: (while) i_req <= n_reqs
debug: ncs <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size > 
    0), nc)
debug: r <- terra::rast(ncs)
debug: stopifnot(all(class(terra::time(r)) %in% c("POSIXct", "POSIXt")))
debug: idx <- dplyr::pull(dplyr::filter(dplyr::arrange(dplyr::tibble(idx = 1:terra::nlyr(r), 
    time = terra::time(r)), time), !duplicated(time)), idx)
debug: r <- terra::subset(r, idx)
debug: stopifnot(terra::crs(r, proj = T) == wgs84)
debug: if (mask_tif) r <- terra::mask(r, sf_zones)
debug: lyrs <- glue("{var}|{terra::time(r)}")
debug: if (length(dims_other) > 0 && !all(length(dims[dims_other]) == 
    1)) stop(glue("Other dimensions not yet supported: {paste(dims_other, collapse = ',')}"))
debug: names(r) <- lyrs
debug: if (!is.null(rast_tif)) {
    if (fs::file_exists(rast_tif)) {
        r_tmp_tif <- tempfile(fileext = ".tif")
        r_tmp <- c(rast(rast_tif), r)
        r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
        terra::writeRaster(r_tmp, r_tmp_tif)
        fs::file_delete(rast_tif)
        fs::file_move(r_tmp_tif, rast_tif)
        rm(r)
        rm(r_tmp)
    }
    else {
        terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
    }
    r <- terra::rast(rast_tif)
}
debug: if (fs::file_exists(rast_tif)) {
    r_tmp_tif <- tempfile(fileext = ".tif")
    r_tmp <- c(rast(rast_tif), r)
    r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
    terra::writeRaster(r_tmp, r_tmp_tif)
    fs::file_delete(rast_tif)
    fs::file_move(r_tmp_tif, rast_tif)
    rm(r)
    rm(r_tmp)
} else {
    terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
}
debug: terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
debug: r <- terra::rast(rast_tif)
debug: d_r <- mutate(tidyr::pivot_longer(sf::st_drop_geometry(sf::st_as_sf(terra::zonal(x = r, 
    z = terra::vect(dplyr::select(sf_zones, dplyr::all_of(fld_zones))), 
    fun = zonal_fun, exact = T, na.rm = T, as.polygons = T))), 
    cols = -dplyr::any_of(fld_zones), names_to = "lyr", values_to = zonal_fun), 
    time = readr::parse_datetime(str_replace(lyr, glue("{var}\\|(.*)"), 
        "\\1")))
debug: if (!is.null(zonal_csv)) write_csv(d_r, zonal_csv)
debug: write_csv(d_r, zonal_csv)
debug: if (!keep_nc) unlink(dir_nc, recursive = T)
debug: unlink(dir_nc, recursive = T)
debug: return(d_r)
Downloading 1 requests, up to 490 time slices each
Called from: extractr::ed_extract(ed, var = v, sf_zones = ply, bbox = bb, 
    mask_tif = F, rast_tif = glue("{dir_out}/{nms}/{yr}.tif"), 
    zonal_fun = "mean", zonal_csv = glue("{dir_out}/{nms}/{yr}.csv"), 
    dir_nc = glue("{dir_out}/{nms}/{yr}_nc"), keep_nc = F, n_max_vals_per_req = 1e+05, 
    time_min = time_min, time_max = time_max, verbose = T)
debug: while (i_req <= n_reqs) {
    i_t_beg <- (i_req - 1) * n_t_per_req + 1
    i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
    t_req <- times_todo[c(i_t_beg, i_t_end)]
    t_req_str <- format_ISO8601(t_req, usetz = "Z")
    if (verbose) 
        message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
    ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
        ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
        0), nc)
    unlink(ncs0)
    nc_retry <- T
    nc_n_try <- 1
    n_max_retries
    while (nc_retry) {
        res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
            url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
                bbox[["xmax"]]), latitude = c(bbox[["ymin"]], 
                bbox[["ymax"]]), time = t_req_str, fmt = "nc", 
            store = rerddap::disk(path = dir_nc)))
        if (inherits(res, "try-error")) {
            err <- attr(res, "condition")
            msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
            nc_n_try <- nc_n_try + 1
            if (nc_n_try > n_max_retries) {
                stop(msg)
            }
            else {
                message(msg, "\nRETRYing...")
                Sys.sleep(1)
            }
        }
        else {
            nc_retry <- F
        }
    }
    i_req <- i_req + 1
}
debug: i_t_beg <- (i_req - 1) * n_t_per_req + 1
debug: i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
debug: t_req <- times_todo[c(i_t_beg, i_t_end)]
debug: t_req_str <- format_ISO8601(t_req, usetz = "Z")
debug: if (verbose) message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
debug: message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
Fetching request 1 of 1 (2015-01-01 to 2015-12-01) ~ 19:31:39 UTC
debug: ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
    0), nc)
debug: unlink(ncs0)
debug: nc_retry <- T
debug: nc_n_try <- 1
debug: n_max_retries
debug: while (nc_retry) {
    res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
        url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
            bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
        time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
    if (inherits(res, "try-error")) {
        err <- attr(res, "condition")
        msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
        nc_n_try <- nc_n_try + 1
        if (nc_n_try > n_max_retries) {
            stop(msg)
        }
        else {
            message(msg, "\nRETRYing...")
            Sys.sleep(1)
        }
    }
    else {
        nc_retry <- F
    }
}
debug: res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
    url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
        bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
    time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
debug: if (inherits(res, "try-error")) {
    err <- attr(res, "condition")
    msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
    nc_n_try <- nc_n_try + 1
    if (nc_n_try > n_max_retries) {
        stop(msg)
    }
    else {
        message(msg, "\nRETRYing...")
        Sys.sleep(1)
    }
} else {
    nc_retry <- F
}
debug: nc_retry <- F
debug: (while) nc_retry
debug: i_req <- i_req + 1
debug: (while) i_req <= n_reqs
debug: ncs <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size > 
    0), nc)
debug: r <- terra::rast(ncs)
debug: stopifnot(all(class(terra::time(r)) %in% c("POSIXct", "POSIXt")))
debug: idx <- dplyr::pull(dplyr::filter(dplyr::arrange(dplyr::tibble(idx = 1:terra::nlyr(r), 
    time = terra::time(r)), time), !duplicated(time)), idx)
debug: r <- terra::subset(r, idx)
debug: stopifnot(terra::crs(r, proj = T) == wgs84)
debug: if (mask_tif) r <- terra::mask(r, sf_zones)
debug: lyrs <- glue("{var}|{terra::time(r)}")
debug: if (length(dims_other) > 0 && !all(length(dims[dims_other]) == 
    1)) stop(glue("Other dimensions not yet supported: {paste(dims_other, collapse = ',')}"))
debug: names(r) <- lyrs
debug: if (!is.null(rast_tif)) {
    if (fs::file_exists(rast_tif)) {
        r_tmp_tif <- tempfile(fileext = ".tif")
        r_tmp <- c(rast(rast_tif), r)
        r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
        terra::writeRaster(r_tmp, r_tmp_tif)
        fs::file_delete(rast_tif)
        fs::file_move(r_tmp_tif, rast_tif)
        rm(r)
        rm(r_tmp)
    }
    else {
        terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
    }
    r <- terra::rast(rast_tif)
}
debug: if (fs::file_exists(rast_tif)) {
    r_tmp_tif <- tempfile(fileext = ".tif")
    r_tmp <- c(rast(rast_tif), r)
    r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
    terra::writeRaster(r_tmp, r_tmp_tif)
    fs::file_delete(rast_tif)
    fs::file_move(r_tmp_tif, rast_tif)
    rm(r)
    rm(r_tmp)
} else {
    terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
}
debug: terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
debug: r <- terra::rast(rast_tif)
debug: d_r <- mutate(tidyr::pivot_longer(sf::st_drop_geometry(sf::st_as_sf(terra::zonal(x = r, 
    z = terra::vect(dplyr::select(sf_zones, dplyr::all_of(fld_zones))), 
    fun = zonal_fun, exact = T, na.rm = T, as.polygons = T))), 
    cols = -dplyr::any_of(fld_zones), names_to = "lyr", values_to = zonal_fun), 
    time = readr::parse_datetime(str_replace(lyr, glue("{var}\\|(.*)"), 
        "\\1")))
debug: if (!is.null(zonal_csv)) write_csv(d_r, zonal_csv)
debug: write_csv(d_r, zonal_csv)
debug: if (!keep_nc) unlink(dir_nc, recursive = T)
debug: unlink(dir_nc, recursive = T)
debug: return(d_r)
Downloading 1 requests, up to 490 time slices each
Called from: extractr::ed_extract(ed, var = v, sf_zones = ply, bbox = bb, 
    mask_tif = F, rast_tif = glue("{dir_out}/{nms}/{yr}.tif"), 
    zonal_fun = "mean", zonal_csv = glue("{dir_out}/{nms}/{yr}.csv"), 
    dir_nc = glue("{dir_out}/{nms}/{yr}_nc"), keep_nc = F, n_max_vals_per_req = 1e+05, 
    time_min = time_min, time_max = time_max, verbose = T)
debug: while (i_req <= n_reqs) {
    i_t_beg <- (i_req - 1) * n_t_per_req + 1
    i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
    t_req <- times_todo[c(i_t_beg, i_t_end)]
    t_req_str <- format_ISO8601(t_req, usetz = "Z")
    if (verbose) 
        message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
    ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
        ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
        0), nc)
    unlink(ncs0)
    nc_retry <- T
    nc_n_try <- 1
    n_max_retries
    while (nc_retry) {
        res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
            url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
                bbox[["xmax"]]), latitude = c(bbox[["ymin"]], 
                bbox[["ymax"]]), time = t_req_str, fmt = "nc", 
            store = rerddap::disk(path = dir_nc)))
        if (inherits(res, "try-error")) {
            err <- attr(res, "condition")
            msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
            nc_n_try <- nc_n_try + 1
            if (nc_n_try > n_max_retries) {
                stop(msg)
            }
            else {
                message(msg, "\nRETRYing...")
                Sys.sleep(1)
            }
        }
        else {
            nc_retry <- F
        }
    }
    i_req <- i_req + 1
}
debug: i_t_beg <- (i_req - 1) * n_t_per_req + 1
debug: i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
debug: t_req <- times_todo[c(i_t_beg, i_t_end)]
debug: t_req_str <- format_ISO8601(t_req, usetz = "Z")
debug: if (verbose) message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
debug: message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
Fetching request 1 of 1 (2016-01-01 to 2016-12-01) ~ 19:31:41 UTC
debug: ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
    0), nc)
debug: unlink(ncs0)
debug: nc_retry <- T
debug: nc_n_try <- 1
debug: n_max_retries
debug: while (nc_retry) {
    res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
        url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
            bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
        time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
    if (inherits(res, "try-error")) {
        err <- attr(res, "condition")
        msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
        nc_n_try <- nc_n_try + 1
        if (nc_n_try > n_max_retries) {
            stop(msg)
        }
        else {
            message(msg, "\nRETRYing...")
            Sys.sleep(1)
        }
    }
    else {
        nc_retry <- F
    }
}
debug: res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
    url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
        bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
    time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
debug: if (inherits(res, "try-error")) {
    err <- attr(res, "condition")
    msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
    nc_n_try <- nc_n_try + 1
    if (nc_n_try > n_max_retries) {
        stop(msg)
    }
    else {
        message(msg, "\nRETRYing...")
        Sys.sleep(1)
    }
} else {
    nc_retry <- F
}
debug: nc_retry <- F
debug: (while) nc_retry
debug: i_req <- i_req + 1
debug: (while) i_req <= n_reqs
debug: ncs <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size > 
    0), nc)
debug: r <- terra::rast(ncs)
debug: stopifnot(all(class(terra::time(r)) %in% c("POSIXct", "POSIXt")))
debug: idx <- dplyr::pull(dplyr::filter(dplyr::arrange(dplyr::tibble(idx = 1:terra::nlyr(r), 
    time = terra::time(r)), time), !duplicated(time)), idx)
debug: r <- terra::subset(r, idx)
debug: stopifnot(terra::crs(r, proj = T) == wgs84)
debug: if (mask_tif) r <- terra::mask(r, sf_zones)
debug: lyrs <- glue("{var}|{terra::time(r)}")
debug: if (length(dims_other) > 0 && !all(length(dims[dims_other]) == 
    1)) stop(glue("Other dimensions not yet supported: {paste(dims_other, collapse = ',')}"))
debug: names(r) <- lyrs
debug: if (!is.null(rast_tif)) {
    if (fs::file_exists(rast_tif)) {
        r_tmp_tif <- tempfile(fileext = ".tif")
        r_tmp <- c(rast(rast_tif), r)
        r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
        terra::writeRaster(r_tmp, r_tmp_tif)
        fs::file_delete(rast_tif)
        fs::file_move(r_tmp_tif, rast_tif)
        rm(r)
        rm(r_tmp)
    }
    else {
        terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
    }
    r <- terra::rast(rast_tif)
}
debug: if (fs::file_exists(rast_tif)) {
    r_tmp_tif <- tempfile(fileext = ".tif")
    r_tmp <- c(rast(rast_tif), r)
    r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
    terra::writeRaster(r_tmp, r_tmp_tif)
    fs::file_delete(rast_tif)
    fs::file_move(r_tmp_tif, rast_tif)
    rm(r)
    rm(r_tmp)
} else {
    terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
}
debug: terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
debug: r <- terra::rast(rast_tif)
debug: d_r <- mutate(tidyr::pivot_longer(sf::st_drop_geometry(sf::st_as_sf(terra::zonal(x = r, 
    z = terra::vect(dplyr::select(sf_zones, dplyr::all_of(fld_zones))), 
    fun = zonal_fun, exact = T, na.rm = T, as.polygons = T))), 
    cols = -dplyr::any_of(fld_zones), names_to = "lyr", values_to = zonal_fun), 
    time = readr::parse_datetime(str_replace(lyr, glue("{var}\\|(.*)"), 
        "\\1")))
debug: if (!is.null(zonal_csv)) write_csv(d_r, zonal_csv)
debug: write_csv(d_r, zonal_csv)
debug: if (!keep_nc) unlink(dir_nc, recursive = T)
debug: unlink(dir_nc, recursive = T)
debug: return(d_r)
Downloading 1 requests, up to 490 time slices each
Called from: extractr::ed_extract(ed, var = v, sf_zones = ply, bbox = bb, 
    mask_tif = F, rast_tif = glue("{dir_out}/{nms}/{yr}.tif"), 
    zonal_fun = "mean", zonal_csv = glue("{dir_out}/{nms}/{yr}.csv"), 
    dir_nc = glue("{dir_out}/{nms}/{yr}_nc"), keep_nc = F, n_max_vals_per_req = 1e+05, 
    time_min = time_min, time_max = time_max, verbose = T)
debug: while (i_req <= n_reqs) {
    i_t_beg <- (i_req - 1) * n_t_per_req + 1
    i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
    t_req <- times_todo[c(i_t_beg, i_t_end)]
    t_req_str <- format_ISO8601(t_req, usetz = "Z")
    if (verbose) 
        message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
    ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
        ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
        0), nc)
    unlink(ncs0)
    nc_retry <- T
    nc_n_try <- 1
    n_max_retries
    while (nc_retry) {
        res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
            url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
                bbox[["xmax"]]), latitude = c(bbox[["ymin"]], 
                bbox[["ymax"]]), time = t_req_str, fmt = "nc", 
            store = rerddap::disk(path = dir_nc)))
        if (inherits(res, "try-error")) {
            err <- attr(res, "condition")
            msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
            nc_n_try <- nc_n_try + 1
            if (nc_n_try > n_max_retries) {
                stop(msg)
            }
            else {
                message(msg, "\nRETRYing...")
                Sys.sleep(1)
            }
        }
        else {
            nc_retry <- F
        }
    }
    i_req <- i_req + 1
}
debug: i_t_beg <- (i_req - 1) * n_t_per_req + 1
debug: i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
debug: t_req <- times_todo[c(i_t_beg, i_t_end)]
debug: t_req_str <- format_ISO8601(t_req, usetz = "Z")
debug: if (verbose) message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
debug: message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
Fetching request 1 of 1 (2017-01-01 to 2017-12-01) ~ 19:31:43 UTC
debug: ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
    0), nc)
debug: unlink(ncs0)
debug: nc_retry <- T
debug: nc_n_try <- 1
debug: n_max_retries
debug: while (nc_retry) {
    res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
        url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
            bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
        time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
    if (inherits(res, "try-error")) {
        err <- attr(res, "condition")
        msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
        nc_n_try <- nc_n_try + 1
        if (nc_n_try > n_max_retries) {
            stop(msg)
        }
        else {
            message(msg, "\nRETRYing...")
            Sys.sleep(1)
        }
    }
    else {
        nc_retry <- F
    }
}
debug: res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
    url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
        bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
    time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
debug: if (inherits(res, "try-error")) {
    err <- attr(res, "condition")
    msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
    nc_n_try <- nc_n_try + 1
    if (nc_n_try > n_max_retries) {
        stop(msg)
    }
    else {
        message(msg, "\nRETRYing...")
        Sys.sleep(1)
    }
} else {
    nc_retry <- F
}
debug: nc_retry <- F
debug: (while) nc_retry
debug: i_req <- i_req + 1
debug: (while) i_req <= n_reqs
debug: ncs <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size > 
    0), nc)
debug: r <- terra::rast(ncs)
debug: stopifnot(all(class(terra::time(r)) %in% c("POSIXct", "POSIXt")))
debug: idx <- dplyr::pull(dplyr::filter(dplyr::arrange(dplyr::tibble(idx = 1:terra::nlyr(r), 
    time = terra::time(r)), time), !duplicated(time)), idx)
debug: r <- terra::subset(r, idx)
debug: stopifnot(terra::crs(r, proj = T) == wgs84)
debug: if (mask_tif) r <- terra::mask(r, sf_zones)
debug: lyrs <- glue("{var}|{terra::time(r)}")
debug: if (length(dims_other) > 0 && !all(length(dims[dims_other]) == 
    1)) stop(glue("Other dimensions not yet supported: {paste(dims_other, collapse = ',')}"))
debug: names(r) <- lyrs
debug: if (!is.null(rast_tif)) {
    if (fs::file_exists(rast_tif)) {
        r_tmp_tif <- tempfile(fileext = ".tif")
        r_tmp <- c(rast(rast_tif), r)
        r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
        terra::writeRaster(r_tmp, r_tmp_tif)
        fs::file_delete(rast_tif)
        fs::file_move(r_tmp_tif, rast_tif)
        rm(r)
        rm(r_tmp)
    }
    else {
        terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
    }
    r <- terra::rast(rast_tif)
}
debug: if (fs::file_exists(rast_tif)) {
    r_tmp_tif <- tempfile(fileext = ".tif")
    r_tmp <- c(rast(rast_tif), r)
    r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
    terra::writeRaster(r_tmp, r_tmp_tif)
    fs::file_delete(rast_tif)
    fs::file_move(r_tmp_tif, rast_tif)
    rm(r)
    rm(r_tmp)
} else {
    terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
}
debug: terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
debug: r <- terra::rast(rast_tif)
debug: d_r <- mutate(tidyr::pivot_longer(sf::st_drop_geometry(sf::st_as_sf(terra::zonal(x = r, 
    z = terra::vect(dplyr::select(sf_zones, dplyr::all_of(fld_zones))), 
    fun = zonal_fun, exact = T, na.rm = T, as.polygons = T))), 
    cols = -dplyr::any_of(fld_zones), names_to = "lyr", values_to = zonal_fun), 
    time = readr::parse_datetime(str_replace(lyr, glue("{var}\\|(.*)"), 
        "\\1")))
debug: if (!is.null(zonal_csv)) write_csv(d_r, zonal_csv)
debug: write_csv(d_r, zonal_csv)
debug: if (!keep_nc) unlink(dir_nc, recursive = T)
debug: unlink(dir_nc, recursive = T)
debug: return(d_r)
Downloading 1 requests, up to 490 time slices each
Called from: extractr::ed_extract(ed, var = v, sf_zones = ply, bbox = bb, 
    mask_tif = F, rast_tif = glue("{dir_out}/{nms}/{yr}.tif"), 
    zonal_fun = "mean", zonal_csv = glue("{dir_out}/{nms}/{yr}.csv"), 
    dir_nc = glue("{dir_out}/{nms}/{yr}_nc"), keep_nc = F, n_max_vals_per_req = 1e+05, 
    time_min = time_min, time_max = time_max, verbose = T)
debug: while (i_req <= n_reqs) {
    i_t_beg <- (i_req - 1) * n_t_per_req + 1
    i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
    t_req <- times_todo[c(i_t_beg, i_t_end)]
    t_req_str <- format_ISO8601(t_req, usetz = "Z")
    if (verbose) 
        message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
    ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
        ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
        0), nc)
    unlink(ncs0)
    nc_retry <- T
    nc_n_try <- 1
    n_max_retries
    while (nc_retry) {
        res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
            url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
                bbox[["xmax"]]), latitude = c(bbox[["ymin"]], 
                bbox[["ymax"]]), time = t_req_str, fmt = "nc", 
            store = rerddap::disk(path = dir_nc)))
        if (inherits(res, "try-error")) {
            err <- attr(res, "condition")
            msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
            nc_n_try <- nc_n_try + 1
            if (nc_n_try > n_max_retries) {
                stop(msg)
            }
            else {
                message(msg, "\nRETRYing...")
                Sys.sleep(1)
            }
        }
        else {
            nc_retry <- F
        }
    }
    i_req <- i_req + 1
}
debug: i_t_beg <- (i_req - 1) * n_t_per_req + 1
debug: i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
debug: t_req <- times_todo[c(i_t_beg, i_t_end)]
debug: t_req_str <- format_ISO8601(t_req, usetz = "Z")
debug: if (verbose) message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
debug: message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
Fetching request 1 of 1 (2018-01-01 to 2018-12-01) ~ 19:31:44 UTC
debug: ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
    0), nc)
debug: unlink(ncs0)
debug: nc_retry <- T
debug: nc_n_try <- 1
debug: n_max_retries
debug: while (nc_retry) {
    res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
        url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
            bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
        time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
    if (inherits(res, "try-error")) {
        err <- attr(res, "condition")
        msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
        nc_n_try <- nc_n_try + 1
        if (nc_n_try > n_max_retries) {
            stop(msg)
        }
        else {
            message(msg, "\nRETRYing...")
            Sys.sleep(1)
        }
    }
    else {
        nc_retry <- F
    }
}
debug: res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
    url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
        bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
    time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
debug: if (inherits(res, "try-error")) {
    err <- attr(res, "condition")
    msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
    nc_n_try <- nc_n_try + 1
    if (nc_n_try > n_max_retries) {
        stop(msg)
    }
    else {
        message(msg, "\nRETRYing...")
        Sys.sleep(1)
    }
} else {
    nc_retry <- F
}
debug: nc_retry <- F
debug: (while) nc_retry
debug: i_req <- i_req + 1
debug: (while) i_req <= n_reqs
debug: ncs <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size > 
    0), nc)
debug: r <- terra::rast(ncs)
debug: stopifnot(all(class(terra::time(r)) %in% c("POSIXct", "POSIXt")))
debug: idx <- dplyr::pull(dplyr::filter(dplyr::arrange(dplyr::tibble(idx = 1:terra::nlyr(r), 
    time = terra::time(r)), time), !duplicated(time)), idx)
debug: r <- terra::subset(r, idx)
debug: stopifnot(terra::crs(r, proj = T) == wgs84)
debug: if (mask_tif) r <- terra::mask(r, sf_zones)
debug: lyrs <- glue("{var}|{terra::time(r)}")
debug: if (length(dims_other) > 0 && !all(length(dims[dims_other]) == 
    1)) stop(glue("Other dimensions not yet supported: {paste(dims_other, collapse = ',')}"))
debug: names(r) <- lyrs
debug: if (!is.null(rast_tif)) {
    if (fs::file_exists(rast_tif)) {
        r_tmp_tif <- tempfile(fileext = ".tif")
        r_tmp <- c(rast(rast_tif), r)
        r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
        terra::writeRaster(r_tmp, r_tmp_tif)
        fs::file_delete(rast_tif)
        fs::file_move(r_tmp_tif, rast_tif)
        rm(r)
        rm(r_tmp)
    }
    else {
        terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
    }
    r <- terra::rast(rast_tif)
}
debug: if (fs::file_exists(rast_tif)) {
    r_tmp_tif <- tempfile(fileext = ".tif")
    r_tmp <- c(rast(rast_tif), r)
    r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
    terra::writeRaster(r_tmp, r_tmp_tif)
    fs::file_delete(rast_tif)
    fs::file_move(r_tmp_tif, rast_tif)
    rm(r)
    rm(r_tmp)
} else {
    terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
}
debug: terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
debug: r <- terra::rast(rast_tif)
debug: d_r <- mutate(tidyr::pivot_longer(sf::st_drop_geometry(sf::st_as_sf(terra::zonal(x = r, 
    z = terra::vect(dplyr::select(sf_zones, dplyr::all_of(fld_zones))), 
    fun = zonal_fun, exact = T, na.rm = T, as.polygons = T))), 
    cols = -dplyr::any_of(fld_zones), names_to = "lyr", values_to = zonal_fun), 
    time = readr::parse_datetime(str_replace(lyr, glue("{var}\\|(.*)"), 
        "\\1")))
debug: if (!is.null(zonal_csv)) write_csv(d_r, zonal_csv)
debug: write_csv(d_r, zonal_csv)
debug: if (!keep_nc) unlink(dir_nc, recursive = T)
debug: unlink(dir_nc, recursive = T)
debug: return(d_r)
Downloading 1 requests, up to 490 time slices each
Called from: extractr::ed_extract(ed, var = v, sf_zones = ply, bbox = bb, 
    mask_tif = F, rast_tif = glue("{dir_out}/{nms}/{yr}.tif"), 
    zonal_fun = "mean", zonal_csv = glue("{dir_out}/{nms}/{yr}.csv"), 
    dir_nc = glue("{dir_out}/{nms}/{yr}_nc"), keep_nc = F, n_max_vals_per_req = 1e+05, 
    time_min = time_min, time_max = time_max, verbose = T)
debug: while (i_req <= n_reqs) {
    i_t_beg <- (i_req - 1) * n_t_per_req + 1
    i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
    t_req <- times_todo[c(i_t_beg, i_t_end)]
    t_req_str <- format_ISO8601(t_req, usetz = "Z")
    if (verbose) 
        message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
    ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
        ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
        0), nc)
    unlink(ncs0)
    nc_retry <- T
    nc_n_try <- 1
    n_max_retries
    while (nc_retry) {
        res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
            url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
                bbox[["xmax"]]), latitude = c(bbox[["ymin"]], 
                bbox[["ymax"]]), time = t_req_str, fmt = "nc", 
            store = rerddap::disk(path = dir_nc)))
        if (inherits(res, "try-error")) {
            err <- attr(res, "condition")
            msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
            nc_n_try <- nc_n_try + 1
            if (nc_n_try > n_max_retries) {
                stop(msg)
            }
            else {
                message(msg, "\nRETRYing...")
                Sys.sleep(1)
            }
        }
        else {
            nc_retry <- F
        }
    }
    i_req <- i_req + 1
}
debug: i_t_beg <- (i_req - 1) * n_t_per_req + 1
debug: i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
debug: t_req <- times_todo[c(i_t_beg, i_t_end)]
debug: t_req_str <- format_ISO8601(t_req, usetz = "Z")
debug: if (verbose) message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
debug: message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
Fetching request 1 of 1 (2019-01-01 to 2019-12-01) ~ 19:31:46 UTC
debug: ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
    0), nc)
debug: unlink(ncs0)
debug: nc_retry <- T
debug: nc_n_try <- 1
debug: n_max_retries
debug: while (nc_retry) {
    res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
        url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
            bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
        time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
    if (inherits(res, "try-error")) {
        err <- attr(res, "condition")
        msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
        nc_n_try <- nc_n_try + 1
        if (nc_n_try > n_max_retries) {
            stop(msg)
        }
        else {
            message(msg, "\nRETRYing...")
            Sys.sleep(1)
        }
    }
    else {
        nc_retry <- F
    }
}
debug: res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
    url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
        bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
    time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
debug: if (inherits(res, "try-error")) {
    err <- attr(res, "condition")
    msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
    nc_n_try <- nc_n_try + 1
    if (nc_n_try > n_max_retries) {
        stop(msg)
    }
    else {
        message(msg, "\nRETRYing...")
        Sys.sleep(1)
    }
} else {
    nc_retry <- F
}
debug: nc_retry <- F
debug: (while) nc_retry
debug: i_req <- i_req + 1
debug: (while) i_req <= n_reqs
debug: ncs <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size > 
    0), nc)
debug: r <- terra::rast(ncs)
debug: stopifnot(all(class(terra::time(r)) %in% c("POSIXct", "POSIXt")))
debug: idx <- dplyr::pull(dplyr::filter(dplyr::arrange(dplyr::tibble(idx = 1:terra::nlyr(r), 
    time = terra::time(r)), time), !duplicated(time)), idx)
debug: r <- terra::subset(r, idx)
debug: stopifnot(terra::crs(r, proj = T) == wgs84)
debug: if (mask_tif) r <- terra::mask(r, sf_zones)
debug: lyrs <- glue("{var}|{terra::time(r)}")
debug: if (length(dims_other) > 0 && !all(length(dims[dims_other]) == 
    1)) stop(glue("Other dimensions not yet supported: {paste(dims_other, collapse = ',')}"))
debug: names(r) <- lyrs
debug: if (!is.null(rast_tif)) {
    if (fs::file_exists(rast_tif)) {
        r_tmp_tif <- tempfile(fileext = ".tif")
        r_tmp <- c(rast(rast_tif), r)
        r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
        terra::writeRaster(r_tmp, r_tmp_tif)
        fs::file_delete(rast_tif)
        fs::file_move(r_tmp_tif, rast_tif)
        rm(r)
        rm(r_tmp)
    }
    else {
        terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
    }
    r <- terra::rast(rast_tif)
}
debug: if (fs::file_exists(rast_tif)) {
    r_tmp_tif <- tempfile(fileext = ".tif")
    r_tmp <- c(rast(rast_tif), r)
    r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
    terra::writeRaster(r_tmp, r_tmp_tif)
    fs::file_delete(rast_tif)
    fs::file_move(r_tmp_tif, rast_tif)
    rm(r)
    rm(r_tmp)
} else {
    terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
}
debug: terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
debug: r <- terra::rast(rast_tif)
debug: d_r <- mutate(tidyr::pivot_longer(sf::st_drop_geometry(sf::st_as_sf(terra::zonal(x = r, 
    z = terra::vect(dplyr::select(sf_zones, dplyr::all_of(fld_zones))), 
    fun = zonal_fun, exact = T, na.rm = T, as.polygons = T))), 
    cols = -dplyr::any_of(fld_zones), names_to = "lyr", values_to = zonal_fun), 
    time = readr::parse_datetime(str_replace(lyr, glue("{var}\\|(.*)"), 
        "\\1")))
debug: if (!is.null(zonal_csv)) write_csv(d_r, zonal_csv)
debug: write_csv(d_r, zonal_csv)
debug: if (!keep_nc) unlink(dir_nc, recursive = T)
debug: unlink(dir_nc, recursive = T)
debug: return(d_r)
Downloading 1 requests, up to 490 time slices each
Called from: extractr::ed_extract(ed, var = v, sf_zones = ply, bbox = bb, 
    mask_tif = F, rast_tif = glue("{dir_out}/{nms}/{yr}.tif"), 
    zonal_fun = "mean", zonal_csv = glue("{dir_out}/{nms}/{yr}.csv"), 
    dir_nc = glue("{dir_out}/{nms}/{yr}_nc"), keep_nc = F, n_max_vals_per_req = 1e+05, 
    time_min = time_min, time_max = time_max, verbose = T)
debug: while (i_req <= n_reqs) {
    i_t_beg <- (i_req - 1) * n_t_per_req + 1
    i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
    t_req <- times_todo[c(i_t_beg, i_t_end)]
    t_req_str <- format_ISO8601(t_req, usetz = "Z")
    if (verbose) 
        message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
    ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
        ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
        0), nc)
    unlink(ncs0)
    nc_retry <- T
    nc_n_try <- 1
    n_max_retries
    while (nc_retry) {
        res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
            url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
                bbox[["xmax"]]), latitude = c(bbox[["ymin"]], 
                bbox[["ymax"]]), time = t_req_str, fmt = "nc", 
            store = rerddap::disk(path = dir_nc)))
        if (inherits(res, "try-error")) {
            err <- attr(res, "condition")
            msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
            nc_n_try <- nc_n_try + 1
            if (nc_n_try > n_max_retries) {
                stop(msg)
            }
            else {
                message(msg, "\nRETRYing...")
                Sys.sleep(1)
            }
        }
        else {
            nc_retry <- F
        }
    }
    i_req <- i_req + 1
}
debug: i_t_beg <- (i_req - 1) * n_t_per_req + 1
debug: i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
debug: t_req <- times_todo[c(i_t_beg, i_t_end)]
debug: t_req_str <- format_ISO8601(t_req, usetz = "Z")
debug: if (verbose) message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
debug: message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
Fetching request 1 of 1 (2020-01-01 to 2020-12-01) ~ 19:31:48 UTC
debug: ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
    0), nc)
debug: unlink(ncs0)
debug: nc_retry <- T
debug: nc_n_try <- 1
debug: n_max_retries
debug: while (nc_retry) {
    res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
        url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
            bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
        time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
    if (inherits(res, "try-error")) {
        err <- attr(res, "condition")
        msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
        nc_n_try <- nc_n_try + 1
        if (nc_n_try > n_max_retries) {
            stop(msg)
        }
        else {
            message(msg, "\nRETRYing...")
            Sys.sleep(1)
        }
    }
    else {
        nc_retry <- F
    }
}
debug: res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
    url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
        bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
    time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
debug: if (inherits(res, "try-error")) {
    err <- attr(res, "condition")
    msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
    nc_n_try <- nc_n_try + 1
    if (nc_n_try > n_max_retries) {
        stop(msg)
    }
    else {
        message(msg, "\nRETRYing...")
        Sys.sleep(1)
    }
} else {
    nc_retry <- F
}
debug: nc_retry <- F
debug: (while) nc_retry
debug: i_req <- i_req + 1
debug: (while) i_req <= n_reqs
debug: ncs <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size > 
    0), nc)
debug: r <- terra::rast(ncs)
debug: stopifnot(all(class(terra::time(r)) %in% c("POSIXct", "POSIXt")))
debug: idx <- dplyr::pull(dplyr::filter(dplyr::arrange(dplyr::tibble(idx = 1:terra::nlyr(r), 
    time = terra::time(r)), time), !duplicated(time)), idx)
debug: r <- terra::subset(r, idx)
debug: stopifnot(terra::crs(r, proj = T) == wgs84)
debug: if (mask_tif) r <- terra::mask(r, sf_zones)
debug: lyrs <- glue("{var}|{terra::time(r)}")
debug: if (length(dims_other) > 0 && !all(length(dims[dims_other]) == 
    1)) stop(glue("Other dimensions not yet supported: {paste(dims_other, collapse = ',')}"))
debug: names(r) <- lyrs
debug: if (!is.null(rast_tif)) {
    if (fs::file_exists(rast_tif)) {
        r_tmp_tif <- tempfile(fileext = ".tif")
        r_tmp <- c(rast(rast_tif), r)
        r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
        terra::writeRaster(r_tmp, r_tmp_tif)
        fs::file_delete(rast_tif)
        fs::file_move(r_tmp_tif, rast_tif)
        rm(r)
        rm(r_tmp)
    }
    else {
        terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
    }
    r <- terra::rast(rast_tif)
}
debug: if (fs::file_exists(rast_tif)) {
    r_tmp_tif <- tempfile(fileext = ".tif")
    r_tmp <- c(rast(rast_tif), r)
    r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
    terra::writeRaster(r_tmp, r_tmp_tif)
    fs::file_delete(rast_tif)
    fs::file_move(r_tmp_tif, rast_tif)
    rm(r)
    rm(r_tmp)
} else {
    terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
}
debug: terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
debug: r <- terra::rast(rast_tif)
debug: d_r <- mutate(tidyr::pivot_longer(sf::st_drop_geometry(sf::st_as_sf(terra::zonal(x = r, 
    z = terra::vect(dplyr::select(sf_zones, dplyr::all_of(fld_zones))), 
    fun = zonal_fun, exact = T, na.rm = T, as.polygons = T))), 
    cols = -dplyr::any_of(fld_zones), names_to = "lyr", values_to = zonal_fun), 
    time = readr::parse_datetime(str_replace(lyr, glue("{var}\\|(.*)"), 
        "\\1")))
debug: if (!is.null(zonal_csv)) write_csv(d_r, zonal_csv)
debug: write_csv(d_r, zonal_csv)
debug: if (!keep_nc) unlink(dir_nc, recursive = T)
debug: unlink(dir_nc, recursive = T)
debug: return(d_r)
Downloading 1 requests, up to 490 time slices each
Called from: extractr::ed_extract(ed, var = v, sf_zones = ply, bbox = bb, 
    mask_tif = F, rast_tif = glue("{dir_out}/{nms}/{yr}.tif"), 
    zonal_fun = "mean", zonal_csv = glue("{dir_out}/{nms}/{yr}.csv"), 
    dir_nc = glue("{dir_out}/{nms}/{yr}_nc"), keep_nc = F, n_max_vals_per_req = 1e+05, 
    time_min = time_min, time_max = time_max, verbose = T)
debug: while (i_req <= n_reqs) {
    i_t_beg <- (i_req - 1) * n_t_per_req + 1
    i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
    t_req <- times_todo[c(i_t_beg, i_t_end)]
    t_req_str <- format_ISO8601(t_req, usetz = "Z")
    if (verbose) 
        message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
    ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
        ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
        0), nc)
    unlink(ncs0)
    nc_retry <- T
    nc_n_try <- 1
    n_max_retries
    while (nc_retry) {
        res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
            url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
                bbox[["xmax"]]), latitude = c(bbox[["ymin"]], 
                bbox[["ymax"]]), time = t_req_str, fmt = "nc", 
            store = rerddap::disk(path = dir_nc)))
        if (inherits(res, "try-error")) {
            err <- attr(res, "condition")
            msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
            nc_n_try <- nc_n_try + 1
            if (nc_n_try > n_max_retries) {
                stop(msg)
            }
            else {
                message(msg, "\nRETRYing...")
                Sys.sleep(1)
            }
        }
        else {
            nc_retry <- F
        }
    }
    i_req <- i_req + 1
}
debug: i_t_beg <- (i_req - 1) * n_t_per_req + 1
debug: i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
debug: t_req <- times_todo[c(i_t_beg, i_t_end)]
debug: t_req_str <- format_ISO8601(t_req, usetz = "Z")
debug: if (verbose) message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
debug: message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
Fetching request 1 of 1 (2021-01-01 to 2021-12-01) ~ 19:31:50 UTC
debug: ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
    0), nc)
debug: unlink(ncs0)
debug: nc_retry <- T
debug: nc_n_try <- 1
debug: n_max_retries
debug: while (nc_retry) {
    res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
        url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
            bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
        time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
    if (inherits(res, "try-error")) {
        err <- attr(res, "condition")
        msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
        nc_n_try <- nc_n_try + 1
        if (nc_n_try > n_max_retries) {
            stop(msg)
        }
        else {
            message(msg, "\nRETRYing...")
            Sys.sleep(1)
        }
    }
    else {
        nc_retry <- F
    }
}
debug: res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
    url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
        bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
    time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
debug: if (inherits(res, "try-error")) {
    err <- attr(res, "condition")
    msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
    nc_n_try <- nc_n_try + 1
    if (nc_n_try > n_max_retries) {
        stop(msg)
    }
    else {
        message(msg, "\nRETRYing...")
        Sys.sleep(1)
    }
} else {
    nc_retry <- F
}
debug: nc_retry <- F
debug: (while) nc_retry
debug: i_req <- i_req + 1
debug: (while) i_req <= n_reqs
debug: ncs <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size > 
    0), nc)
debug: r <- terra::rast(ncs)
debug: stopifnot(all(class(terra::time(r)) %in% c("POSIXct", "POSIXt")))
debug: idx <- dplyr::pull(dplyr::filter(dplyr::arrange(dplyr::tibble(idx = 1:terra::nlyr(r), 
    time = terra::time(r)), time), !duplicated(time)), idx)
debug: r <- terra::subset(r, idx)
debug: stopifnot(terra::crs(r, proj = T) == wgs84)
debug: if (mask_tif) r <- terra::mask(r, sf_zones)
debug: lyrs <- glue("{var}|{terra::time(r)}")
debug: if (length(dims_other) > 0 && !all(length(dims[dims_other]) == 
    1)) stop(glue("Other dimensions not yet supported: {paste(dims_other, collapse = ',')}"))
debug: names(r) <- lyrs
debug: if (!is.null(rast_tif)) {
    if (fs::file_exists(rast_tif)) {
        r_tmp_tif <- tempfile(fileext = ".tif")
        r_tmp <- c(rast(rast_tif), r)
        r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
        terra::writeRaster(r_tmp, r_tmp_tif)
        fs::file_delete(rast_tif)
        fs::file_move(r_tmp_tif, rast_tif)
        rm(r)
        rm(r_tmp)
    }
    else {
        terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
    }
    r <- terra::rast(rast_tif)
}
debug: if (fs::file_exists(rast_tif)) {
    r_tmp_tif <- tempfile(fileext = ".tif")
    r_tmp <- c(rast(rast_tif), r)
    r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
    terra::writeRaster(r_tmp, r_tmp_tif)
    fs::file_delete(rast_tif)
    fs::file_move(r_tmp_tif, rast_tif)
    rm(r)
    rm(r_tmp)
} else {
    terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
}
debug: terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
debug: r <- terra::rast(rast_tif)
debug: d_r <- mutate(tidyr::pivot_longer(sf::st_drop_geometry(sf::st_as_sf(terra::zonal(x = r, 
    z = terra::vect(dplyr::select(sf_zones, dplyr::all_of(fld_zones))), 
    fun = zonal_fun, exact = T, na.rm = T, as.polygons = T))), 
    cols = -dplyr::any_of(fld_zones), names_to = "lyr", values_to = zonal_fun), 
    time = readr::parse_datetime(str_replace(lyr, glue("{var}\\|(.*)"), 
        "\\1")))
debug: if (!is.null(zonal_csv)) write_csv(d_r, zonal_csv)
debug: write_csv(d_r, zonal_csv)
debug: if (!keep_nc) unlink(dir_nc, recursive = T)
debug: unlink(dir_nc, recursive = T)
debug: return(d_r)
Downloading 1 requests, up to 490 time slices each
Called from: extractr::ed_extract(ed, var = v, sf_zones = ply, bbox = bb, 
    mask_tif = F, rast_tif = glue("{dir_out}/{nms}/{yr}.tif"), 
    zonal_fun = "mean", zonal_csv = glue("{dir_out}/{nms}/{yr}.csv"), 
    dir_nc = glue("{dir_out}/{nms}/{yr}_nc"), keep_nc = F, n_max_vals_per_req = 1e+05, 
    time_min = time_min, time_max = time_max, verbose = T)
debug: while (i_req <= n_reqs) {
    i_t_beg <- (i_req - 1) * n_t_per_req + 1
    i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
    t_req <- times_todo[c(i_t_beg, i_t_end)]
    t_req_str <- format_ISO8601(t_req, usetz = "Z")
    if (verbose) 
        message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
    ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
        ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
        0), nc)
    unlink(ncs0)
    nc_retry <- T
    nc_n_try <- 1
    n_max_retries
    while (nc_retry) {
        res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
            url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
                bbox[["xmax"]]), latitude = c(bbox[["ymin"]], 
                bbox[["ymax"]]), time = t_req_str, fmt = "nc", 
            store = rerddap::disk(path = dir_nc)))
        if (inherits(res, "try-error")) {
            err <- attr(res, "condition")
            msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
            nc_n_try <- nc_n_try + 1
            if (nc_n_try > n_max_retries) {
                stop(msg)
            }
            else {
                message(msg, "\nRETRYing...")
                Sys.sleep(1)
            }
        }
        else {
            nc_retry <- F
        }
    }
    i_req <- i_req + 1
}
debug: i_t_beg <- (i_req - 1) * n_t_per_req + 1
debug: i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
debug: t_req <- times_todo[c(i_t_beg, i_t_end)]
debug: t_req_str <- format_ISO8601(t_req, usetz = "Z")
debug: if (verbose) message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
debug: message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
Fetching request 1 of 1 (2022-01-01 to 2022-12-01) ~ 19:31:52 UTC
debug: ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
    0), nc)
debug: unlink(ncs0)
debug: nc_retry <- T
debug: nc_n_try <- 1
debug: n_max_retries
debug: while (nc_retry) {
    res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
        url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
            bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
        time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
    if (inherits(res, "try-error")) {
        err <- attr(res, "condition")
        msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
        nc_n_try <- nc_n_try + 1
        if (nc_n_try > n_max_retries) {
            stop(msg)
        }
        else {
            message(msg, "\nRETRYing...")
            Sys.sleep(1)
        }
    }
    else {
        nc_retry <- F
    }
}
debug: res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
    url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
        bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
    time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
debug: if (inherits(res, "try-error")) {
    err <- attr(res, "condition")
    msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
    nc_n_try <- nc_n_try + 1
    if (nc_n_try > n_max_retries) {
        stop(msg)
    }
    else {
        message(msg, "\nRETRYing...")
        Sys.sleep(1)
    }
} else {
    nc_retry <- F
}
debug: nc_retry <- F
debug: (while) nc_retry
debug: i_req <- i_req + 1
debug: (while) i_req <= n_reqs
debug: ncs <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size > 
    0), nc)
debug: r <- terra::rast(ncs)
debug: stopifnot(all(class(terra::time(r)) %in% c("POSIXct", "POSIXt")))
debug: idx <- dplyr::pull(dplyr::filter(dplyr::arrange(dplyr::tibble(idx = 1:terra::nlyr(r), 
    time = terra::time(r)), time), !duplicated(time)), idx)
debug: r <- terra::subset(r, idx)
debug: stopifnot(terra::crs(r, proj = T) == wgs84)
debug: if (mask_tif) r <- terra::mask(r, sf_zones)
debug: lyrs <- glue("{var}|{terra::time(r)}")
debug: if (length(dims_other) > 0 && !all(length(dims[dims_other]) == 
    1)) stop(glue("Other dimensions not yet supported: {paste(dims_other, collapse = ',')}"))
debug: names(r) <- lyrs
debug: if (!is.null(rast_tif)) {
    if (fs::file_exists(rast_tif)) {
        r_tmp_tif <- tempfile(fileext = ".tif")
        r_tmp <- c(rast(rast_tif), r)
        r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
        terra::writeRaster(r_tmp, r_tmp_tif)
        fs::file_delete(rast_tif)
        fs::file_move(r_tmp_tif, rast_tif)
        rm(r)
        rm(r_tmp)
    }
    else {
        terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
    }
    r <- terra::rast(rast_tif)
}
debug: if (fs::file_exists(rast_tif)) {
    r_tmp_tif <- tempfile(fileext = ".tif")
    r_tmp <- c(rast(rast_tif), r)
    r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
    terra::writeRaster(r_tmp, r_tmp_tif)
    fs::file_delete(rast_tif)
    fs::file_move(r_tmp_tif, rast_tif)
    rm(r)
    rm(r_tmp)
} else {
    terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
}
debug: terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
debug: r <- terra::rast(rast_tif)
debug: d_r <- mutate(tidyr::pivot_longer(sf::st_drop_geometry(sf::st_as_sf(terra::zonal(x = r, 
    z = terra::vect(dplyr::select(sf_zones, dplyr::all_of(fld_zones))), 
    fun = zonal_fun, exact = T, na.rm = T, as.polygons = T))), 
    cols = -dplyr::any_of(fld_zones), names_to = "lyr", values_to = zonal_fun), 
    time = readr::parse_datetime(str_replace(lyr, glue("{var}\\|(.*)"), 
        "\\1")))
debug: if (!is.null(zonal_csv)) write_csv(d_r, zonal_csv)
debug: write_csv(d_r, zonal_csv)
debug: if (!keep_nc) unlink(dir_nc, recursive = T)
debug: unlink(dir_nc, recursive = T)
debug: return(d_r)
Downloading 1 requests, up to 490 time slices each
Called from: extractr::ed_extract(ed, var = v, sf_zones = ply, bbox = bb, 
    mask_tif = F, rast_tif = glue("{dir_out}/{nms}/{yr}.tif"), 
    zonal_fun = "mean", zonal_csv = glue("{dir_out}/{nms}/{yr}.csv"), 
    dir_nc = glue("{dir_out}/{nms}/{yr}_nc"), keep_nc = F, n_max_vals_per_req = 1e+05, 
    time_min = time_min, time_max = time_max, verbose = T)
debug: while (i_req <= n_reqs) {
    i_t_beg <- (i_req - 1) * n_t_per_req + 1
    i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
    t_req <- times_todo[c(i_t_beg, i_t_end)]
    t_req_str <- format_ISO8601(t_req, usetz = "Z")
    if (verbose) 
        message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
    ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
        ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
        0), nc)
    unlink(ncs0)
    nc_retry <- T
    nc_n_try <- 1
    n_max_retries
    while (nc_retry) {
        res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
            url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
                bbox[["xmax"]]), latitude = c(bbox[["ymin"]], 
                bbox[["ymax"]]), time = t_req_str, fmt = "nc", 
            store = rerddap::disk(path = dir_nc)))
        if (inherits(res, "try-error")) {
            err <- attr(res, "condition")
            msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
            nc_n_try <- nc_n_try + 1
            if (nc_n_try > n_max_retries) {
                stop(msg)
            }
            else {
                message(msg, "\nRETRYing...")
                Sys.sleep(1)
            }
        }
        else {
            nc_retry <- F
        }
    }
    i_req <- i_req + 1
}
debug: i_t_beg <- (i_req - 1) * n_t_per_req + 1
debug: i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
debug: t_req <- times_todo[c(i_t_beg, i_t_end)]
debug: t_req_str <- format_ISO8601(t_req, usetz = "Z")
debug: if (verbose) message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
debug: message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
Fetching request 1 of 1 (2023-01-01 to 2023-12-01) ~ 19:31:54 UTC
debug: ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
    0), nc)
debug: unlink(ncs0)
debug: nc_retry <- T
debug: nc_n_try <- 1
debug: n_max_retries
debug: while (nc_retry) {
    res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
        url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
            bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
        time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
    if (inherits(res, "try-error")) {
        err <- attr(res, "condition")
        msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
        nc_n_try <- nc_n_try + 1
        if (nc_n_try > n_max_retries) {
            stop(msg)
        }
        else {
            message(msg, "\nRETRYing...")
            Sys.sleep(1)
        }
    }
    else {
        nc_retry <- F
    }
}
debug: res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
    url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
        bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
    time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
debug: if (inherits(res, "try-error")) {
    err <- attr(res, "condition")
    msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
    nc_n_try <- nc_n_try + 1
    if (nc_n_try > n_max_retries) {
        stop(msg)
    }
    else {
        message(msg, "\nRETRYing...")
        Sys.sleep(1)
    }
} else {
    nc_retry <- F
}
debug: nc_retry <- F
debug: (while) nc_retry
debug: i_req <- i_req + 1
debug: (while) i_req <= n_reqs
debug: ncs <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size > 
    0), nc)
debug: r <- terra::rast(ncs)
debug: stopifnot(all(class(terra::time(r)) %in% c("POSIXct", "POSIXt")))
debug: idx <- dplyr::pull(dplyr::filter(dplyr::arrange(dplyr::tibble(idx = 1:terra::nlyr(r), 
    time = terra::time(r)), time), !duplicated(time)), idx)
debug: r <- terra::subset(r, idx)
debug: stopifnot(terra::crs(r, proj = T) == wgs84)
debug: if (mask_tif) r <- terra::mask(r, sf_zones)
debug: lyrs <- glue("{var}|{terra::time(r)}")
debug: if (length(dims_other) > 0 && !all(length(dims[dims_other]) == 
    1)) stop(glue("Other dimensions not yet supported: {paste(dims_other, collapse = ',')}"))
debug: names(r) <- lyrs
debug: if (!is.null(rast_tif)) {
    if (fs::file_exists(rast_tif)) {
        r_tmp_tif <- tempfile(fileext = ".tif")
        r_tmp <- c(rast(rast_tif), r)
        r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
        terra::writeRaster(r_tmp, r_tmp_tif)
        fs::file_delete(rast_tif)
        fs::file_move(r_tmp_tif, rast_tif)
        rm(r)
        rm(r_tmp)
    }
    else {
        terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
    }
    r <- terra::rast(rast_tif)
}
debug: if (fs::file_exists(rast_tif)) {
    r_tmp_tif <- tempfile(fileext = ".tif")
    r_tmp <- c(rast(rast_tif), r)
    r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
    terra::writeRaster(r_tmp, r_tmp_tif)
    fs::file_delete(rast_tif)
    fs::file_move(r_tmp_tif, rast_tif)
    rm(r)
    rm(r_tmp)
} else {
    terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
}
debug: terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
debug: r <- terra::rast(rast_tif)
debug: d_r <- mutate(tidyr::pivot_longer(sf::st_drop_geometry(sf::st_as_sf(terra::zonal(x = r, 
    z = terra::vect(dplyr::select(sf_zones, dplyr::all_of(fld_zones))), 
    fun = zonal_fun, exact = T, na.rm = T, as.polygons = T))), 
    cols = -dplyr::any_of(fld_zones), names_to = "lyr", values_to = zonal_fun), 
    time = readr::parse_datetime(str_replace(lyr, glue("{var}\\|(.*)"), 
        "\\1")))
debug: if (!is.null(zonal_csv)) write_csv(d_r, zonal_csv)
debug: write_csv(d_r, zonal_csv)
debug: if (!keep_nc) unlink(dir_nc, recursive = T)
debug: unlink(dir_nc, recursive = T)
debug: return(d_r)
Downloading 1 requests, up to 490 time slices each
Called from: extractr::ed_extract(ed, var = v, sf_zones = ply, bbox = bb, 
    mask_tif = F, rast_tif = glue("{dir_out}/{nms}/{yr}.tif"), 
    zonal_fun = "mean", zonal_csv = glue("{dir_out}/{nms}/{yr}.csv"), 
    dir_nc = glue("{dir_out}/{nms}/{yr}_nc"), keep_nc = F, n_max_vals_per_req = 1e+05, 
    time_min = time_min, time_max = time_max, verbose = T)
debug: while (i_req <= n_reqs) {
    i_t_beg <- (i_req - 1) * n_t_per_req + 1
    i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
    t_req <- times_todo[c(i_t_beg, i_t_end)]
    t_req_str <- format_ISO8601(t_req, usetz = "Z")
    if (verbose) 
        message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
    ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
        ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
        0), nc)
    unlink(ncs0)
    nc_retry <- T
    nc_n_try <- 1
    n_max_retries
    while (nc_retry) {
        res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
            url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
                bbox[["xmax"]]), latitude = c(bbox[["ymin"]], 
                bbox[["ymax"]]), time = t_req_str, fmt = "nc", 
            store = rerddap::disk(path = dir_nc)))
        if (inherits(res, "try-error")) {
            err <- attr(res, "condition")
            msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
            nc_n_try <- nc_n_try + 1
            if (nc_n_try > n_max_retries) {
                stop(msg)
            }
            else {
                message(msg, "\nRETRYing...")
                Sys.sleep(1)
            }
        }
        else {
            nc_retry <- F
        }
    }
    i_req <- i_req + 1
}
debug: i_t_beg <- (i_req - 1) * n_t_per_req + 1
debug: i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
debug: t_req <- times_todo[c(i_t_beg, i_t_end)]
debug: t_req_str <- format_ISO8601(t_req, usetz = "Z")
debug: if (verbose) message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
debug: message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
Fetching request 1 of 1 (2024-01-01 to 2024-12-01) ~ 19:31:55 UTC
debug: ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
    0), nc)
debug: unlink(ncs0)
debug: nc_retry <- T
debug: nc_n_try <- 1
debug: n_max_retries
debug: while (nc_retry) {
    res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
        url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
            bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
        time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
    if (inherits(res, "try-error")) {
        err <- attr(res, "condition")
        msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
        nc_n_try <- nc_n_try + 1
        if (nc_n_try > n_max_retries) {
            stop(msg)
        }
        else {
            message(msg, "\nRETRYing...")
            Sys.sleep(1)
        }
    }
    else {
        nc_retry <- F
    }
}
debug: res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
    url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
        bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
    time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
debug: if (inherits(res, "try-error")) {
    err <- attr(res, "condition")
    msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
    nc_n_try <- nc_n_try + 1
    if (nc_n_try > n_max_retries) {
        stop(msg)
    }
    else {
        message(msg, "\nRETRYing...")
        Sys.sleep(1)
    }
} else {
    nc_retry <- F
}
debug: nc_retry <- F
debug: (while) nc_retry
debug: i_req <- i_req + 1
debug: (while) i_req <= n_reqs
debug: ncs <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size > 
    0), nc)
debug: r <- terra::rast(ncs)
debug: stopifnot(all(class(terra::time(r)) %in% c("POSIXct", "POSIXt")))
debug: idx <- dplyr::pull(dplyr::filter(dplyr::arrange(dplyr::tibble(idx = 1:terra::nlyr(r), 
    time = terra::time(r)), time), !duplicated(time)), idx)
debug: r <- terra::subset(r, idx)
debug: stopifnot(terra::crs(r, proj = T) == wgs84)
debug: if (mask_tif) r <- terra::mask(r, sf_zones)
debug: lyrs <- glue("{var}|{terra::time(r)}")
debug: if (length(dims_other) > 0 && !all(length(dims[dims_other]) == 
    1)) stop(glue("Other dimensions not yet supported: {paste(dims_other, collapse = ',')}"))
debug: names(r) <- lyrs
debug: if (!is.null(rast_tif)) {
    if (fs::file_exists(rast_tif)) {
        r_tmp_tif <- tempfile(fileext = ".tif")
        r_tmp <- c(rast(rast_tif), r)
        r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
        terra::writeRaster(r_tmp, r_tmp_tif)
        fs::file_delete(rast_tif)
        fs::file_move(r_tmp_tif, rast_tif)
        rm(r)
        rm(r_tmp)
    }
    else {
        terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
    }
    r <- terra::rast(rast_tif)
}
debug: if (fs::file_exists(rast_tif)) {
    r_tmp_tif <- tempfile(fileext = ".tif")
    r_tmp <- c(rast(rast_tif), r)
    r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
    terra::writeRaster(r_tmp, r_tmp_tif)
    fs::file_delete(rast_tif)
    fs::file_move(r_tmp_tif, rast_tif)
    rm(r)
    rm(r_tmp)
} else {
    terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
}
debug: terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
debug: r <- terra::rast(rast_tif)
debug: d_r <- mutate(tidyr::pivot_longer(sf::st_drop_geometry(sf::st_as_sf(terra::zonal(x = r, 
    z = terra::vect(dplyr::select(sf_zones, dplyr::all_of(fld_zones))), 
    fun = zonal_fun, exact = T, na.rm = T, as.polygons = T))), 
    cols = -dplyr::any_of(fld_zones), names_to = "lyr", values_to = zonal_fun), 
    time = readr::parse_datetime(str_replace(lyr, glue("{var}\\|(.*)"), 
        "\\1")))
debug: if (!is.null(zonal_csv)) write_csv(d_r, zonal_csv)
debug: write_csv(d_r, zonal_csv)
debug: if (!keep_nc) unlink(dir_nc, recursive = T)
debug: unlink(dir_nc, recursive = T)
debug: return(d_r)
Downloading 1 requests, up to 490 time slices each
Called from: extractr::ed_extract(ed, var = v, sf_zones = ply, bbox = bb, 
    mask_tif = F, rast_tif = glue("{dir_out}/{nms}/{yr}.tif"), 
    zonal_fun = "mean", zonal_csv = glue("{dir_out}/{nms}/{yr}.csv"), 
    dir_nc = glue("{dir_out}/{nms}/{yr}_nc"), keep_nc = F, n_max_vals_per_req = 1e+05, 
    time_min = time_min, time_max = time_max, verbose = T)
debug: while (i_req <= n_reqs) {
    i_t_beg <- (i_req - 1) * n_t_per_req + 1
    i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
    t_req <- times_todo[c(i_t_beg, i_t_end)]
    t_req_str <- format_ISO8601(t_req, usetz = "Z")
    if (verbose) 
        message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
    ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
        ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
        0), nc)
    unlink(ncs0)
    nc_retry <- T
    nc_n_try <- 1
    n_max_retries
    while (nc_retry) {
        res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
            url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
                bbox[["xmax"]]), latitude = c(bbox[["ymin"]], 
                bbox[["ymax"]]), time = t_req_str, fmt = "nc", 
            store = rerddap::disk(path = dir_nc)))
        if (inherits(res, "try-error")) {
            err <- attr(res, "condition")
            msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
            nc_n_try <- nc_n_try + 1
            if (nc_n_try > n_max_retries) {
                stop(msg)
            }
            else {
                message(msg, "\nRETRYing...")
                Sys.sleep(1)
            }
        }
        else {
            nc_retry <- F
        }
    }
    i_req <- i_req + 1
}
debug: i_t_beg <- (i_req - 1) * n_t_per_req + 1
debug: i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
debug: t_req <- times_todo[c(i_t_beg, i_t_end)]
debug: t_req_str <- format_ISO8601(t_req, usetz = "Z")
debug: if (verbose) message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
debug: message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
Fetching request 1 of 1 (2025-01-01 to 2025-07-01) ~ 19:31:57 UTC
debug: ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
    0), nc)
debug: unlink(ncs0)
debug: nc_retry <- T
debug: nc_n_try <- 1
debug: n_max_retries
debug: while (nc_retry) {
    res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
        url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
            bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
        time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
    if (inherits(res, "try-error")) {
        err <- attr(res, "condition")
        msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
        nc_n_try <- nc_n_try + 1
        if (nc_n_try > n_max_retries) {
            stop(msg)
        }
        else {
            message(msg, "\nRETRYing...")
            Sys.sleep(1)
        }
    }
    else {
        nc_retry <- F
    }
}
debug: res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
    url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
        bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
    time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
debug: if (inherits(res, "try-error")) {
    err <- attr(res, "condition")
    msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
    nc_n_try <- nc_n_try + 1
    if (nc_n_try > n_max_retries) {
        stop(msg)
    }
    else {
        message(msg, "\nRETRYing...")
        Sys.sleep(1)
    }
} else {
    nc_retry <- F
}
debug: nc_retry <- F
debug: (while) nc_retry
debug: i_req <- i_req + 1
debug: (while) i_req <= n_reqs
debug: ncs <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size > 
    0), nc)
debug: r <- terra::rast(ncs)
debug: stopifnot(all(class(terra::time(r)) %in% c("POSIXct", "POSIXt")))
debug: idx <- dplyr::pull(dplyr::filter(dplyr::arrange(dplyr::tibble(idx = 1:terra::nlyr(r), 
    time = terra::time(r)), time), !duplicated(time)), idx)
debug: r <- terra::subset(r, idx)
debug: stopifnot(terra::crs(r, proj = T) == wgs84)
debug: if (mask_tif) r <- terra::mask(r, sf_zones)
debug: lyrs <- glue("{var}|{terra::time(r)}")
debug: if (length(dims_other) > 0 && !all(length(dims[dims_other]) == 
    1)) stop(glue("Other dimensions not yet supported: {paste(dims_other, collapse = ',')}"))
debug: names(r) <- lyrs
debug: if (!is.null(rast_tif)) {
    if (fs::file_exists(rast_tif)) {
        r_tmp_tif <- tempfile(fileext = ".tif")
        r_tmp <- c(rast(rast_tif), r)
        r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
        terra::writeRaster(r_tmp, r_tmp_tif)
        fs::file_delete(rast_tif)
        fs::file_move(r_tmp_tif, rast_tif)
        rm(r)
        rm(r_tmp)
    }
    else {
        terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
    }
    r <- terra::rast(rast_tif)
}
debug: if (fs::file_exists(rast_tif)) {
    r_tmp_tif <- tempfile(fileext = ".tif")
    r_tmp <- c(rast(rast_tif), r)
    r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
    terra::writeRaster(r_tmp, r_tmp_tif)
    fs::file_delete(rast_tif)
    fs::file_move(r_tmp_tif, rast_tif)
    rm(r)
    rm(r_tmp)
} else {
    terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
}
debug: terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
debug: r <- terra::rast(rast_tif)
debug: d_r <- mutate(tidyr::pivot_longer(sf::st_drop_geometry(sf::st_as_sf(terra::zonal(x = r, 
    z = terra::vect(dplyr::select(sf_zones, dplyr::all_of(fld_zones))), 
    fun = zonal_fun, exact = T, na.rm = T, as.polygons = T))), 
    cols = -dplyr::any_of(fld_zones), names_to = "lyr", values_to = zonal_fun), 
    time = readr::parse_datetime(str_replace(lyr, glue("{var}\\|(.*)"), 
        "\\1")))
debug: if (!is.null(zonal_csv)) write_csv(d_r, zonal_csv)
debug: write_csv(d_r, zonal_csv)
debug: if (!keep_nc) unlink(dir_nc, recursive = T)
debug: unlink(dir_nc, recursive = T)
debug: return(d_r)
Downloading 1 requests, up to 240 time slices each
Called from: extractr::ed_extract(ed, var = v, sf_zones = ply, bbox = bb, 
    mask_tif = F, rast_tif = glue("{dir_out}/{nms}/{yr}.tif"), 
    zonal_fun = "mean", zonal_csv = glue("{dir_out}/{nms}/{yr}.csv"), 
    dir_nc = glue("{dir_out}/{nms}/{yr}_nc"), keep_nc = F, n_max_vals_per_req = 1e+05, 
    time_min = time_min, time_max = time_max, verbose = T)
debug: while (i_req <= n_reqs) {
    i_t_beg <- (i_req - 1) * n_t_per_req + 1
    i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
    t_req <- times_todo[c(i_t_beg, i_t_end)]
    t_req_str <- format_ISO8601(t_req, usetz = "Z")
    if (verbose) 
        message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
    ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
        ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
        0), nc)
    unlink(ncs0)
    nc_retry <- T
    nc_n_try <- 1
    n_max_retries
    while (nc_retry) {
        res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
            url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
                bbox[["xmax"]]), latitude = c(bbox[["ymin"]], 
                bbox[["ymax"]]), time = t_req_str, fmt = "nc", 
            store = rerddap::disk(path = dir_nc)))
        if (inherits(res, "try-error")) {
            err <- attr(res, "condition")
            msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
            nc_n_try <- nc_n_try + 1
            if (nc_n_try > n_max_retries) {
                stop(msg)
            }
            else {
                message(msg, "\nRETRYing...")
                Sys.sleep(1)
            }
        }
        else {
            nc_retry <- F
        }
    }
    i_req <- i_req + 1
}
debug: i_t_beg <- (i_req - 1) * n_t_per_req + 1
debug: i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
debug: t_req <- times_todo[c(i_t_beg, i_t_end)]
debug: t_req_str <- format_ISO8601(t_req, usetz = "Z")
debug: if (verbose) message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
debug: message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
Fetching request 1 of 1 (1998-01-01 to 1998-12-01) ~ 19:31:59 UTC
debug: ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
    0), nc)
debug: unlink(ncs0)
debug: nc_retry <- T
debug: nc_n_try <- 1
debug: n_max_retries
debug: while (nc_retry) {
    res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
        url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
            bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
        time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
    if (inherits(res, "try-error")) {
        err <- attr(res, "condition")
        msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
        nc_n_try <- nc_n_try + 1
        if (nc_n_try > n_max_retries) {
            stop(msg)
        }
        else {
            message(msg, "\nRETRYing...")
            Sys.sleep(1)
        }
    }
    else {
        nc_retry <- F
    }
}
debug: res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
    url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
        bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
    time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
debug: if (inherits(res, "try-error")) {
    err <- attr(res, "condition")
    msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
    nc_n_try <- nc_n_try + 1
    if (nc_n_try > n_max_retries) {
        stop(msg)
    }
    else {
        message(msg, "\nRETRYing...")
        Sys.sleep(1)
    }
} else {
    nc_retry <- F
}
debug: nc_retry <- F
debug: (while) nc_retry
debug: i_req <- i_req + 1
debug: (while) i_req <= n_reqs
debug: ncs <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size > 
    0), nc)
debug: r <- terra::rast(ncs)
debug: stopifnot(all(class(terra::time(r)) %in% c("POSIXct", "POSIXt")))
debug: idx <- dplyr::pull(dplyr::filter(dplyr::arrange(dplyr::tibble(idx = 1:terra::nlyr(r), 
    time = terra::time(r)), time), !duplicated(time)), idx)
debug: r <- terra::subset(r, idx)
debug: stopifnot(terra::crs(r, proj = T) == wgs84)
debug: if (mask_tif) r <- terra::mask(r, sf_zones)
debug: lyrs <- glue("{var}|{terra::time(r)}")
debug: if (length(dims_other) > 0 && !all(length(dims[dims_other]) == 
    1)) stop(glue("Other dimensions not yet supported: {paste(dims_other, collapse = ',')}"))
debug: names(r) <- lyrs
debug: if (!is.null(rast_tif)) {
    if (fs::file_exists(rast_tif)) {
        r_tmp_tif <- tempfile(fileext = ".tif")
        r_tmp <- c(rast(rast_tif), r)
        r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
        terra::writeRaster(r_tmp, r_tmp_tif)
        fs::file_delete(rast_tif)
        fs::file_move(r_tmp_tif, rast_tif)
        rm(r)
        rm(r_tmp)
    }
    else {
        terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
    }
    r <- terra::rast(rast_tif)
}
debug: if (fs::file_exists(rast_tif)) {
    r_tmp_tif <- tempfile(fileext = ".tif")
    r_tmp <- c(rast(rast_tif), r)
    r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
    terra::writeRaster(r_tmp, r_tmp_tif)
    fs::file_delete(rast_tif)
    fs::file_move(r_tmp_tif, rast_tif)
    rm(r)
    rm(r_tmp)
} else {
    terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
}
debug: terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
debug: r <- terra::rast(rast_tif)
debug: d_r <- mutate(tidyr::pivot_longer(sf::st_drop_geometry(sf::st_as_sf(terra::zonal(x = r, 
    z = terra::vect(dplyr::select(sf_zones, dplyr::all_of(fld_zones))), 
    fun = zonal_fun, exact = T, na.rm = T, as.polygons = T))), 
    cols = -dplyr::any_of(fld_zones), names_to = "lyr", values_to = zonal_fun), 
    time = readr::parse_datetime(str_replace(lyr, glue("{var}\\|(.*)"), 
        "\\1")))
debug: if (!is.null(zonal_csv)) write_csv(d_r, zonal_csv)
debug: write_csv(d_r, zonal_csv)
debug: if (!keep_nc) unlink(dir_nc, recursive = T)
debug: unlink(dir_nc, recursive = T)
debug: return(d_r)
Downloading 1 requests, up to 240 time slices each
Called from: extractr::ed_extract(ed, var = v, sf_zones = ply, bbox = bb, 
    mask_tif = F, rast_tif = glue("{dir_out}/{nms}/{yr}.tif"), 
    zonal_fun = "mean", zonal_csv = glue("{dir_out}/{nms}/{yr}.csv"), 
    dir_nc = glue("{dir_out}/{nms}/{yr}_nc"), keep_nc = F, n_max_vals_per_req = 1e+05, 
    time_min = time_min, time_max = time_max, verbose = T)
debug: while (i_req <= n_reqs) {
    i_t_beg <- (i_req - 1) * n_t_per_req + 1
    i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
    t_req <- times_todo[c(i_t_beg, i_t_end)]
    t_req_str <- format_ISO8601(t_req, usetz = "Z")
    if (verbose) 
        message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
    ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
        ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
        0), nc)
    unlink(ncs0)
    nc_retry <- T
    nc_n_try <- 1
    n_max_retries
    while (nc_retry) {
        res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
            url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
                bbox[["xmax"]]), latitude = c(bbox[["ymin"]], 
                bbox[["ymax"]]), time = t_req_str, fmt = "nc", 
            store = rerddap::disk(path = dir_nc)))
        if (inherits(res, "try-error")) {
            err <- attr(res, "condition")
            msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
            nc_n_try <- nc_n_try + 1
            if (nc_n_try > n_max_retries) {
                stop(msg)
            }
            else {
                message(msg, "\nRETRYing...")
                Sys.sleep(1)
            }
        }
        else {
            nc_retry <- F
        }
    }
    i_req <- i_req + 1
}
debug: i_t_beg <- (i_req - 1) * n_t_per_req + 1
debug: i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
debug: t_req <- times_todo[c(i_t_beg, i_t_end)]
debug: t_req_str <- format_ISO8601(t_req, usetz = "Z")
debug: if (verbose) message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
debug: message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
Fetching request 1 of 1 (1999-01-01 to 1999-12-01) ~ 19:32:02 UTC
debug: ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
    0), nc)
debug: unlink(ncs0)
debug: nc_retry <- T
debug: nc_n_try <- 1
debug: n_max_retries
debug: while (nc_retry) {
    res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
        url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
            bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
        time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
    if (inherits(res, "try-error")) {
        err <- attr(res, "condition")
        msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
        nc_n_try <- nc_n_try + 1
        if (nc_n_try > n_max_retries) {
            stop(msg)
        }
        else {
            message(msg, "\nRETRYing...")
            Sys.sleep(1)
        }
    }
    else {
        nc_retry <- F
    }
}
debug: res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
    url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
        bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
    time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
debug: if (inherits(res, "try-error")) {
    err <- attr(res, "condition")
    msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
    nc_n_try <- nc_n_try + 1
    if (nc_n_try > n_max_retries) {
        stop(msg)
    }
    else {
        message(msg, "\nRETRYing...")
        Sys.sleep(1)
    }
} else {
    nc_retry <- F
}
debug: nc_retry <- F
debug: (while) nc_retry
debug: i_req <- i_req + 1
debug: (while) i_req <= n_reqs
debug: ncs <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size > 
    0), nc)
debug: r <- terra::rast(ncs)
debug: stopifnot(all(class(terra::time(r)) %in% c("POSIXct", "POSIXt")))
debug: idx <- dplyr::pull(dplyr::filter(dplyr::arrange(dplyr::tibble(idx = 1:terra::nlyr(r), 
    time = terra::time(r)), time), !duplicated(time)), idx)
debug: r <- terra::subset(r, idx)
debug: stopifnot(terra::crs(r, proj = T) == wgs84)
debug: if (mask_tif) r <- terra::mask(r, sf_zones)
debug: lyrs <- glue("{var}|{terra::time(r)}")
debug: if (length(dims_other) > 0 && !all(length(dims[dims_other]) == 
    1)) stop(glue("Other dimensions not yet supported: {paste(dims_other, collapse = ',')}"))
debug: names(r) <- lyrs
debug: if (!is.null(rast_tif)) {
    if (fs::file_exists(rast_tif)) {
        r_tmp_tif <- tempfile(fileext = ".tif")
        r_tmp <- c(rast(rast_tif), r)
        r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
        terra::writeRaster(r_tmp, r_tmp_tif)
        fs::file_delete(rast_tif)
        fs::file_move(r_tmp_tif, rast_tif)
        rm(r)
        rm(r_tmp)
    }
    else {
        terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
    }
    r <- terra::rast(rast_tif)
}
debug: if (fs::file_exists(rast_tif)) {
    r_tmp_tif <- tempfile(fileext = ".tif")
    r_tmp <- c(rast(rast_tif), r)
    r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
    terra::writeRaster(r_tmp, r_tmp_tif)
    fs::file_delete(rast_tif)
    fs::file_move(r_tmp_tif, rast_tif)
    rm(r)
    rm(r_tmp)
} else {
    terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
}
debug: terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
debug: r <- terra::rast(rast_tif)
debug: d_r <- mutate(tidyr::pivot_longer(sf::st_drop_geometry(sf::st_as_sf(terra::zonal(x = r, 
    z = terra::vect(dplyr::select(sf_zones, dplyr::all_of(fld_zones))), 
    fun = zonal_fun, exact = T, na.rm = T, as.polygons = T))), 
    cols = -dplyr::any_of(fld_zones), names_to = "lyr", values_to = zonal_fun), 
    time = readr::parse_datetime(str_replace(lyr, glue("{var}\\|(.*)"), 
        "\\1")))
debug: if (!is.null(zonal_csv)) write_csv(d_r, zonal_csv)
debug: write_csv(d_r, zonal_csv)
debug: if (!keep_nc) unlink(dir_nc, recursive = T)
debug: unlink(dir_nc, recursive = T)
debug: return(d_r)
Downloading 1 requests, up to 240 time slices each
Called from: extractr::ed_extract(ed, var = v, sf_zones = ply, bbox = bb, 
    mask_tif = F, rast_tif = glue("{dir_out}/{nms}/{yr}.tif"), 
    zonal_fun = "mean", zonal_csv = glue("{dir_out}/{nms}/{yr}.csv"), 
    dir_nc = glue("{dir_out}/{nms}/{yr}_nc"), keep_nc = F, n_max_vals_per_req = 1e+05, 
    time_min = time_min, time_max = time_max, verbose = T)
debug: while (i_req <= n_reqs) {
    i_t_beg <- (i_req - 1) * n_t_per_req + 1
    i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
    t_req <- times_todo[c(i_t_beg, i_t_end)]
    t_req_str <- format_ISO8601(t_req, usetz = "Z")
    if (verbose) 
        message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
    ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
        ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
        0), nc)
    unlink(ncs0)
    nc_retry <- T
    nc_n_try <- 1
    n_max_retries
    while (nc_retry) {
        res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
            url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
                bbox[["xmax"]]), latitude = c(bbox[["ymin"]], 
                bbox[["ymax"]]), time = t_req_str, fmt = "nc", 
            store = rerddap::disk(path = dir_nc)))
        if (inherits(res, "try-error")) {
            err <- attr(res, "condition")
            msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
            nc_n_try <- nc_n_try + 1
            if (nc_n_try > n_max_retries) {
                stop(msg)
            }
            else {
                message(msg, "\nRETRYing...")
                Sys.sleep(1)
            }
        }
        else {
            nc_retry <- F
        }
    }
    i_req <- i_req + 1
}
debug: i_t_beg <- (i_req - 1) * n_t_per_req + 1
debug: i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
debug: t_req <- times_todo[c(i_t_beg, i_t_end)]
debug: t_req_str <- format_ISO8601(t_req, usetz = "Z")
debug: if (verbose) message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
debug: message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
Fetching request 1 of 1 (2000-01-01 to 2000-12-01) ~ 19:32:04 UTC
debug: ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
    0), nc)
debug: unlink(ncs0)
debug: nc_retry <- T
debug: nc_n_try <- 1
debug: n_max_retries
debug: while (nc_retry) {
    res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
        url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
            bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
        time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
    if (inherits(res, "try-error")) {
        err <- attr(res, "condition")
        msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
        nc_n_try <- nc_n_try + 1
        if (nc_n_try > n_max_retries) {
            stop(msg)
        }
        else {
            message(msg, "\nRETRYing...")
            Sys.sleep(1)
        }
    }
    else {
        nc_retry <- F
    }
}
debug: res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
    url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
        bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
    time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
debug: if (inherits(res, "try-error")) {
    err <- attr(res, "condition")
    msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
    nc_n_try <- nc_n_try + 1
    if (nc_n_try > n_max_retries) {
        stop(msg)
    }
    else {
        message(msg, "\nRETRYing...")
        Sys.sleep(1)
    }
} else {
    nc_retry <- F
}
debug: nc_retry <- F
debug: (while) nc_retry
debug: i_req <- i_req + 1
debug: (while) i_req <= n_reqs
debug: ncs <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size > 
    0), nc)
debug: r <- terra::rast(ncs)
debug: stopifnot(all(class(terra::time(r)) %in% c("POSIXct", "POSIXt")))
debug: idx <- dplyr::pull(dplyr::filter(dplyr::arrange(dplyr::tibble(idx = 1:terra::nlyr(r), 
    time = terra::time(r)), time), !duplicated(time)), idx)
debug: r <- terra::subset(r, idx)
debug: stopifnot(terra::crs(r, proj = T) == wgs84)
debug: if (mask_tif) r <- terra::mask(r, sf_zones)
debug: lyrs <- glue("{var}|{terra::time(r)}")
debug: if (length(dims_other) > 0 && !all(length(dims[dims_other]) == 
    1)) stop(glue("Other dimensions not yet supported: {paste(dims_other, collapse = ',')}"))
debug: names(r) <- lyrs
debug: if (!is.null(rast_tif)) {
    if (fs::file_exists(rast_tif)) {
        r_tmp_tif <- tempfile(fileext = ".tif")
        r_tmp <- c(rast(rast_tif), r)
        r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
        terra::writeRaster(r_tmp, r_tmp_tif)
        fs::file_delete(rast_tif)
        fs::file_move(r_tmp_tif, rast_tif)
        rm(r)
        rm(r_tmp)
    }
    else {
        terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
    }
    r <- terra::rast(rast_tif)
}
debug: if (fs::file_exists(rast_tif)) {
    r_tmp_tif <- tempfile(fileext = ".tif")
    r_tmp <- c(rast(rast_tif), r)
    r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
    terra::writeRaster(r_tmp, r_tmp_tif)
    fs::file_delete(rast_tif)
    fs::file_move(r_tmp_tif, rast_tif)
    rm(r)
    rm(r_tmp)
} else {
    terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
}
debug: terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
debug: r <- terra::rast(rast_tif)
debug: d_r <- mutate(tidyr::pivot_longer(sf::st_drop_geometry(sf::st_as_sf(terra::zonal(x = r, 
    z = terra::vect(dplyr::select(sf_zones, dplyr::all_of(fld_zones))), 
    fun = zonal_fun, exact = T, na.rm = T, as.polygons = T))), 
    cols = -dplyr::any_of(fld_zones), names_to = "lyr", values_to = zonal_fun), 
    time = readr::parse_datetime(str_replace(lyr, glue("{var}\\|(.*)"), 
        "\\1")))
debug: if (!is.null(zonal_csv)) write_csv(d_r, zonal_csv)
debug: write_csv(d_r, zonal_csv)
debug: if (!keep_nc) unlink(dir_nc, recursive = T)
debug: unlink(dir_nc, recursive = T)
debug: return(d_r)
Downloading 1 requests, up to 240 time slices each
Called from: extractr::ed_extract(ed, var = v, sf_zones = ply, bbox = bb, 
    mask_tif = F, rast_tif = glue("{dir_out}/{nms}/{yr}.tif"), 
    zonal_fun = "mean", zonal_csv = glue("{dir_out}/{nms}/{yr}.csv"), 
    dir_nc = glue("{dir_out}/{nms}/{yr}_nc"), keep_nc = F, n_max_vals_per_req = 1e+05, 
    time_min = time_min, time_max = time_max, verbose = T)
debug: while (i_req <= n_reqs) {
    i_t_beg <- (i_req - 1) * n_t_per_req + 1
    i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
    t_req <- times_todo[c(i_t_beg, i_t_end)]
    t_req_str <- format_ISO8601(t_req, usetz = "Z")
    if (verbose) 
        message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
    ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
        ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
        0), nc)
    unlink(ncs0)
    nc_retry <- T
    nc_n_try <- 1
    n_max_retries
    while (nc_retry) {
        res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
            url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
                bbox[["xmax"]]), latitude = c(bbox[["ymin"]], 
                bbox[["ymax"]]), time = t_req_str, fmt = "nc", 
            store = rerddap::disk(path = dir_nc)))
        if (inherits(res, "try-error")) {
            err <- attr(res, "condition")
            msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
            nc_n_try <- nc_n_try + 1
            if (nc_n_try > n_max_retries) {
                stop(msg)
            }
            else {
                message(msg, "\nRETRYing...")
                Sys.sleep(1)
            }
        }
        else {
            nc_retry <- F
        }
    }
    i_req <- i_req + 1
}
debug: i_t_beg <- (i_req - 1) * n_t_per_req + 1
debug: i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
debug: t_req <- times_todo[c(i_t_beg, i_t_end)]
debug: t_req_str <- format_ISO8601(t_req, usetz = "Z")
debug: if (verbose) message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
debug: message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
Fetching request 1 of 1 (2001-01-01 to 2001-12-01) ~ 19:32:06 UTC
debug: ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
    0), nc)
debug: unlink(ncs0)
debug: nc_retry <- T
debug: nc_n_try <- 1
debug: n_max_retries
debug: while (nc_retry) {
    res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
        url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
            bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
        time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
    if (inherits(res, "try-error")) {
        err <- attr(res, "condition")
        msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
        nc_n_try <- nc_n_try + 1
        if (nc_n_try > n_max_retries) {
            stop(msg)
        }
        else {
            message(msg, "\nRETRYing...")
            Sys.sleep(1)
        }
    }
    else {
        nc_retry <- F
    }
}
debug: res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
    url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
        bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
    time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
debug: if (inherits(res, "try-error")) {
    err <- attr(res, "condition")
    msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
    nc_n_try <- nc_n_try + 1
    if (nc_n_try > n_max_retries) {
        stop(msg)
    }
    else {
        message(msg, "\nRETRYing...")
        Sys.sleep(1)
    }
} else {
    nc_retry <- F
}
debug: nc_retry <- F
debug: (while) nc_retry
debug: i_req <- i_req + 1
debug: (while) i_req <= n_reqs
debug: ncs <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size > 
    0), nc)
debug: r <- terra::rast(ncs)
debug: stopifnot(all(class(terra::time(r)) %in% c("POSIXct", "POSIXt")))
debug: idx <- dplyr::pull(dplyr::filter(dplyr::arrange(dplyr::tibble(idx = 1:terra::nlyr(r), 
    time = terra::time(r)), time), !duplicated(time)), idx)
debug: r <- terra::subset(r, idx)
debug: stopifnot(terra::crs(r, proj = T) == wgs84)
debug: if (mask_tif) r <- terra::mask(r, sf_zones)
debug: lyrs <- glue("{var}|{terra::time(r)}")
debug: if (length(dims_other) > 0 && !all(length(dims[dims_other]) == 
    1)) stop(glue("Other dimensions not yet supported: {paste(dims_other, collapse = ',')}"))
debug: names(r) <- lyrs
debug: if (!is.null(rast_tif)) {
    if (fs::file_exists(rast_tif)) {
        r_tmp_tif <- tempfile(fileext = ".tif")
        r_tmp <- c(rast(rast_tif), r)
        r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
        terra::writeRaster(r_tmp, r_tmp_tif)
        fs::file_delete(rast_tif)
        fs::file_move(r_tmp_tif, rast_tif)
        rm(r)
        rm(r_tmp)
    }
    else {
        terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
    }
    r <- terra::rast(rast_tif)
}
debug: if (fs::file_exists(rast_tif)) {
    r_tmp_tif <- tempfile(fileext = ".tif")
    r_tmp <- c(rast(rast_tif), r)
    r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
    terra::writeRaster(r_tmp, r_tmp_tif)
    fs::file_delete(rast_tif)
    fs::file_move(r_tmp_tif, rast_tif)
    rm(r)
    rm(r_tmp)
} else {
    terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
}
debug: terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
debug: r <- terra::rast(rast_tif)
debug: d_r <- mutate(tidyr::pivot_longer(sf::st_drop_geometry(sf::st_as_sf(terra::zonal(x = r, 
    z = terra::vect(dplyr::select(sf_zones, dplyr::all_of(fld_zones))), 
    fun = zonal_fun, exact = T, na.rm = T, as.polygons = T))), 
    cols = -dplyr::any_of(fld_zones), names_to = "lyr", values_to = zonal_fun), 
    time = readr::parse_datetime(str_replace(lyr, glue("{var}\\|(.*)"), 
        "\\1")))
debug: if (!is.null(zonal_csv)) write_csv(d_r, zonal_csv)
debug: write_csv(d_r, zonal_csv)
debug: if (!keep_nc) unlink(dir_nc, recursive = T)
debug: unlink(dir_nc, recursive = T)
debug: return(d_r)
Downloading 1 requests, up to 240 time slices each
Called from: extractr::ed_extract(ed, var = v, sf_zones = ply, bbox = bb, 
    mask_tif = F, rast_tif = glue("{dir_out}/{nms}/{yr}.tif"), 
    zonal_fun = "mean", zonal_csv = glue("{dir_out}/{nms}/{yr}.csv"), 
    dir_nc = glue("{dir_out}/{nms}/{yr}_nc"), keep_nc = F, n_max_vals_per_req = 1e+05, 
    time_min = time_min, time_max = time_max, verbose = T)
debug: while (i_req <= n_reqs) {
    i_t_beg <- (i_req - 1) * n_t_per_req + 1
    i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
    t_req <- times_todo[c(i_t_beg, i_t_end)]
    t_req_str <- format_ISO8601(t_req, usetz = "Z")
    if (verbose) 
        message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
    ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
        ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
        0), nc)
    unlink(ncs0)
    nc_retry <- T
    nc_n_try <- 1
    n_max_retries
    while (nc_retry) {
        res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
            url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
                bbox[["xmax"]]), latitude = c(bbox[["ymin"]], 
                bbox[["ymax"]]), time = t_req_str, fmt = "nc", 
            store = rerddap::disk(path = dir_nc)))
        if (inherits(res, "try-error")) {
            err <- attr(res, "condition")
            msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
            nc_n_try <- nc_n_try + 1
            if (nc_n_try > n_max_retries) {
                stop(msg)
            }
            else {
                message(msg, "\nRETRYing...")
                Sys.sleep(1)
            }
        }
        else {
            nc_retry <- F
        }
    }
    i_req <- i_req + 1
}
debug: i_t_beg <- (i_req - 1) * n_t_per_req + 1
debug: i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
debug: t_req <- times_todo[c(i_t_beg, i_t_end)]
debug: t_req_str <- format_ISO8601(t_req, usetz = "Z")
debug: if (verbose) message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
debug: message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
Fetching request 1 of 1 (2002-01-01 to 2002-12-01) ~ 19:32:08 UTC
debug: ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
    0), nc)
debug: unlink(ncs0)
debug: nc_retry <- T
debug: nc_n_try <- 1
debug: n_max_retries
debug: while (nc_retry) {
    res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
        url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
            bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
        time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
    if (inherits(res, "try-error")) {
        err <- attr(res, "condition")
        msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
        nc_n_try <- nc_n_try + 1
        if (nc_n_try > n_max_retries) {
            stop(msg)
        }
        else {
            message(msg, "\nRETRYing...")
            Sys.sleep(1)
        }
    }
    else {
        nc_retry <- F
    }
}
debug: res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
    url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
        bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
    time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
debug: if (inherits(res, "try-error")) {
    err <- attr(res, "condition")
    msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
    nc_n_try <- nc_n_try + 1
    if (nc_n_try > n_max_retries) {
        stop(msg)
    }
    else {
        message(msg, "\nRETRYing...")
        Sys.sleep(1)
    }
} else {
    nc_retry <- F
}
debug: nc_retry <- F
debug: (while) nc_retry
debug: i_req <- i_req + 1
debug: (while) i_req <= n_reqs
debug: ncs <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size > 
    0), nc)
debug: r <- terra::rast(ncs)
debug: stopifnot(all(class(terra::time(r)) %in% c("POSIXct", "POSIXt")))
debug: idx <- dplyr::pull(dplyr::filter(dplyr::arrange(dplyr::tibble(idx = 1:terra::nlyr(r), 
    time = terra::time(r)), time), !duplicated(time)), idx)
debug: r <- terra::subset(r, idx)
debug: stopifnot(terra::crs(r, proj = T) == wgs84)
debug: if (mask_tif) r <- terra::mask(r, sf_zones)
debug: lyrs <- glue("{var}|{terra::time(r)}")
debug: if (length(dims_other) > 0 && !all(length(dims[dims_other]) == 
    1)) stop(glue("Other dimensions not yet supported: {paste(dims_other, collapse = ',')}"))
debug: names(r) <- lyrs
debug: if (!is.null(rast_tif)) {
    if (fs::file_exists(rast_tif)) {
        r_tmp_tif <- tempfile(fileext = ".tif")
        r_tmp <- c(rast(rast_tif), r)
        r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
        terra::writeRaster(r_tmp, r_tmp_tif)
        fs::file_delete(rast_tif)
        fs::file_move(r_tmp_tif, rast_tif)
        rm(r)
        rm(r_tmp)
    }
    else {
        terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
    }
    r <- terra::rast(rast_tif)
}
debug: if (fs::file_exists(rast_tif)) {
    r_tmp_tif <- tempfile(fileext = ".tif")
    r_tmp <- c(rast(rast_tif), r)
    r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
    terra::writeRaster(r_tmp, r_tmp_tif)
    fs::file_delete(rast_tif)
    fs::file_move(r_tmp_tif, rast_tif)
    rm(r)
    rm(r_tmp)
} else {
    terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
}
debug: terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
debug: r <- terra::rast(rast_tif)
debug: d_r <- mutate(tidyr::pivot_longer(sf::st_drop_geometry(sf::st_as_sf(terra::zonal(x = r, 
    z = terra::vect(dplyr::select(sf_zones, dplyr::all_of(fld_zones))), 
    fun = zonal_fun, exact = T, na.rm = T, as.polygons = T))), 
    cols = -dplyr::any_of(fld_zones), names_to = "lyr", values_to = zonal_fun), 
    time = readr::parse_datetime(str_replace(lyr, glue("{var}\\|(.*)"), 
        "\\1")))
debug: if (!is.null(zonal_csv)) write_csv(d_r, zonal_csv)
debug: write_csv(d_r, zonal_csv)
debug: if (!keep_nc) unlink(dir_nc, recursive = T)
debug: unlink(dir_nc, recursive = T)
debug: return(d_r)
Downloading 1 requests, up to 240 time slices each
Called from: extractr::ed_extract(ed, var = v, sf_zones = ply, bbox = bb, 
    mask_tif = F, rast_tif = glue("{dir_out}/{nms}/{yr}.tif"), 
    zonal_fun = "mean", zonal_csv = glue("{dir_out}/{nms}/{yr}.csv"), 
    dir_nc = glue("{dir_out}/{nms}/{yr}_nc"), keep_nc = F, n_max_vals_per_req = 1e+05, 
    time_min = time_min, time_max = time_max, verbose = T)
debug: while (i_req <= n_reqs) {
    i_t_beg <- (i_req - 1) * n_t_per_req + 1
    i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
    t_req <- times_todo[c(i_t_beg, i_t_end)]
    t_req_str <- format_ISO8601(t_req, usetz = "Z")
    if (verbose) 
        message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
    ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
        ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
        0), nc)
    unlink(ncs0)
    nc_retry <- T
    nc_n_try <- 1
    n_max_retries
    while (nc_retry) {
        res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
            url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
                bbox[["xmax"]]), latitude = c(bbox[["ymin"]], 
                bbox[["ymax"]]), time = t_req_str, fmt = "nc", 
            store = rerddap::disk(path = dir_nc)))
        if (inherits(res, "try-error")) {
            err <- attr(res, "condition")
            msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
            nc_n_try <- nc_n_try + 1
            if (nc_n_try > n_max_retries) {
                stop(msg)
            }
            else {
                message(msg, "\nRETRYing...")
                Sys.sleep(1)
            }
        }
        else {
            nc_retry <- F
        }
    }
    i_req <- i_req + 1
}
debug: i_t_beg <- (i_req - 1) * n_t_per_req + 1
debug: i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
debug: t_req <- times_todo[c(i_t_beg, i_t_end)]
debug: t_req_str <- format_ISO8601(t_req, usetz = "Z")
debug: if (verbose) message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
debug: message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
Fetching request 1 of 1 (2003-01-01 to 2003-12-01) ~ 19:32:10 UTC
debug: ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
    0), nc)
debug: unlink(ncs0)
debug: nc_retry <- T
debug: nc_n_try <- 1
debug: n_max_retries
debug: while (nc_retry) {
    res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
        url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
            bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
        time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
    if (inherits(res, "try-error")) {
        err <- attr(res, "condition")
        msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
        nc_n_try <- nc_n_try + 1
        if (nc_n_try > n_max_retries) {
            stop(msg)
        }
        else {
            message(msg, "\nRETRYing...")
            Sys.sleep(1)
        }
    }
    else {
        nc_retry <- F
    }
}
debug: res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
    url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
        bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
    time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
debug: if (inherits(res, "try-error")) {
    err <- attr(res, "condition")
    msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
    nc_n_try <- nc_n_try + 1
    if (nc_n_try > n_max_retries) {
        stop(msg)
    }
    else {
        message(msg, "\nRETRYing...")
        Sys.sleep(1)
    }
} else {
    nc_retry <- F
}
debug: nc_retry <- F
debug: (while) nc_retry
debug: i_req <- i_req + 1
debug: (while) i_req <= n_reqs
debug: ncs <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size > 
    0), nc)
debug: r <- terra::rast(ncs)
debug: stopifnot(all(class(terra::time(r)) %in% c("POSIXct", "POSIXt")))
debug: idx <- dplyr::pull(dplyr::filter(dplyr::arrange(dplyr::tibble(idx = 1:terra::nlyr(r), 
    time = terra::time(r)), time), !duplicated(time)), idx)
debug: r <- terra::subset(r, idx)
debug: stopifnot(terra::crs(r, proj = T) == wgs84)
debug: if (mask_tif) r <- terra::mask(r, sf_zones)
debug: lyrs <- glue("{var}|{terra::time(r)}")
debug: if (length(dims_other) > 0 && !all(length(dims[dims_other]) == 
    1)) stop(glue("Other dimensions not yet supported: {paste(dims_other, collapse = ',')}"))
debug: names(r) <- lyrs
debug: if (!is.null(rast_tif)) {
    if (fs::file_exists(rast_tif)) {
        r_tmp_tif <- tempfile(fileext = ".tif")
        r_tmp <- c(rast(rast_tif), r)
        r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
        terra::writeRaster(r_tmp, r_tmp_tif)
        fs::file_delete(rast_tif)
        fs::file_move(r_tmp_tif, rast_tif)
        rm(r)
        rm(r_tmp)
    }
    else {
        terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
    }
    r <- terra::rast(rast_tif)
}
debug: if (fs::file_exists(rast_tif)) {
    r_tmp_tif <- tempfile(fileext = ".tif")
    r_tmp <- c(rast(rast_tif), r)
    r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
    terra::writeRaster(r_tmp, r_tmp_tif)
    fs::file_delete(rast_tif)
    fs::file_move(r_tmp_tif, rast_tif)
    rm(r)
    rm(r_tmp)
} else {
    terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
}
debug: terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
debug: r <- terra::rast(rast_tif)
debug: d_r <- mutate(tidyr::pivot_longer(sf::st_drop_geometry(sf::st_as_sf(terra::zonal(x = r, 
    z = terra::vect(dplyr::select(sf_zones, dplyr::all_of(fld_zones))), 
    fun = zonal_fun, exact = T, na.rm = T, as.polygons = T))), 
    cols = -dplyr::any_of(fld_zones), names_to = "lyr", values_to = zonal_fun), 
    time = readr::parse_datetime(str_replace(lyr, glue("{var}\\|(.*)"), 
        "\\1")))
debug: if (!is.null(zonal_csv)) write_csv(d_r, zonal_csv)
debug: write_csv(d_r, zonal_csv)
debug: if (!keep_nc) unlink(dir_nc, recursive = T)
debug: unlink(dir_nc, recursive = T)
debug: return(d_r)
Downloading 1 requests, up to 240 time slices each
Called from: extractr::ed_extract(ed, var = v, sf_zones = ply, bbox = bb, 
    mask_tif = F, rast_tif = glue("{dir_out}/{nms}/{yr}.tif"), 
    zonal_fun = "mean", zonal_csv = glue("{dir_out}/{nms}/{yr}.csv"), 
    dir_nc = glue("{dir_out}/{nms}/{yr}_nc"), keep_nc = F, n_max_vals_per_req = 1e+05, 
    time_min = time_min, time_max = time_max, verbose = T)
debug: while (i_req <= n_reqs) {
    i_t_beg <- (i_req - 1) * n_t_per_req + 1
    i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
    t_req <- times_todo[c(i_t_beg, i_t_end)]
    t_req_str <- format_ISO8601(t_req, usetz = "Z")
    if (verbose) 
        message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
    ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
        ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
        0), nc)
    unlink(ncs0)
    nc_retry <- T
    nc_n_try <- 1
    n_max_retries
    while (nc_retry) {
        res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
            url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
                bbox[["xmax"]]), latitude = c(bbox[["ymin"]], 
                bbox[["ymax"]]), time = t_req_str, fmt = "nc", 
            store = rerddap::disk(path = dir_nc)))
        if (inherits(res, "try-error")) {
            err <- attr(res, "condition")
            msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
            nc_n_try <- nc_n_try + 1
            if (nc_n_try > n_max_retries) {
                stop(msg)
            }
            else {
                message(msg, "\nRETRYing...")
                Sys.sleep(1)
            }
        }
        else {
            nc_retry <- F
        }
    }
    i_req <- i_req + 1
}
debug: i_t_beg <- (i_req - 1) * n_t_per_req + 1
debug: i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
debug: t_req <- times_todo[c(i_t_beg, i_t_end)]
debug: t_req_str <- format_ISO8601(t_req, usetz = "Z")
debug: if (verbose) message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
debug: message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
Fetching request 1 of 1 (2004-01-01 to 2004-12-01) ~ 19:32:13 UTC
debug: ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
    0), nc)
debug: unlink(ncs0)
debug: nc_retry <- T
debug: nc_n_try <- 1
debug: n_max_retries
debug: while (nc_retry) {
    res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
        url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
            bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
        time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
    if (inherits(res, "try-error")) {
        err <- attr(res, "condition")
        msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
        nc_n_try <- nc_n_try + 1
        if (nc_n_try > n_max_retries) {
            stop(msg)
        }
        else {
            message(msg, "\nRETRYing...")
            Sys.sleep(1)
        }
    }
    else {
        nc_retry <- F
    }
}
debug: res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
    url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
        bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
    time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
debug: if (inherits(res, "try-error")) {
    err <- attr(res, "condition")
    msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
    nc_n_try <- nc_n_try + 1
    if (nc_n_try > n_max_retries) {
        stop(msg)
    }
    else {
        message(msg, "\nRETRYing...")
        Sys.sleep(1)
    }
} else {
    nc_retry <- F
}
debug: nc_retry <- F
debug: (while) nc_retry
debug: i_req <- i_req + 1
debug: (while) i_req <= n_reqs
debug: ncs <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size > 
    0), nc)
debug: r <- terra::rast(ncs)
debug: stopifnot(all(class(terra::time(r)) %in% c("POSIXct", "POSIXt")))
debug: idx <- dplyr::pull(dplyr::filter(dplyr::arrange(dplyr::tibble(idx = 1:terra::nlyr(r), 
    time = terra::time(r)), time), !duplicated(time)), idx)
debug: r <- terra::subset(r, idx)
debug: stopifnot(terra::crs(r, proj = T) == wgs84)
debug: if (mask_tif) r <- terra::mask(r, sf_zones)
debug: lyrs <- glue("{var}|{terra::time(r)}")
debug: if (length(dims_other) > 0 && !all(length(dims[dims_other]) == 
    1)) stop(glue("Other dimensions not yet supported: {paste(dims_other, collapse = ',')}"))
debug: names(r) <- lyrs
debug: if (!is.null(rast_tif)) {
    if (fs::file_exists(rast_tif)) {
        r_tmp_tif <- tempfile(fileext = ".tif")
        r_tmp <- c(rast(rast_tif), r)
        r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
        terra::writeRaster(r_tmp, r_tmp_tif)
        fs::file_delete(rast_tif)
        fs::file_move(r_tmp_tif, rast_tif)
        rm(r)
        rm(r_tmp)
    }
    else {
        terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
    }
    r <- terra::rast(rast_tif)
}
debug: if (fs::file_exists(rast_tif)) {
    r_tmp_tif <- tempfile(fileext = ".tif")
    r_tmp <- c(rast(rast_tif), r)
    r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
    terra::writeRaster(r_tmp, r_tmp_tif)
    fs::file_delete(rast_tif)
    fs::file_move(r_tmp_tif, rast_tif)
    rm(r)
    rm(r_tmp)
} else {
    terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
}
debug: terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
debug: r <- terra::rast(rast_tif)
debug: d_r <- mutate(tidyr::pivot_longer(sf::st_drop_geometry(sf::st_as_sf(terra::zonal(x = r, 
    z = terra::vect(dplyr::select(sf_zones, dplyr::all_of(fld_zones))), 
    fun = zonal_fun, exact = T, na.rm = T, as.polygons = T))), 
    cols = -dplyr::any_of(fld_zones), names_to = "lyr", values_to = zonal_fun), 
    time = readr::parse_datetime(str_replace(lyr, glue("{var}\\|(.*)"), 
        "\\1")))
debug: if (!is.null(zonal_csv)) write_csv(d_r, zonal_csv)
debug: write_csv(d_r, zonal_csv)
debug: if (!keep_nc) unlink(dir_nc, recursive = T)
debug: unlink(dir_nc, recursive = T)
debug: return(d_r)
Downloading 1 requests, up to 240 time slices each
Called from: extractr::ed_extract(ed, var = v, sf_zones = ply, bbox = bb, 
    mask_tif = F, rast_tif = glue("{dir_out}/{nms}/{yr}.tif"), 
    zonal_fun = "mean", zonal_csv = glue("{dir_out}/{nms}/{yr}.csv"), 
    dir_nc = glue("{dir_out}/{nms}/{yr}_nc"), keep_nc = F, n_max_vals_per_req = 1e+05, 
    time_min = time_min, time_max = time_max, verbose = T)
debug: while (i_req <= n_reqs) {
    i_t_beg <- (i_req - 1) * n_t_per_req + 1
    i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
    t_req <- times_todo[c(i_t_beg, i_t_end)]
    t_req_str <- format_ISO8601(t_req, usetz = "Z")
    if (verbose) 
        message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
    ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
        ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
        0), nc)
    unlink(ncs0)
    nc_retry <- T
    nc_n_try <- 1
    n_max_retries
    while (nc_retry) {
        res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
            url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
                bbox[["xmax"]]), latitude = c(bbox[["ymin"]], 
                bbox[["ymax"]]), time = t_req_str, fmt = "nc", 
            store = rerddap::disk(path = dir_nc)))
        if (inherits(res, "try-error")) {
            err <- attr(res, "condition")
            msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
            nc_n_try <- nc_n_try + 1
            if (nc_n_try > n_max_retries) {
                stop(msg)
            }
            else {
                message(msg, "\nRETRYing...")
                Sys.sleep(1)
            }
        }
        else {
            nc_retry <- F
        }
    }
    i_req <- i_req + 1
}
debug: i_t_beg <- (i_req - 1) * n_t_per_req + 1
debug: i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
debug: t_req <- times_todo[c(i_t_beg, i_t_end)]
debug: t_req_str <- format_ISO8601(t_req, usetz = "Z")
debug: if (verbose) message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
debug: message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
Fetching request 1 of 1 (2005-01-01 to 2005-12-01) ~ 19:32:14 UTC
debug: ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
    0), nc)
debug: unlink(ncs0)
debug: nc_retry <- T
debug: nc_n_try <- 1
debug: n_max_retries
debug: while (nc_retry) {
    res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
        url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
            bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
        time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
    if (inherits(res, "try-error")) {
        err <- attr(res, "condition")
        msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
        nc_n_try <- nc_n_try + 1
        if (nc_n_try > n_max_retries) {
            stop(msg)
        }
        else {
            message(msg, "\nRETRYing...")
            Sys.sleep(1)
        }
    }
    else {
        nc_retry <- F
    }
}
debug: res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
    url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
        bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
    time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
debug: if (inherits(res, "try-error")) {
    err <- attr(res, "condition")
    msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
    nc_n_try <- nc_n_try + 1
    if (nc_n_try > n_max_retries) {
        stop(msg)
    }
    else {
        message(msg, "\nRETRYing...")
        Sys.sleep(1)
    }
} else {
    nc_retry <- F
}
debug: nc_retry <- F
debug: (while) nc_retry
debug: i_req <- i_req + 1
debug: (while) i_req <= n_reqs
debug: ncs <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size > 
    0), nc)
debug: r <- terra::rast(ncs)
debug: stopifnot(all(class(terra::time(r)) %in% c("POSIXct", "POSIXt")))
debug: idx <- dplyr::pull(dplyr::filter(dplyr::arrange(dplyr::tibble(idx = 1:terra::nlyr(r), 
    time = terra::time(r)), time), !duplicated(time)), idx)
debug: r <- terra::subset(r, idx)
debug: stopifnot(terra::crs(r, proj = T) == wgs84)
debug: if (mask_tif) r <- terra::mask(r, sf_zones)
debug: lyrs <- glue("{var}|{terra::time(r)}")
debug: if (length(dims_other) > 0 && !all(length(dims[dims_other]) == 
    1)) stop(glue("Other dimensions not yet supported: {paste(dims_other, collapse = ',')}"))
debug: names(r) <- lyrs
debug: if (!is.null(rast_tif)) {
    if (fs::file_exists(rast_tif)) {
        r_tmp_tif <- tempfile(fileext = ".tif")
        r_tmp <- c(rast(rast_tif), r)
        r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
        terra::writeRaster(r_tmp, r_tmp_tif)
        fs::file_delete(rast_tif)
        fs::file_move(r_tmp_tif, rast_tif)
        rm(r)
        rm(r_tmp)
    }
    else {
        terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
    }
    r <- terra::rast(rast_tif)
}
debug: if (fs::file_exists(rast_tif)) {
    r_tmp_tif <- tempfile(fileext = ".tif")
    r_tmp <- c(rast(rast_tif), r)
    r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
    terra::writeRaster(r_tmp, r_tmp_tif)
    fs::file_delete(rast_tif)
    fs::file_move(r_tmp_tif, rast_tif)
    rm(r)
    rm(r_tmp)
} else {
    terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
}
debug: terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
debug: r <- terra::rast(rast_tif)
debug: d_r <- mutate(tidyr::pivot_longer(sf::st_drop_geometry(sf::st_as_sf(terra::zonal(x = r, 
    z = terra::vect(dplyr::select(sf_zones, dplyr::all_of(fld_zones))), 
    fun = zonal_fun, exact = T, na.rm = T, as.polygons = T))), 
    cols = -dplyr::any_of(fld_zones), names_to = "lyr", values_to = zonal_fun), 
    time = readr::parse_datetime(str_replace(lyr, glue("{var}\\|(.*)"), 
        "\\1")))
debug: if (!is.null(zonal_csv)) write_csv(d_r, zonal_csv)
debug: write_csv(d_r, zonal_csv)
debug: if (!keep_nc) unlink(dir_nc, recursive = T)
debug: unlink(dir_nc, recursive = T)
debug: return(d_r)
Downloading 1 requests, up to 240 time slices each
Called from: extractr::ed_extract(ed, var = v, sf_zones = ply, bbox = bb, 
    mask_tif = F, rast_tif = glue("{dir_out}/{nms}/{yr}.tif"), 
    zonal_fun = "mean", zonal_csv = glue("{dir_out}/{nms}/{yr}.csv"), 
    dir_nc = glue("{dir_out}/{nms}/{yr}_nc"), keep_nc = F, n_max_vals_per_req = 1e+05, 
    time_min = time_min, time_max = time_max, verbose = T)
debug: while (i_req <= n_reqs) {
    i_t_beg <- (i_req - 1) * n_t_per_req + 1
    i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
    t_req <- times_todo[c(i_t_beg, i_t_end)]
    t_req_str <- format_ISO8601(t_req, usetz = "Z")
    if (verbose) 
        message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
    ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
        ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
        0), nc)
    unlink(ncs0)
    nc_retry <- T
    nc_n_try <- 1
    n_max_retries
    while (nc_retry) {
        res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
            url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
                bbox[["xmax"]]), latitude = c(bbox[["ymin"]], 
                bbox[["ymax"]]), time = t_req_str, fmt = "nc", 
            store = rerddap::disk(path = dir_nc)))
        if (inherits(res, "try-error")) {
            err <- attr(res, "condition")
            msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
            nc_n_try <- nc_n_try + 1
            if (nc_n_try > n_max_retries) {
                stop(msg)
            }
            else {
                message(msg, "\nRETRYing...")
                Sys.sleep(1)
            }
        }
        else {
            nc_retry <- F
        }
    }
    i_req <- i_req + 1
}
debug: i_t_beg <- (i_req - 1) * n_t_per_req + 1
debug: i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
debug: t_req <- times_todo[c(i_t_beg, i_t_end)]
debug: t_req_str <- format_ISO8601(t_req, usetz = "Z")
debug: if (verbose) message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
debug: message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
Fetching request 1 of 1 (2006-01-01 to 2006-12-01) ~ 19:32:16 UTC
debug: ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
    0), nc)
debug: unlink(ncs0)
debug: nc_retry <- T
debug: nc_n_try <- 1
debug: n_max_retries
debug: while (nc_retry) {
    res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
        url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
            bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
        time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
    if (inherits(res, "try-error")) {
        err <- attr(res, "condition")
        msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
        nc_n_try <- nc_n_try + 1
        if (nc_n_try > n_max_retries) {
            stop(msg)
        }
        else {
            message(msg, "\nRETRYing...")
            Sys.sleep(1)
        }
    }
    else {
        nc_retry <- F
    }
}
debug: res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
    url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
        bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
    time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
debug: if (inherits(res, "try-error")) {
    err <- attr(res, "condition")
    msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
    nc_n_try <- nc_n_try + 1
    if (nc_n_try > n_max_retries) {
        stop(msg)
    }
    else {
        message(msg, "\nRETRYing...")
        Sys.sleep(1)
    }
} else {
    nc_retry <- F
}
debug: nc_retry <- F
debug: (while) nc_retry
debug: i_req <- i_req + 1
debug: (while) i_req <= n_reqs
debug: ncs <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size > 
    0), nc)
debug: r <- terra::rast(ncs)
debug: stopifnot(all(class(terra::time(r)) %in% c("POSIXct", "POSIXt")))
debug: idx <- dplyr::pull(dplyr::filter(dplyr::arrange(dplyr::tibble(idx = 1:terra::nlyr(r), 
    time = terra::time(r)), time), !duplicated(time)), idx)
debug: r <- terra::subset(r, idx)
debug: stopifnot(terra::crs(r, proj = T) == wgs84)
debug: if (mask_tif) r <- terra::mask(r, sf_zones)
debug: lyrs <- glue("{var}|{terra::time(r)}")
debug: if (length(dims_other) > 0 && !all(length(dims[dims_other]) == 
    1)) stop(glue("Other dimensions not yet supported: {paste(dims_other, collapse = ',')}"))
debug: names(r) <- lyrs
debug: if (!is.null(rast_tif)) {
    if (fs::file_exists(rast_tif)) {
        r_tmp_tif <- tempfile(fileext = ".tif")
        r_tmp <- c(rast(rast_tif), r)
        r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
        terra::writeRaster(r_tmp, r_tmp_tif)
        fs::file_delete(rast_tif)
        fs::file_move(r_tmp_tif, rast_tif)
        rm(r)
        rm(r_tmp)
    }
    else {
        terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
    }
    r <- terra::rast(rast_tif)
}
debug: if (fs::file_exists(rast_tif)) {
    r_tmp_tif <- tempfile(fileext = ".tif")
    r_tmp <- c(rast(rast_tif), r)
    r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
    terra::writeRaster(r_tmp, r_tmp_tif)
    fs::file_delete(rast_tif)
    fs::file_move(r_tmp_tif, rast_tif)
    rm(r)
    rm(r_tmp)
} else {
    terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
}
debug: terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
debug: r <- terra::rast(rast_tif)
debug: d_r <- mutate(tidyr::pivot_longer(sf::st_drop_geometry(sf::st_as_sf(terra::zonal(x = r, 
    z = terra::vect(dplyr::select(sf_zones, dplyr::all_of(fld_zones))), 
    fun = zonal_fun, exact = T, na.rm = T, as.polygons = T))), 
    cols = -dplyr::any_of(fld_zones), names_to = "lyr", values_to = zonal_fun), 
    time = readr::parse_datetime(str_replace(lyr, glue("{var}\\|(.*)"), 
        "\\1")))
debug: if (!is.null(zonal_csv)) write_csv(d_r, zonal_csv)
debug: write_csv(d_r, zonal_csv)
debug: if (!keep_nc) unlink(dir_nc, recursive = T)
debug: unlink(dir_nc, recursive = T)
debug: return(d_r)
Downloading 1 requests, up to 240 time slices each
Called from: extractr::ed_extract(ed, var = v, sf_zones = ply, bbox = bb, 
    mask_tif = F, rast_tif = glue("{dir_out}/{nms}/{yr}.tif"), 
    zonal_fun = "mean", zonal_csv = glue("{dir_out}/{nms}/{yr}.csv"), 
    dir_nc = glue("{dir_out}/{nms}/{yr}_nc"), keep_nc = F, n_max_vals_per_req = 1e+05, 
    time_min = time_min, time_max = time_max, verbose = T)
debug: while (i_req <= n_reqs) {
    i_t_beg <- (i_req - 1) * n_t_per_req + 1
    i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
    t_req <- times_todo[c(i_t_beg, i_t_end)]
    t_req_str <- format_ISO8601(t_req, usetz = "Z")
    if (verbose) 
        message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
    ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
        ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
        0), nc)
    unlink(ncs0)
    nc_retry <- T
    nc_n_try <- 1
    n_max_retries
    while (nc_retry) {
        res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
            url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
                bbox[["xmax"]]), latitude = c(bbox[["ymin"]], 
                bbox[["ymax"]]), time = t_req_str, fmt = "nc", 
            store = rerddap::disk(path = dir_nc)))
        if (inherits(res, "try-error")) {
            err <- attr(res, "condition")
            msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
            nc_n_try <- nc_n_try + 1
            if (nc_n_try > n_max_retries) {
                stop(msg)
            }
            else {
                message(msg, "\nRETRYing...")
                Sys.sleep(1)
            }
        }
        else {
            nc_retry <- F
        }
    }
    i_req <- i_req + 1
}
debug: i_t_beg <- (i_req - 1) * n_t_per_req + 1
debug: i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
debug: t_req <- times_todo[c(i_t_beg, i_t_end)]
debug: t_req_str <- format_ISO8601(t_req, usetz = "Z")
debug: if (verbose) message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
debug: message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
Fetching request 1 of 1 (2007-01-01 to 2007-12-01) ~ 19:32:18 UTC
debug: ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
    0), nc)
debug: unlink(ncs0)
debug: nc_retry <- T
debug: nc_n_try <- 1
debug: n_max_retries
debug: while (nc_retry) {
    res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
        url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
            bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
        time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
    if (inherits(res, "try-error")) {
        err <- attr(res, "condition")
        msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
        nc_n_try <- nc_n_try + 1
        if (nc_n_try > n_max_retries) {
            stop(msg)
        }
        else {
            message(msg, "\nRETRYing...")
            Sys.sleep(1)
        }
    }
    else {
        nc_retry <- F
    }
}
debug: res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
    url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
        bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
    time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
debug: if (inherits(res, "try-error")) {
    err <- attr(res, "condition")
    msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
    nc_n_try <- nc_n_try + 1
    if (nc_n_try > n_max_retries) {
        stop(msg)
    }
    else {
        message(msg, "\nRETRYing...")
        Sys.sleep(1)
    }
} else {
    nc_retry <- F
}
debug: nc_retry <- F
debug: (while) nc_retry
debug: i_req <- i_req + 1
debug: (while) i_req <= n_reqs
debug: ncs <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size > 
    0), nc)
debug: r <- terra::rast(ncs)
debug: stopifnot(all(class(terra::time(r)) %in% c("POSIXct", "POSIXt")))
debug: idx <- dplyr::pull(dplyr::filter(dplyr::arrange(dplyr::tibble(idx = 1:terra::nlyr(r), 
    time = terra::time(r)), time), !duplicated(time)), idx)
debug: r <- terra::subset(r, idx)
debug: stopifnot(terra::crs(r, proj = T) == wgs84)
debug: if (mask_tif) r <- terra::mask(r, sf_zones)
debug: lyrs <- glue("{var}|{terra::time(r)}")
debug: if (length(dims_other) > 0 && !all(length(dims[dims_other]) == 
    1)) stop(glue("Other dimensions not yet supported: {paste(dims_other, collapse = ',')}"))
debug: names(r) <- lyrs
debug: if (!is.null(rast_tif)) {
    if (fs::file_exists(rast_tif)) {
        r_tmp_tif <- tempfile(fileext = ".tif")
        r_tmp <- c(rast(rast_tif), r)
        r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
        terra::writeRaster(r_tmp, r_tmp_tif)
        fs::file_delete(rast_tif)
        fs::file_move(r_tmp_tif, rast_tif)
        rm(r)
        rm(r_tmp)
    }
    else {
        terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
    }
    r <- terra::rast(rast_tif)
}
debug: if (fs::file_exists(rast_tif)) {
    r_tmp_tif <- tempfile(fileext = ".tif")
    r_tmp <- c(rast(rast_tif), r)
    r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
    terra::writeRaster(r_tmp, r_tmp_tif)
    fs::file_delete(rast_tif)
    fs::file_move(r_tmp_tif, rast_tif)
    rm(r)
    rm(r_tmp)
} else {
    terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
}
debug: terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
debug: r <- terra::rast(rast_tif)
debug: d_r <- mutate(tidyr::pivot_longer(sf::st_drop_geometry(sf::st_as_sf(terra::zonal(x = r, 
    z = terra::vect(dplyr::select(sf_zones, dplyr::all_of(fld_zones))), 
    fun = zonal_fun, exact = T, na.rm = T, as.polygons = T))), 
    cols = -dplyr::any_of(fld_zones), names_to = "lyr", values_to = zonal_fun), 
    time = readr::parse_datetime(str_replace(lyr, glue("{var}\\|(.*)"), 
        "\\1")))
debug: if (!is.null(zonal_csv)) write_csv(d_r, zonal_csv)
debug: write_csv(d_r, zonal_csv)
debug: if (!keep_nc) unlink(dir_nc, recursive = T)
debug: unlink(dir_nc, recursive = T)
debug: return(d_r)
Downloading 1 requests, up to 240 time slices each
Called from: extractr::ed_extract(ed, var = v, sf_zones = ply, bbox = bb, 
    mask_tif = F, rast_tif = glue("{dir_out}/{nms}/{yr}.tif"), 
    zonal_fun = "mean", zonal_csv = glue("{dir_out}/{nms}/{yr}.csv"), 
    dir_nc = glue("{dir_out}/{nms}/{yr}_nc"), keep_nc = F, n_max_vals_per_req = 1e+05, 
    time_min = time_min, time_max = time_max, verbose = T)
debug: while (i_req <= n_reqs) {
    i_t_beg <- (i_req - 1) * n_t_per_req + 1
    i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
    t_req <- times_todo[c(i_t_beg, i_t_end)]
    t_req_str <- format_ISO8601(t_req, usetz = "Z")
    if (verbose) 
        message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
    ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
        ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
        0), nc)
    unlink(ncs0)
    nc_retry <- T
    nc_n_try <- 1
    n_max_retries
    while (nc_retry) {
        res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
            url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
                bbox[["xmax"]]), latitude = c(bbox[["ymin"]], 
                bbox[["ymax"]]), time = t_req_str, fmt = "nc", 
            store = rerddap::disk(path = dir_nc)))
        if (inherits(res, "try-error")) {
            err <- attr(res, "condition")
            msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
            nc_n_try <- nc_n_try + 1
            if (nc_n_try > n_max_retries) {
                stop(msg)
            }
            else {
                message(msg, "\nRETRYing...")
                Sys.sleep(1)
            }
        }
        else {
            nc_retry <- F
        }
    }
    i_req <- i_req + 1
}
debug: i_t_beg <- (i_req - 1) * n_t_per_req + 1
debug: i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
debug: t_req <- times_todo[c(i_t_beg, i_t_end)]
debug: t_req_str <- format_ISO8601(t_req, usetz = "Z")
debug: if (verbose) message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
debug: message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
Fetching request 1 of 1 (2008-01-01 to 2008-12-01) ~ 19:32:20 UTC
debug: ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
    0), nc)
debug: unlink(ncs0)
debug: nc_retry <- T
debug: nc_n_try <- 1
debug: n_max_retries
debug: while (nc_retry) {
    res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
        url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
            bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
        time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
    if (inherits(res, "try-error")) {
        err <- attr(res, "condition")
        msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
        nc_n_try <- nc_n_try + 1
        if (nc_n_try > n_max_retries) {
            stop(msg)
        }
        else {
            message(msg, "\nRETRYing...")
            Sys.sleep(1)
        }
    }
    else {
        nc_retry <- F
    }
}
debug: res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
    url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
        bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
    time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
debug: if (inherits(res, "try-error")) {
    err <- attr(res, "condition")
    msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
    nc_n_try <- nc_n_try + 1
    if (nc_n_try > n_max_retries) {
        stop(msg)
    }
    else {
        message(msg, "\nRETRYing...")
        Sys.sleep(1)
    }
} else {
    nc_retry <- F
}
debug: nc_retry <- F
debug: (while) nc_retry
debug: i_req <- i_req + 1
debug: (while) i_req <= n_reqs
debug: ncs <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size > 
    0), nc)
debug: r <- terra::rast(ncs)
debug: stopifnot(all(class(terra::time(r)) %in% c("POSIXct", "POSIXt")))
debug: idx <- dplyr::pull(dplyr::filter(dplyr::arrange(dplyr::tibble(idx = 1:terra::nlyr(r), 
    time = terra::time(r)), time), !duplicated(time)), idx)
debug: r <- terra::subset(r, idx)
debug: stopifnot(terra::crs(r, proj = T) == wgs84)
debug: if (mask_tif) r <- terra::mask(r, sf_zones)
debug: lyrs <- glue("{var}|{terra::time(r)}")
debug: if (length(dims_other) > 0 && !all(length(dims[dims_other]) == 
    1)) stop(glue("Other dimensions not yet supported: {paste(dims_other, collapse = ',')}"))
debug: names(r) <- lyrs
debug: if (!is.null(rast_tif)) {
    if (fs::file_exists(rast_tif)) {
        r_tmp_tif <- tempfile(fileext = ".tif")
        r_tmp <- c(rast(rast_tif), r)
        r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
        terra::writeRaster(r_tmp, r_tmp_tif)
        fs::file_delete(rast_tif)
        fs::file_move(r_tmp_tif, rast_tif)
        rm(r)
        rm(r_tmp)
    }
    else {
        terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
    }
    r <- terra::rast(rast_tif)
}
debug: if (fs::file_exists(rast_tif)) {
    r_tmp_tif <- tempfile(fileext = ".tif")
    r_tmp <- c(rast(rast_tif), r)
    r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
    terra::writeRaster(r_tmp, r_tmp_tif)
    fs::file_delete(rast_tif)
    fs::file_move(r_tmp_tif, rast_tif)
    rm(r)
    rm(r_tmp)
} else {
    terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
}
debug: terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
debug: r <- terra::rast(rast_tif)
debug: d_r <- mutate(tidyr::pivot_longer(sf::st_drop_geometry(sf::st_as_sf(terra::zonal(x = r, 
    z = terra::vect(dplyr::select(sf_zones, dplyr::all_of(fld_zones))), 
    fun = zonal_fun, exact = T, na.rm = T, as.polygons = T))), 
    cols = -dplyr::any_of(fld_zones), names_to = "lyr", values_to = zonal_fun), 
    time = readr::parse_datetime(str_replace(lyr, glue("{var}\\|(.*)"), 
        "\\1")))
debug: if (!is.null(zonal_csv)) write_csv(d_r, zonal_csv)
debug: write_csv(d_r, zonal_csv)
debug: if (!keep_nc) unlink(dir_nc, recursive = T)
debug: unlink(dir_nc, recursive = T)
debug: return(d_r)
Downloading 1 requests, up to 240 time slices each
Called from: extractr::ed_extract(ed, var = v, sf_zones = ply, bbox = bb, 
    mask_tif = F, rast_tif = glue("{dir_out}/{nms}/{yr}.tif"), 
    zonal_fun = "mean", zonal_csv = glue("{dir_out}/{nms}/{yr}.csv"), 
    dir_nc = glue("{dir_out}/{nms}/{yr}_nc"), keep_nc = F, n_max_vals_per_req = 1e+05, 
    time_min = time_min, time_max = time_max, verbose = T)
debug: while (i_req <= n_reqs) {
    i_t_beg <- (i_req - 1) * n_t_per_req + 1
    i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
    t_req <- times_todo[c(i_t_beg, i_t_end)]
    t_req_str <- format_ISO8601(t_req, usetz = "Z")
    if (verbose) 
        message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
    ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
        ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
        0), nc)
    unlink(ncs0)
    nc_retry <- T
    nc_n_try <- 1
    n_max_retries
    while (nc_retry) {
        res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
            url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
                bbox[["xmax"]]), latitude = c(bbox[["ymin"]], 
                bbox[["ymax"]]), time = t_req_str, fmt = "nc", 
            store = rerddap::disk(path = dir_nc)))
        if (inherits(res, "try-error")) {
            err <- attr(res, "condition")
            msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
            nc_n_try <- nc_n_try + 1
            if (nc_n_try > n_max_retries) {
                stop(msg)
            }
            else {
                message(msg, "\nRETRYing...")
                Sys.sleep(1)
            }
        }
        else {
            nc_retry <- F
        }
    }
    i_req <- i_req + 1
}
debug: i_t_beg <- (i_req - 1) * n_t_per_req + 1
debug: i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
debug: t_req <- times_todo[c(i_t_beg, i_t_end)]
debug: t_req_str <- format_ISO8601(t_req, usetz = "Z")
debug: if (verbose) message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
debug: message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
Fetching request 1 of 1 (2009-01-01 to 2009-12-01) ~ 19:32:22 UTC
debug: ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
    0), nc)
debug: unlink(ncs0)
debug: nc_retry <- T
debug: nc_n_try <- 1
debug: n_max_retries
debug: while (nc_retry) {
    res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
        url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
            bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
        time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
    if (inherits(res, "try-error")) {
        err <- attr(res, "condition")
        msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
        nc_n_try <- nc_n_try + 1
        if (nc_n_try > n_max_retries) {
            stop(msg)
        }
        else {
            message(msg, "\nRETRYing...")
            Sys.sleep(1)
        }
    }
    else {
        nc_retry <- F
    }
}
debug: res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
    url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
        bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
    time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
debug: if (inherits(res, "try-error")) {
    err <- attr(res, "condition")
    msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
    nc_n_try <- nc_n_try + 1
    if (nc_n_try > n_max_retries) {
        stop(msg)
    }
    else {
        message(msg, "\nRETRYing...")
        Sys.sleep(1)
    }
} else {
    nc_retry <- F
}
debug: nc_retry <- F
debug: (while) nc_retry
debug: i_req <- i_req + 1
debug: (while) i_req <= n_reqs
debug: ncs <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size > 
    0), nc)
debug: r <- terra::rast(ncs)
debug: stopifnot(all(class(terra::time(r)) %in% c("POSIXct", "POSIXt")))
debug: idx <- dplyr::pull(dplyr::filter(dplyr::arrange(dplyr::tibble(idx = 1:terra::nlyr(r), 
    time = terra::time(r)), time), !duplicated(time)), idx)
debug: r <- terra::subset(r, idx)
debug: stopifnot(terra::crs(r, proj = T) == wgs84)
debug: if (mask_tif) r <- terra::mask(r, sf_zones)
debug: lyrs <- glue("{var}|{terra::time(r)}")
debug: if (length(dims_other) > 0 && !all(length(dims[dims_other]) == 
    1)) stop(glue("Other dimensions not yet supported: {paste(dims_other, collapse = ',')}"))
debug: names(r) <- lyrs
debug: if (!is.null(rast_tif)) {
    if (fs::file_exists(rast_tif)) {
        r_tmp_tif <- tempfile(fileext = ".tif")
        r_tmp <- c(rast(rast_tif), r)
        r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
        terra::writeRaster(r_tmp, r_tmp_tif)
        fs::file_delete(rast_tif)
        fs::file_move(r_tmp_tif, rast_tif)
        rm(r)
        rm(r_tmp)
    }
    else {
        terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
    }
    r <- terra::rast(rast_tif)
}
debug: if (fs::file_exists(rast_tif)) {
    r_tmp_tif <- tempfile(fileext = ".tif")
    r_tmp <- c(rast(rast_tif), r)
    r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
    terra::writeRaster(r_tmp, r_tmp_tif)
    fs::file_delete(rast_tif)
    fs::file_move(r_tmp_tif, rast_tif)
    rm(r)
    rm(r_tmp)
} else {
    terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
}
debug: terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
debug: r <- terra::rast(rast_tif)
debug: d_r <- mutate(tidyr::pivot_longer(sf::st_drop_geometry(sf::st_as_sf(terra::zonal(x = r, 
    z = terra::vect(dplyr::select(sf_zones, dplyr::all_of(fld_zones))), 
    fun = zonal_fun, exact = T, na.rm = T, as.polygons = T))), 
    cols = -dplyr::any_of(fld_zones), names_to = "lyr", values_to = zonal_fun), 
    time = readr::parse_datetime(str_replace(lyr, glue("{var}\\|(.*)"), 
        "\\1")))
debug: if (!is.null(zonal_csv)) write_csv(d_r, zonal_csv)
debug: write_csv(d_r, zonal_csv)
debug: if (!keep_nc) unlink(dir_nc, recursive = T)
debug: unlink(dir_nc, recursive = T)
debug: return(d_r)
Downloading 1 requests, up to 240 time slices each
Called from: extractr::ed_extract(ed, var = v, sf_zones = ply, bbox = bb, 
    mask_tif = F, rast_tif = glue("{dir_out}/{nms}/{yr}.tif"), 
    zonal_fun = "mean", zonal_csv = glue("{dir_out}/{nms}/{yr}.csv"), 
    dir_nc = glue("{dir_out}/{nms}/{yr}_nc"), keep_nc = F, n_max_vals_per_req = 1e+05, 
    time_min = time_min, time_max = time_max, verbose = T)
debug: while (i_req <= n_reqs) {
    i_t_beg <- (i_req - 1) * n_t_per_req + 1
    i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
    t_req <- times_todo[c(i_t_beg, i_t_end)]
    t_req_str <- format_ISO8601(t_req, usetz = "Z")
    if (verbose) 
        message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
    ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
        ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
        0), nc)
    unlink(ncs0)
    nc_retry <- T
    nc_n_try <- 1
    n_max_retries
    while (nc_retry) {
        res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
            url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
                bbox[["xmax"]]), latitude = c(bbox[["ymin"]], 
                bbox[["ymax"]]), time = t_req_str, fmt = "nc", 
            store = rerddap::disk(path = dir_nc)))
        if (inherits(res, "try-error")) {
            err <- attr(res, "condition")
            msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
            nc_n_try <- nc_n_try + 1
            if (nc_n_try > n_max_retries) {
                stop(msg)
            }
            else {
                message(msg, "\nRETRYing...")
                Sys.sleep(1)
            }
        }
        else {
            nc_retry <- F
        }
    }
    i_req <- i_req + 1
}
debug: i_t_beg <- (i_req - 1) * n_t_per_req + 1
debug: i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
debug: t_req <- times_todo[c(i_t_beg, i_t_end)]
debug: t_req_str <- format_ISO8601(t_req, usetz = "Z")
debug: if (verbose) message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
debug: message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
Fetching request 1 of 1 (2010-01-01 to 2010-12-01) ~ 19:32:24 UTC
debug: ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
    0), nc)
debug: unlink(ncs0)
debug: nc_retry <- T
debug: nc_n_try <- 1
debug: n_max_retries
debug: while (nc_retry) {
    res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
        url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
            bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
        time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
    if (inherits(res, "try-error")) {
        err <- attr(res, "condition")
        msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
        nc_n_try <- nc_n_try + 1
        if (nc_n_try > n_max_retries) {
            stop(msg)
        }
        else {
            message(msg, "\nRETRYing...")
            Sys.sleep(1)
        }
    }
    else {
        nc_retry <- F
    }
}
debug: res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
    url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
        bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
    time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
debug: if (inherits(res, "try-error")) {
    err <- attr(res, "condition")
    msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
    nc_n_try <- nc_n_try + 1
    if (nc_n_try > n_max_retries) {
        stop(msg)
    }
    else {
        message(msg, "\nRETRYing...")
        Sys.sleep(1)
    }
} else {
    nc_retry <- F
}
debug: nc_retry <- F
debug: (while) nc_retry
debug: i_req <- i_req + 1
debug: (while) i_req <= n_reqs
debug: ncs <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size > 
    0), nc)
debug: r <- terra::rast(ncs)
debug: stopifnot(all(class(terra::time(r)) %in% c("POSIXct", "POSIXt")))
debug: idx <- dplyr::pull(dplyr::filter(dplyr::arrange(dplyr::tibble(idx = 1:terra::nlyr(r), 
    time = terra::time(r)), time), !duplicated(time)), idx)
debug: r <- terra::subset(r, idx)
debug: stopifnot(terra::crs(r, proj = T) == wgs84)
debug: if (mask_tif) r <- terra::mask(r, sf_zones)
debug: lyrs <- glue("{var}|{terra::time(r)}")
debug: if (length(dims_other) > 0 && !all(length(dims[dims_other]) == 
    1)) stop(glue("Other dimensions not yet supported: {paste(dims_other, collapse = ',')}"))
debug: names(r) <- lyrs
debug: if (!is.null(rast_tif)) {
    if (fs::file_exists(rast_tif)) {
        r_tmp_tif <- tempfile(fileext = ".tif")
        r_tmp <- c(rast(rast_tif), r)
        r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
        terra::writeRaster(r_tmp, r_tmp_tif)
        fs::file_delete(rast_tif)
        fs::file_move(r_tmp_tif, rast_tif)
        rm(r)
        rm(r_tmp)
    }
    else {
        terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
    }
    r <- terra::rast(rast_tif)
}
debug: if (fs::file_exists(rast_tif)) {
    r_tmp_tif <- tempfile(fileext = ".tif")
    r_tmp <- c(rast(rast_tif), r)
    r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
    terra::writeRaster(r_tmp, r_tmp_tif)
    fs::file_delete(rast_tif)
    fs::file_move(r_tmp_tif, rast_tif)
    rm(r)
    rm(r_tmp)
} else {
    terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
}
debug: terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
debug: r <- terra::rast(rast_tif)
debug: d_r <- mutate(tidyr::pivot_longer(sf::st_drop_geometry(sf::st_as_sf(terra::zonal(x = r, 
    z = terra::vect(dplyr::select(sf_zones, dplyr::all_of(fld_zones))), 
    fun = zonal_fun, exact = T, na.rm = T, as.polygons = T))), 
    cols = -dplyr::any_of(fld_zones), names_to = "lyr", values_to = zonal_fun), 
    time = readr::parse_datetime(str_replace(lyr, glue("{var}\\|(.*)"), 
        "\\1")))
debug: if (!is.null(zonal_csv)) write_csv(d_r, zonal_csv)
debug: write_csv(d_r, zonal_csv)
debug: if (!keep_nc) unlink(dir_nc, recursive = T)
debug: unlink(dir_nc, recursive = T)
debug: return(d_r)
Downloading 1 requests, up to 240 time slices each
Called from: extractr::ed_extract(ed, var = v, sf_zones = ply, bbox = bb, 
    mask_tif = F, rast_tif = glue("{dir_out}/{nms}/{yr}.tif"), 
    zonal_fun = "mean", zonal_csv = glue("{dir_out}/{nms}/{yr}.csv"), 
    dir_nc = glue("{dir_out}/{nms}/{yr}_nc"), keep_nc = F, n_max_vals_per_req = 1e+05, 
    time_min = time_min, time_max = time_max, verbose = T)
debug: while (i_req <= n_reqs) {
    i_t_beg <- (i_req - 1) * n_t_per_req + 1
    i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
    t_req <- times_todo[c(i_t_beg, i_t_end)]
    t_req_str <- format_ISO8601(t_req, usetz = "Z")
    if (verbose) 
        message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
    ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
        ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
        0), nc)
    unlink(ncs0)
    nc_retry <- T
    nc_n_try <- 1
    n_max_retries
    while (nc_retry) {
        res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
            url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
                bbox[["xmax"]]), latitude = c(bbox[["ymin"]], 
                bbox[["ymax"]]), time = t_req_str, fmt = "nc", 
            store = rerddap::disk(path = dir_nc)))
        if (inherits(res, "try-error")) {
            err <- attr(res, "condition")
            msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
            nc_n_try <- nc_n_try + 1
            if (nc_n_try > n_max_retries) {
                stop(msg)
            }
            else {
                message(msg, "\nRETRYing...")
                Sys.sleep(1)
            }
        }
        else {
            nc_retry <- F
        }
    }
    i_req <- i_req + 1
}
debug: i_t_beg <- (i_req - 1) * n_t_per_req + 1
debug: i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
debug: t_req <- times_todo[c(i_t_beg, i_t_end)]
debug: t_req_str <- format_ISO8601(t_req, usetz = "Z")
debug: if (verbose) message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
debug: message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
Fetching request 1 of 1 (2011-01-01 to 2011-12-01) ~ 19:32:26 UTC
debug: ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
    0), nc)
debug: unlink(ncs0)
debug: nc_retry <- T
debug: nc_n_try <- 1
debug: n_max_retries
debug: while (nc_retry) {
    res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
        url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
            bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
        time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
    if (inherits(res, "try-error")) {
        err <- attr(res, "condition")
        msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
        nc_n_try <- nc_n_try + 1
        if (nc_n_try > n_max_retries) {
            stop(msg)
        }
        else {
            message(msg, "\nRETRYing...")
            Sys.sleep(1)
        }
    }
    else {
        nc_retry <- F
    }
}
debug: res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
    url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
        bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
    time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
debug: if (inherits(res, "try-error")) {
    err <- attr(res, "condition")
    msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
    nc_n_try <- nc_n_try + 1
    if (nc_n_try > n_max_retries) {
        stop(msg)
    }
    else {
        message(msg, "\nRETRYing...")
        Sys.sleep(1)
    }
} else {
    nc_retry <- F
}
debug: nc_retry <- F
debug: (while) nc_retry
debug: i_req <- i_req + 1
debug: (while) i_req <= n_reqs
debug: ncs <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size > 
    0), nc)
debug: r <- terra::rast(ncs)
debug: stopifnot(all(class(terra::time(r)) %in% c("POSIXct", "POSIXt")))
debug: idx <- dplyr::pull(dplyr::filter(dplyr::arrange(dplyr::tibble(idx = 1:terra::nlyr(r), 
    time = terra::time(r)), time), !duplicated(time)), idx)
debug: r <- terra::subset(r, idx)
debug: stopifnot(terra::crs(r, proj = T) == wgs84)
debug: if (mask_tif) r <- terra::mask(r, sf_zones)
debug: lyrs <- glue("{var}|{terra::time(r)}")
debug: if (length(dims_other) > 0 && !all(length(dims[dims_other]) == 
    1)) stop(glue("Other dimensions not yet supported: {paste(dims_other, collapse = ',')}"))
debug: names(r) <- lyrs
debug: if (!is.null(rast_tif)) {
    if (fs::file_exists(rast_tif)) {
        r_tmp_tif <- tempfile(fileext = ".tif")
        r_tmp <- c(rast(rast_tif), r)
        r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
        terra::writeRaster(r_tmp, r_tmp_tif)
        fs::file_delete(rast_tif)
        fs::file_move(r_tmp_tif, rast_tif)
        rm(r)
        rm(r_tmp)
    }
    else {
        terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
    }
    r <- terra::rast(rast_tif)
}
debug: if (fs::file_exists(rast_tif)) {
    r_tmp_tif <- tempfile(fileext = ".tif")
    r_tmp <- c(rast(rast_tif), r)
    r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
    terra::writeRaster(r_tmp, r_tmp_tif)
    fs::file_delete(rast_tif)
    fs::file_move(r_tmp_tif, rast_tif)
    rm(r)
    rm(r_tmp)
} else {
    terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
}
debug: terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
debug: r <- terra::rast(rast_tif)
debug: d_r <- mutate(tidyr::pivot_longer(sf::st_drop_geometry(sf::st_as_sf(terra::zonal(x = r, 
    z = terra::vect(dplyr::select(sf_zones, dplyr::all_of(fld_zones))), 
    fun = zonal_fun, exact = T, na.rm = T, as.polygons = T))), 
    cols = -dplyr::any_of(fld_zones), names_to = "lyr", values_to = zonal_fun), 
    time = readr::parse_datetime(str_replace(lyr, glue("{var}\\|(.*)"), 
        "\\1")))
debug: if (!is.null(zonal_csv)) write_csv(d_r, zonal_csv)
debug: write_csv(d_r, zonal_csv)
debug: if (!keep_nc) unlink(dir_nc, recursive = T)
debug: unlink(dir_nc, recursive = T)
debug: return(d_r)
Downloading 1 requests, up to 240 time slices each
Called from: extractr::ed_extract(ed, var = v, sf_zones = ply, bbox = bb, 
    mask_tif = F, rast_tif = glue("{dir_out}/{nms}/{yr}.tif"), 
    zonal_fun = "mean", zonal_csv = glue("{dir_out}/{nms}/{yr}.csv"), 
    dir_nc = glue("{dir_out}/{nms}/{yr}_nc"), keep_nc = F, n_max_vals_per_req = 1e+05, 
    time_min = time_min, time_max = time_max, verbose = T)
debug: while (i_req <= n_reqs) {
    i_t_beg <- (i_req - 1) * n_t_per_req + 1
    i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
    t_req <- times_todo[c(i_t_beg, i_t_end)]
    t_req_str <- format_ISO8601(t_req, usetz = "Z")
    if (verbose) 
        message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
    ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
        ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
        0), nc)
    unlink(ncs0)
    nc_retry <- T
    nc_n_try <- 1
    n_max_retries
    while (nc_retry) {
        res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
            url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
                bbox[["xmax"]]), latitude = c(bbox[["ymin"]], 
                bbox[["ymax"]]), time = t_req_str, fmt = "nc", 
            store = rerddap::disk(path = dir_nc)))
        if (inherits(res, "try-error")) {
            err <- attr(res, "condition")
            msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
            nc_n_try <- nc_n_try + 1
            if (nc_n_try > n_max_retries) {
                stop(msg)
            }
            else {
                message(msg, "\nRETRYing...")
                Sys.sleep(1)
            }
        }
        else {
            nc_retry <- F
        }
    }
    i_req <- i_req + 1
}
debug: i_t_beg <- (i_req - 1) * n_t_per_req + 1
debug: i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
debug: t_req <- times_todo[c(i_t_beg, i_t_end)]
debug: t_req_str <- format_ISO8601(t_req, usetz = "Z")
debug: if (verbose) message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
debug: message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
Fetching request 1 of 1 (2012-01-01 to 2012-12-01) ~ 19:32:28 UTC
debug: ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
    0), nc)
debug: unlink(ncs0)
debug: nc_retry <- T
debug: nc_n_try <- 1
debug: n_max_retries
debug: while (nc_retry) {
    res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
        url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
            bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
        time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
    if (inherits(res, "try-error")) {
        err <- attr(res, "condition")
        msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
        nc_n_try <- nc_n_try + 1
        if (nc_n_try > n_max_retries) {
            stop(msg)
        }
        else {
            message(msg, "\nRETRYing...")
            Sys.sleep(1)
        }
    }
    else {
        nc_retry <- F
    }
}
debug: res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
    url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
        bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
    time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
debug: if (inherits(res, "try-error")) {
    err <- attr(res, "condition")
    msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
    nc_n_try <- nc_n_try + 1
    if (nc_n_try > n_max_retries) {
        stop(msg)
    }
    else {
        message(msg, "\nRETRYing...")
        Sys.sleep(1)
    }
} else {
    nc_retry <- F
}
debug: nc_retry <- F
debug: (while) nc_retry
debug: i_req <- i_req + 1
debug: (while) i_req <= n_reqs
debug: ncs <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size > 
    0), nc)
debug: r <- terra::rast(ncs)
debug: stopifnot(all(class(terra::time(r)) %in% c("POSIXct", "POSIXt")))
debug: idx <- dplyr::pull(dplyr::filter(dplyr::arrange(dplyr::tibble(idx = 1:terra::nlyr(r), 
    time = terra::time(r)), time), !duplicated(time)), idx)
debug: r <- terra::subset(r, idx)
debug: stopifnot(terra::crs(r, proj = T) == wgs84)
debug: if (mask_tif) r <- terra::mask(r, sf_zones)
debug: lyrs <- glue("{var}|{terra::time(r)}")
debug: if (length(dims_other) > 0 && !all(length(dims[dims_other]) == 
    1)) stop(glue("Other dimensions not yet supported: {paste(dims_other, collapse = ',')}"))
debug: names(r) <- lyrs
debug: if (!is.null(rast_tif)) {
    if (fs::file_exists(rast_tif)) {
        r_tmp_tif <- tempfile(fileext = ".tif")
        r_tmp <- c(rast(rast_tif), r)
        r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
        terra::writeRaster(r_tmp, r_tmp_tif)
        fs::file_delete(rast_tif)
        fs::file_move(r_tmp_tif, rast_tif)
        rm(r)
        rm(r_tmp)
    }
    else {
        terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
    }
    r <- terra::rast(rast_tif)
}
debug: if (fs::file_exists(rast_tif)) {
    r_tmp_tif <- tempfile(fileext = ".tif")
    r_tmp <- c(rast(rast_tif), r)
    r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
    terra::writeRaster(r_tmp, r_tmp_tif)
    fs::file_delete(rast_tif)
    fs::file_move(r_tmp_tif, rast_tif)
    rm(r)
    rm(r_tmp)
} else {
    terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
}
debug: terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
debug: r <- terra::rast(rast_tif)
debug: d_r <- mutate(tidyr::pivot_longer(sf::st_drop_geometry(sf::st_as_sf(terra::zonal(x = r, 
    z = terra::vect(dplyr::select(sf_zones, dplyr::all_of(fld_zones))), 
    fun = zonal_fun, exact = T, na.rm = T, as.polygons = T))), 
    cols = -dplyr::any_of(fld_zones), names_to = "lyr", values_to = zonal_fun), 
    time = readr::parse_datetime(str_replace(lyr, glue("{var}\\|(.*)"), 
        "\\1")))
debug: if (!is.null(zonal_csv)) write_csv(d_r, zonal_csv)
debug: write_csv(d_r, zonal_csv)
debug: if (!keep_nc) unlink(dir_nc, recursive = T)
debug: unlink(dir_nc, recursive = T)
debug: return(d_r)
Downloading 1 requests, up to 240 time slices each
Called from: extractr::ed_extract(ed, var = v, sf_zones = ply, bbox = bb, 
    mask_tif = F, rast_tif = glue("{dir_out}/{nms}/{yr}.tif"), 
    zonal_fun = "mean", zonal_csv = glue("{dir_out}/{nms}/{yr}.csv"), 
    dir_nc = glue("{dir_out}/{nms}/{yr}_nc"), keep_nc = F, n_max_vals_per_req = 1e+05, 
    time_min = time_min, time_max = time_max, verbose = T)
debug: while (i_req <= n_reqs) {
    i_t_beg <- (i_req - 1) * n_t_per_req + 1
    i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
    t_req <- times_todo[c(i_t_beg, i_t_end)]
    t_req_str <- format_ISO8601(t_req, usetz = "Z")
    if (verbose) 
        message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
    ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
        ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
        0), nc)
    unlink(ncs0)
    nc_retry <- T
    nc_n_try <- 1
    n_max_retries
    while (nc_retry) {
        res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
            url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
                bbox[["xmax"]]), latitude = c(bbox[["ymin"]], 
                bbox[["ymax"]]), time = t_req_str, fmt = "nc", 
            store = rerddap::disk(path = dir_nc)))
        if (inherits(res, "try-error")) {
            err <- attr(res, "condition")
            msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
            nc_n_try <- nc_n_try + 1
            if (nc_n_try > n_max_retries) {
                stop(msg)
            }
            else {
                message(msg, "\nRETRYing...")
                Sys.sleep(1)
            }
        }
        else {
            nc_retry <- F
        }
    }
    i_req <- i_req + 1
}
debug: i_t_beg <- (i_req - 1) * n_t_per_req + 1
debug: i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
debug: t_req <- times_todo[c(i_t_beg, i_t_end)]
debug: t_req_str <- format_ISO8601(t_req, usetz = "Z")
debug: if (verbose) message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
debug: message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
Fetching request 1 of 1 (2013-01-01 to 2013-12-01) ~ 19:32:30 UTC
debug: ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
    0), nc)
debug: unlink(ncs0)
debug: nc_retry <- T
debug: nc_n_try <- 1
debug: n_max_retries
debug: while (nc_retry) {
    res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
        url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
            bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
        time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
    if (inherits(res, "try-error")) {
        err <- attr(res, "condition")
        msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
        nc_n_try <- nc_n_try + 1
        if (nc_n_try > n_max_retries) {
            stop(msg)
        }
        else {
            message(msg, "\nRETRYing...")
            Sys.sleep(1)
        }
    }
    else {
        nc_retry <- F
    }
}
debug: res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
    url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
        bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
    time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
debug: if (inherits(res, "try-error")) {
    err <- attr(res, "condition")
    msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
    nc_n_try <- nc_n_try + 1
    if (nc_n_try > n_max_retries) {
        stop(msg)
    }
    else {
        message(msg, "\nRETRYing...")
        Sys.sleep(1)
    }
} else {
    nc_retry <- F
}
debug: nc_retry <- F
debug: (while) nc_retry
debug: i_req <- i_req + 1
debug: (while) i_req <= n_reqs
debug: ncs <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size > 
    0), nc)
debug: r <- terra::rast(ncs)
debug: stopifnot(all(class(terra::time(r)) %in% c("POSIXct", "POSIXt")))
debug: idx <- dplyr::pull(dplyr::filter(dplyr::arrange(dplyr::tibble(idx = 1:terra::nlyr(r), 
    time = terra::time(r)), time), !duplicated(time)), idx)
debug: r <- terra::subset(r, idx)
debug: stopifnot(terra::crs(r, proj = T) == wgs84)
debug: if (mask_tif) r <- terra::mask(r, sf_zones)
debug: lyrs <- glue("{var}|{terra::time(r)}")
debug: if (length(dims_other) > 0 && !all(length(dims[dims_other]) == 
    1)) stop(glue("Other dimensions not yet supported: {paste(dims_other, collapse = ',')}"))
debug: names(r) <- lyrs
debug: if (!is.null(rast_tif)) {
    if (fs::file_exists(rast_tif)) {
        r_tmp_tif <- tempfile(fileext = ".tif")
        r_tmp <- c(rast(rast_tif), r)
        r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
        terra::writeRaster(r_tmp, r_tmp_tif)
        fs::file_delete(rast_tif)
        fs::file_move(r_tmp_tif, rast_tif)
        rm(r)
        rm(r_tmp)
    }
    else {
        terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
    }
    r <- terra::rast(rast_tif)
}
debug: if (fs::file_exists(rast_tif)) {
    r_tmp_tif <- tempfile(fileext = ".tif")
    r_tmp <- c(rast(rast_tif), r)
    r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
    terra::writeRaster(r_tmp, r_tmp_tif)
    fs::file_delete(rast_tif)
    fs::file_move(r_tmp_tif, rast_tif)
    rm(r)
    rm(r_tmp)
} else {
    terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
}
debug: terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
debug: r <- terra::rast(rast_tif)
debug: d_r <- mutate(tidyr::pivot_longer(sf::st_drop_geometry(sf::st_as_sf(terra::zonal(x = r, 
    z = terra::vect(dplyr::select(sf_zones, dplyr::all_of(fld_zones))), 
    fun = zonal_fun, exact = T, na.rm = T, as.polygons = T))), 
    cols = -dplyr::any_of(fld_zones), names_to = "lyr", values_to = zonal_fun), 
    time = readr::parse_datetime(str_replace(lyr, glue("{var}\\|(.*)"), 
        "\\1")))
debug: if (!is.null(zonal_csv)) write_csv(d_r, zonal_csv)
debug: write_csv(d_r, zonal_csv)
debug: if (!keep_nc) unlink(dir_nc, recursive = T)
debug: unlink(dir_nc, recursive = T)
debug: return(d_r)
Downloading 1 requests, up to 240 time slices each
Called from: extractr::ed_extract(ed, var = v, sf_zones = ply, bbox = bb, 
    mask_tif = F, rast_tif = glue("{dir_out}/{nms}/{yr}.tif"), 
    zonal_fun = "mean", zonal_csv = glue("{dir_out}/{nms}/{yr}.csv"), 
    dir_nc = glue("{dir_out}/{nms}/{yr}_nc"), keep_nc = F, n_max_vals_per_req = 1e+05, 
    time_min = time_min, time_max = time_max, verbose = T)
debug: while (i_req <= n_reqs) {
    i_t_beg <- (i_req - 1) * n_t_per_req + 1
    i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
    t_req <- times_todo[c(i_t_beg, i_t_end)]
    t_req_str <- format_ISO8601(t_req, usetz = "Z")
    if (verbose) 
        message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
    ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
        ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
        0), nc)
    unlink(ncs0)
    nc_retry <- T
    nc_n_try <- 1
    n_max_retries
    while (nc_retry) {
        res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
            url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
                bbox[["xmax"]]), latitude = c(bbox[["ymin"]], 
                bbox[["ymax"]]), time = t_req_str, fmt = "nc", 
            store = rerddap::disk(path = dir_nc)))
        if (inherits(res, "try-error")) {
            err <- attr(res, "condition")
            msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
            nc_n_try <- nc_n_try + 1
            if (nc_n_try > n_max_retries) {
                stop(msg)
            }
            else {
                message(msg, "\nRETRYing...")
                Sys.sleep(1)
            }
        }
        else {
            nc_retry <- F
        }
    }
    i_req <- i_req + 1
}
debug: i_t_beg <- (i_req - 1) * n_t_per_req + 1
debug: i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
debug: t_req <- times_todo[c(i_t_beg, i_t_end)]
debug: t_req_str <- format_ISO8601(t_req, usetz = "Z")
debug: if (verbose) message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
debug: message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
Fetching request 1 of 1 (2014-01-01 to 2014-12-01) ~ 19:32:32 UTC
debug: ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
    0), nc)
debug: unlink(ncs0)
debug: nc_retry <- T
debug: nc_n_try <- 1
debug: n_max_retries
debug: while (nc_retry) {
    res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
        url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
            bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
        time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
    if (inherits(res, "try-error")) {
        err <- attr(res, "condition")
        msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
        nc_n_try <- nc_n_try + 1
        if (nc_n_try > n_max_retries) {
            stop(msg)
        }
        else {
            message(msg, "\nRETRYing...")
            Sys.sleep(1)
        }
    }
    else {
        nc_retry <- F
    }
}
debug: res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
    url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
        bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
    time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
debug: if (inherits(res, "try-error")) {
    err <- attr(res, "condition")
    msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
    nc_n_try <- nc_n_try + 1
    if (nc_n_try > n_max_retries) {
        stop(msg)
    }
    else {
        message(msg, "\nRETRYing...")
        Sys.sleep(1)
    }
} else {
    nc_retry <- F
}
debug: nc_retry <- F
debug: (while) nc_retry
debug: i_req <- i_req + 1
debug: (while) i_req <= n_reqs
debug: ncs <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size > 
    0), nc)
debug: r <- terra::rast(ncs)
debug: stopifnot(all(class(terra::time(r)) %in% c("POSIXct", "POSIXt")))
debug: idx <- dplyr::pull(dplyr::filter(dplyr::arrange(dplyr::tibble(idx = 1:terra::nlyr(r), 
    time = terra::time(r)), time), !duplicated(time)), idx)
debug: r <- terra::subset(r, idx)
debug: stopifnot(terra::crs(r, proj = T) == wgs84)
debug: if (mask_tif) r <- terra::mask(r, sf_zones)
debug: lyrs <- glue("{var}|{terra::time(r)}")
debug: if (length(dims_other) > 0 && !all(length(dims[dims_other]) == 
    1)) stop(glue("Other dimensions not yet supported: {paste(dims_other, collapse = ',')}"))
debug: names(r) <- lyrs
debug: if (!is.null(rast_tif)) {
    if (fs::file_exists(rast_tif)) {
        r_tmp_tif <- tempfile(fileext = ".tif")
        r_tmp <- c(rast(rast_tif), r)
        r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
        terra::writeRaster(r_tmp, r_tmp_tif)
        fs::file_delete(rast_tif)
        fs::file_move(r_tmp_tif, rast_tif)
        rm(r)
        rm(r_tmp)
    }
    else {
        terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
    }
    r <- terra::rast(rast_tif)
}
debug: if (fs::file_exists(rast_tif)) {
    r_tmp_tif <- tempfile(fileext = ".tif")
    r_tmp <- c(rast(rast_tif), r)
    r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
    terra::writeRaster(r_tmp, r_tmp_tif)
    fs::file_delete(rast_tif)
    fs::file_move(r_tmp_tif, rast_tif)
    rm(r)
    rm(r_tmp)
} else {
    terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
}
debug: terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
debug: r <- terra::rast(rast_tif)
debug: d_r <- mutate(tidyr::pivot_longer(sf::st_drop_geometry(sf::st_as_sf(terra::zonal(x = r, 
    z = terra::vect(dplyr::select(sf_zones, dplyr::all_of(fld_zones))), 
    fun = zonal_fun, exact = T, na.rm = T, as.polygons = T))), 
    cols = -dplyr::any_of(fld_zones), names_to = "lyr", values_to = zonal_fun), 
    time = readr::parse_datetime(str_replace(lyr, glue("{var}\\|(.*)"), 
        "\\1")))
debug: if (!is.null(zonal_csv)) write_csv(d_r, zonal_csv)
debug: write_csv(d_r, zonal_csv)
debug: if (!keep_nc) unlink(dir_nc, recursive = T)
debug: unlink(dir_nc, recursive = T)
debug: return(d_r)
Downloading 1 requests, up to 240 time slices each
Called from: extractr::ed_extract(ed, var = v, sf_zones = ply, bbox = bb, 
    mask_tif = F, rast_tif = glue("{dir_out}/{nms}/{yr}.tif"), 
    zonal_fun = "mean", zonal_csv = glue("{dir_out}/{nms}/{yr}.csv"), 
    dir_nc = glue("{dir_out}/{nms}/{yr}_nc"), keep_nc = F, n_max_vals_per_req = 1e+05, 
    time_min = time_min, time_max = time_max, verbose = T)
debug: while (i_req <= n_reqs) {
    i_t_beg <- (i_req - 1) * n_t_per_req + 1
    i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
    t_req <- times_todo[c(i_t_beg, i_t_end)]
    t_req_str <- format_ISO8601(t_req, usetz = "Z")
    if (verbose) 
        message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
    ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
        ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
        0), nc)
    unlink(ncs0)
    nc_retry <- T
    nc_n_try <- 1
    n_max_retries
    while (nc_retry) {
        res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
            url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
                bbox[["xmax"]]), latitude = c(bbox[["ymin"]], 
                bbox[["ymax"]]), time = t_req_str, fmt = "nc", 
            store = rerddap::disk(path = dir_nc)))
        if (inherits(res, "try-error")) {
            err <- attr(res, "condition")
            msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
            nc_n_try <- nc_n_try + 1
            if (nc_n_try > n_max_retries) {
                stop(msg)
            }
            else {
                message(msg, "\nRETRYing...")
                Sys.sleep(1)
            }
        }
        else {
            nc_retry <- F
        }
    }
    i_req <- i_req + 1
}
debug: i_t_beg <- (i_req - 1) * n_t_per_req + 1
debug: i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
debug: t_req <- times_todo[c(i_t_beg, i_t_end)]
debug: t_req_str <- format_ISO8601(t_req, usetz = "Z")
debug: if (verbose) message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
debug: message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
Fetching request 1 of 1 (2015-01-01 to 2015-12-01) ~ 19:32:34 UTC
debug: ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
    0), nc)
debug: unlink(ncs0)
debug: nc_retry <- T
debug: nc_n_try <- 1
debug: n_max_retries
debug: while (nc_retry) {
    res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
        url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
            bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
        time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
    if (inherits(res, "try-error")) {
        err <- attr(res, "condition")
        msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
        nc_n_try <- nc_n_try + 1
        if (nc_n_try > n_max_retries) {
            stop(msg)
        }
        else {
            message(msg, "\nRETRYing...")
            Sys.sleep(1)
        }
    }
    else {
        nc_retry <- F
    }
}
debug: res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
    url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
        bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
    time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
debug: if (inherits(res, "try-error")) {
    err <- attr(res, "condition")
    msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
    nc_n_try <- nc_n_try + 1
    if (nc_n_try > n_max_retries) {
        stop(msg)
    }
    else {
        message(msg, "\nRETRYing...")
        Sys.sleep(1)
    }
} else {
    nc_retry <- F
}
debug: nc_retry <- F
debug: (while) nc_retry
debug: i_req <- i_req + 1
debug: (while) i_req <= n_reqs
debug: ncs <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size > 
    0), nc)
debug: r <- terra::rast(ncs)
debug: stopifnot(all(class(terra::time(r)) %in% c("POSIXct", "POSIXt")))
debug: idx <- dplyr::pull(dplyr::filter(dplyr::arrange(dplyr::tibble(idx = 1:terra::nlyr(r), 
    time = terra::time(r)), time), !duplicated(time)), idx)
debug: r <- terra::subset(r, idx)
debug: stopifnot(terra::crs(r, proj = T) == wgs84)
debug: if (mask_tif) r <- terra::mask(r, sf_zones)
debug: lyrs <- glue("{var}|{terra::time(r)}")
debug: if (length(dims_other) > 0 && !all(length(dims[dims_other]) == 
    1)) stop(glue("Other dimensions not yet supported: {paste(dims_other, collapse = ',')}"))
debug: names(r) <- lyrs
debug: if (!is.null(rast_tif)) {
    if (fs::file_exists(rast_tif)) {
        r_tmp_tif <- tempfile(fileext = ".tif")
        r_tmp <- c(rast(rast_tif), r)
        r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
        terra::writeRaster(r_tmp, r_tmp_tif)
        fs::file_delete(rast_tif)
        fs::file_move(r_tmp_tif, rast_tif)
        rm(r)
        rm(r_tmp)
    }
    else {
        terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
    }
    r <- terra::rast(rast_tif)
}
debug: if (fs::file_exists(rast_tif)) {
    r_tmp_tif <- tempfile(fileext = ".tif")
    r_tmp <- c(rast(rast_tif), r)
    r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
    terra::writeRaster(r_tmp, r_tmp_tif)
    fs::file_delete(rast_tif)
    fs::file_move(r_tmp_tif, rast_tif)
    rm(r)
    rm(r_tmp)
} else {
    terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
}
debug: terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
debug: r <- terra::rast(rast_tif)
debug: d_r <- mutate(tidyr::pivot_longer(sf::st_drop_geometry(sf::st_as_sf(terra::zonal(x = r, 
    z = terra::vect(dplyr::select(sf_zones, dplyr::all_of(fld_zones))), 
    fun = zonal_fun, exact = T, na.rm = T, as.polygons = T))), 
    cols = -dplyr::any_of(fld_zones), names_to = "lyr", values_to = zonal_fun), 
    time = readr::parse_datetime(str_replace(lyr, glue("{var}\\|(.*)"), 
        "\\1")))
debug: if (!is.null(zonal_csv)) write_csv(d_r, zonal_csv)
debug: write_csv(d_r, zonal_csv)
debug: if (!keep_nc) unlink(dir_nc, recursive = T)
debug: unlink(dir_nc, recursive = T)
debug: return(d_r)
Downloading 1 requests, up to 240 time slices each
Called from: extractr::ed_extract(ed, var = v, sf_zones = ply, bbox = bb, 
    mask_tif = F, rast_tif = glue("{dir_out}/{nms}/{yr}.tif"), 
    zonal_fun = "mean", zonal_csv = glue("{dir_out}/{nms}/{yr}.csv"), 
    dir_nc = glue("{dir_out}/{nms}/{yr}_nc"), keep_nc = F, n_max_vals_per_req = 1e+05, 
    time_min = time_min, time_max = time_max, verbose = T)
debug: while (i_req <= n_reqs) {
    i_t_beg <- (i_req - 1) * n_t_per_req + 1
    i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
    t_req <- times_todo[c(i_t_beg, i_t_end)]
    t_req_str <- format_ISO8601(t_req, usetz = "Z")
    if (verbose) 
        message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
    ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
        ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
        0), nc)
    unlink(ncs0)
    nc_retry <- T
    nc_n_try <- 1
    n_max_retries
    while (nc_retry) {
        res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
            url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
                bbox[["xmax"]]), latitude = c(bbox[["ymin"]], 
                bbox[["ymax"]]), time = t_req_str, fmt = "nc", 
            store = rerddap::disk(path = dir_nc)))
        if (inherits(res, "try-error")) {
            err <- attr(res, "condition")
            msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
            nc_n_try <- nc_n_try + 1
            if (nc_n_try > n_max_retries) {
                stop(msg)
            }
            else {
                message(msg, "\nRETRYing...")
                Sys.sleep(1)
            }
        }
        else {
            nc_retry <- F
        }
    }
    i_req <- i_req + 1
}
debug: i_t_beg <- (i_req - 1) * n_t_per_req + 1
debug: i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
debug: t_req <- times_todo[c(i_t_beg, i_t_end)]
debug: t_req_str <- format_ISO8601(t_req, usetz = "Z")
debug: if (verbose) message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
debug: message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
Fetching request 1 of 1 (2016-01-01 to 2016-12-01) ~ 19:32:36 UTC
debug: ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
    0), nc)
debug: unlink(ncs0)
debug: nc_retry <- T
debug: nc_n_try <- 1
debug: n_max_retries
debug: while (nc_retry) {
    res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
        url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
            bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
        time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
    if (inherits(res, "try-error")) {
        err <- attr(res, "condition")
        msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
        nc_n_try <- nc_n_try + 1
        if (nc_n_try > n_max_retries) {
            stop(msg)
        }
        else {
            message(msg, "\nRETRYing...")
            Sys.sleep(1)
        }
    }
    else {
        nc_retry <- F
    }
}
debug: res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
    url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
        bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
    time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
debug: if (inherits(res, "try-error")) {
    err <- attr(res, "condition")
    msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
    nc_n_try <- nc_n_try + 1
    if (nc_n_try > n_max_retries) {
        stop(msg)
    }
    else {
        message(msg, "\nRETRYing...")
        Sys.sleep(1)
    }
} else {
    nc_retry <- F
}
debug: nc_retry <- F
debug: (while) nc_retry
debug: i_req <- i_req + 1
debug: (while) i_req <= n_reqs
debug: ncs <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size > 
    0), nc)
debug: r <- terra::rast(ncs)
debug: stopifnot(all(class(terra::time(r)) %in% c("POSIXct", "POSIXt")))
debug: idx <- dplyr::pull(dplyr::filter(dplyr::arrange(dplyr::tibble(idx = 1:terra::nlyr(r), 
    time = terra::time(r)), time), !duplicated(time)), idx)
debug: r <- terra::subset(r, idx)
debug: stopifnot(terra::crs(r, proj = T) == wgs84)
debug: if (mask_tif) r <- terra::mask(r, sf_zones)
debug: lyrs <- glue("{var}|{terra::time(r)}")
debug: if (length(dims_other) > 0 && !all(length(dims[dims_other]) == 
    1)) stop(glue("Other dimensions not yet supported: {paste(dims_other, collapse = ',')}"))
debug: names(r) <- lyrs
debug: if (!is.null(rast_tif)) {
    if (fs::file_exists(rast_tif)) {
        r_tmp_tif <- tempfile(fileext = ".tif")
        r_tmp <- c(rast(rast_tif), r)
        r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
        terra::writeRaster(r_tmp, r_tmp_tif)
        fs::file_delete(rast_tif)
        fs::file_move(r_tmp_tif, rast_tif)
        rm(r)
        rm(r_tmp)
    }
    else {
        terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
    }
    r <- terra::rast(rast_tif)
}
debug: if (fs::file_exists(rast_tif)) {
    r_tmp_tif <- tempfile(fileext = ".tif")
    r_tmp <- c(rast(rast_tif), r)
    r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
    terra::writeRaster(r_tmp, r_tmp_tif)
    fs::file_delete(rast_tif)
    fs::file_move(r_tmp_tif, rast_tif)
    rm(r)
    rm(r_tmp)
} else {
    terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
}
debug: terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
debug: r <- terra::rast(rast_tif)
debug: d_r <- mutate(tidyr::pivot_longer(sf::st_drop_geometry(sf::st_as_sf(terra::zonal(x = r, 
    z = terra::vect(dplyr::select(sf_zones, dplyr::all_of(fld_zones))), 
    fun = zonal_fun, exact = T, na.rm = T, as.polygons = T))), 
    cols = -dplyr::any_of(fld_zones), names_to = "lyr", values_to = zonal_fun), 
    time = readr::parse_datetime(str_replace(lyr, glue("{var}\\|(.*)"), 
        "\\1")))
debug: if (!is.null(zonal_csv)) write_csv(d_r, zonal_csv)
debug: write_csv(d_r, zonal_csv)
debug: if (!keep_nc) unlink(dir_nc, recursive = T)
debug: unlink(dir_nc, recursive = T)
debug: return(d_r)
Downloading 1 requests, up to 240 time slices each
Called from: extractr::ed_extract(ed, var = v, sf_zones = ply, bbox = bb, 
    mask_tif = F, rast_tif = glue("{dir_out}/{nms}/{yr}.tif"), 
    zonal_fun = "mean", zonal_csv = glue("{dir_out}/{nms}/{yr}.csv"), 
    dir_nc = glue("{dir_out}/{nms}/{yr}_nc"), keep_nc = F, n_max_vals_per_req = 1e+05, 
    time_min = time_min, time_max = time_max, verbose = T)
debug: while (i_req <= n_reqs) {
    i_t_beg <- (i_req - 1) * n_t_per_req + 1
    i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
    t_req <- times_todo[c(i_t_beg, i_t_end)]
    t_req_str <- format_ISO8601(t_req, usetz = "Z")
    if (verbose) 
        message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
    ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
        ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
        0), nc)
    unlink(ncs0)
    nc_retry <- T
    nc_n_try <- 1
    n_max_retries
    while (nc_retry) {
        res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
            url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
                bbox[["xmax"]]), latitude = c(bbox[["ymin"]], 
                bbox[["ymax"]]), time = t_req_str, fmt = "nc", 
            store = rerddap::disk(path = dir_nc)))
        if (inherits(res, "try-error")) {
            err <- attr(res, "condition")
            msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
            nc_n_try <- nc_n_try + 1
            if (nc_n_try > n_max_retries) {
                stop(msg)
            }
            else {
                message(msg, "\nRETRYing...")
                Sys.sleep(1)
            }
        }
        else {
            nc_retry <- F
        }
    }
    i_req <- i_req + 1
}
debug: i_t_beg <- (i_req - 1) * n_t_per_req + 1
debug: i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
debug: t_req <- times_todo[c(i_t_beg, i_t_end)]
debug: t_req_str <- format_ISO8601(t_req, usetz = "Z")
debug: if (verbose) message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
debug: message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
Fetching request 1 of 1 (2017-01-01 to 2017-12-01) ~ 19:32:37 UTC
debug: ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
    0), nc)
debug: unlink(ncs0)
debug: nc_retry <- T
debug: nc_n_try <- 1
debug: n_max_retries
debug: while (nc_retry) {
    res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
        url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
            bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
        time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
    if (inherits(res, "try-error")) {
        err <- attr(res, "condition")
        msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
        nc_n_try <- nc_n_try + 1
        if (nc_n_try > n_max_retries) {
            stop(msg)
        }
        else {
            message(msg, "\nRETRYing...")
            Sys.sleep(1)
        }
    }
    else {
        nc_retry <- F
    }
}
debug: res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
    url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
        bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
    time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
debug: if (inherits(res, "try-error")) {
    err <- attr(res, "condition")
    msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
    nc_n_try <- nc_n_try + 1
    if (nc_n_try > n_max_retries) {
        stop(msg)
    }
    else {
        message(msg, "\nRETRYing...")
        Sys.sleep(1)
    }
} else {
    nc_retry <- F
}
debug: nc_retry <- F
debug: (while) nc_retry
debug: i_req <- i_req + 1
debug: (while) i_req <= n_reqs
debug: ncs <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size > 
    0), nc)
debug: r <- terra::rast(ncs)
debug: stopifnot(all(class(terra::time(r)) %in% c("POSIXct", "POSIXt")))
debug: idx <- dplyr::pull(dplyr::filter(dplyr::arrange(dplyr::tibble(idx = 1:terra::nlyr(r), 
    time = terra::time(r)), time), !duplicated(time)), idx)
debug: r <- terra::subset(r, idx)
debug: stopifnot(terra::crs(r, proj = T) == wgs84)
debug: if (mask_tif) r <- terra::mask(r, sf_zones)
debug: lyrs <- glue("{var}|{terra::time(r)}")
debug: if (length(dims_other) > 0 && !all(length(dims[dims_other]) == 
    1)) stop(glue("Other dimensions not yet supported: {paste(dims_other, collapse = ',')}"))
debug: names(r) <- lyrs
debug: if (!is.null(rast_tif)) {
    if (fs::file_exists(rast_tif)) {
        r_tmp_tif <- tempfile(fileext = ".tif")
        r_tmp <- c(rast(rast_tif), r)
        r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
        terra::writeRaster(r_tmp, r_tmp_tif)
        fs::file_delete(rast_tif)
        fs::file_move(r_tmp_tif, rast_tif)
        rm(r)
        rm(r_tmp)
    }
    else {
        terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
    }
    r <- terra::rast(rast_tif)
}
debug: if (fs::file_exists(rast_tif)) {
    r_tmp_tif <- tempfile(fileext = ".tif")
    r_tmp <- c(rast(rast_tif), r)
    r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
    terra::writeRaster(r_tmp, r_tmp_tif)
    fs::file_delete(rast_tif)
    fs::file_move(r_tmp_tif, rast_tif)
    rm(r)
    rm(r_tmp)
} else {
    terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
}
debug: terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
debug: r <- terra::rast(rast_tif)
debug: d_r <- mutate(tidyr::pivot_longer(sf::st_drop_geometry(sf::st_as_sf(terra::zonal(x = r, 
    z = terra::vect(dplyr::select(sf_zones, dplyr::all_of(fld_zones))), 
    fun = zonal_fun, exact = T, na.rm = T, as.polygons = T))), 
    cols = -dplyr::any_of(fld_zones), names_to = "lyr", values_to = zonal_fun), 
    time = readr::parse_datetime(str_replace(lyr, glue("{var}\\|(.*)"), 
        "\\1")))
debug: if (!is.null(zonal_csv)) write_csv(d_r, zonal_csv)
debug: write_csv(d_r, zonal_csv)
debug: if (!keep_nc) unlink(dir_nc, recursive = T)
debug: unlink(dir_nc, recursive = T)
debug: return(d_r)
Downloading 1 requests, up to 240 time slices each
Called from: extractr::ed_extract(ed, var = v, sf_zones = ply, bbox = bb, 
    mask_tif = F, rast_tif = glue("{dir_out}/{nms}/{yr}.tif"), 
    zonal_fun = "mean", zonal_csv = glue("{dir_out}/{nms}/{yr}.csv"), 
    dir_nc = glue("{dir_out}/{nms}/{yr}_nc"), keep_nc = F, n_max_vals_per_req = 1e+05, 
    time_min = time_min, time_max = time_max, verbose = T)
debug: while (i_req <= n_reqs) {
    i_t_beg <- (i_req - 1) * n_t_per_req + 1
    i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
    t_req <- times_todo[c(i_t_beg, i_t_end)]
    t_req_str <- format_ISO8601(t_req, usetz = "Z")
    if (verbose) 
        message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
    ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
        ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
        0), nc)
    unlink(ncs0)
    nc_retry <- T
    nc_n_try <- 1
    n_max_retries
    while (nc_retry) {
        res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
            url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
                bbox[["xmax"]]), latitude = c(bbox[["ymin"]], 
                bbox[["ymax"]]), time = t_req_str, fmt = "nc", 
            store = rerddap::disk(path = dir_nc)))
        if (inherits(res, "try-error")) {
            err <- attr(res, "condition")
            msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
            nc_n_try <- nc_n_try + 1
            if (nc_n_try > n_max_retries) {
                stop(msg)
            }
            else {
                message(msg, "\nRETRYing...")
                Sys.sleep(1)
            }
        }
        else {
            nc_retry <- F
        }
    }
    i_req <- i_req + 1
}
debug: i_t_beg <- (i_req - 1) * n_t_per_req + 1
debug: i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
debug: t_req <- times_todo[c(i_t_beg, i_t_end)]
debug: t_req_str <- format_ISO8601(t_req, usetz = "Z")
debug: if (verbose) message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
debug: message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
Fetching request 1 of 1 (2018-01-01 to 2018-12-01) ~ 19:32:39 UTC
debug: ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
    0), nc)
debug: unlink(ncs0)
debug: nc_retry <- T
debug: nc_n_try <- 1
debug: n_max_retries
debug: while (nc_retry) {
    res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
        url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
            bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
        time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
    if (inherits(res, "try-error")) {
        err <- attr(res, "condition")
        msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
        nc_n_try <- nc_n_try + 1
        if (nc_n_try > n_max_retries) {
            stop(msg)
        }
        else {
            message(msg, "\nRETRYing...")
            Sys.sleep(1)
        }
    }
    else {
        nc_retry <- F
    }
}
debug: res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
    url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
        bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
    time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
debug: if (inherits(res, "try-error")) {
    err <- attr(res, "condition")
    msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
    nc_n_try <- nc_n_try + 1
    if (nc_n_try > n_max_retries) {
        stop(msg)
    }
    else {
        message(msg, "\nRETRYing...")
        Sys.sleep(1)
    }
} else {
    nc_retry <- F
}
debug: nc_retry <- F
debug: (while) nc_retry
debug: i_req <- i_req + 1
debug: (while) i_req <= n_reqs
debug: ncs <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size > 
    0), nc)
debug: r <- terra::rast(ncs)
debug: stopifnot(all(class(terra::time(r)) %in% c("POSIXct", "POSIXt")))
debug: idx <- dplyr::pull(dplyr::filter(dplyr::arrange(dplyr::tibble(idx = 1:terra::nlyr(r), 
    time = terra::time(r)), time), !duplicated(time)), idx)
debug: r <- terra::subset(r, idx)
debug: stopifnot(terra::crs(r, proj = T) == wgs84)
debug: if (mask_tif) r <- terra::mask(r, sf_zones)
debug: lyrs <- glue("{var}|{terra::time(r)}")
debug: if (length(dims_other) > 0 && !all(length(dims[dims_other]) == 
    1)) stop(glue("Other dimensions not yet supported: {paste(dims_other, collapse = ',')}"))
debug: names(r) <- lyrs
debug: if (!is.null(rast_tif)) {
    if (fs::file_exists(rast_tif)) {
        r_tmp_tif <- tempfile(fileext = ".tif")
        r_tmp <- c(rast(rast_tif), r)
        r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
        terra::writeRaster(r_tmp, r_tmp_tif)
        fs::file_delete(rast_tif)
        fs::file_move(r_tmp_tif, rast_tif)
        rm(r)
        rm(r_tmp)
    }
    else {
        terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
    }
    r <- terra::rast(rast_tif)
}
debug: if (fs::file_exists(rast_tif)) {
    r_tmp_tif <- tempfile(fileext = ".tif")
    r_tmp <- c(rast(rast_tif), r)
    r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
    terra::writeRaster(r_tmp, r_tmp_tif)
    fs::file_delete(rast_tif)
    fs::file_move(r_tmp_tif, rast_tif)
    rm(r)
    rm(r_tmp)
} else {
    terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
}
debug: terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
debug: r <- terra::rast(rast_tif)
debug: d_r <- mutate(tidyr::pivot_longer(sf::st_drop_geometry(sf::st_as_sf(terra::zonal(x = r, 
    z = terra::vect(dplyr::select(sf_zones, dplyr::all_of(fld_zones))), 
    fun = zonal_fun, exact = T, na.rm = T, as.polygons = T))), 
    cols = -dplyr::any_of(fld_zones), names_to = "lyr", values_to = zonal_fun), 
    time = readr::parse_datetime(str_replace(lyr, glue("{var}\\|(.*)"), 
        "\\1")))
debug: if (!is.null(zonal_csv)) write_csv(d_r, zonal_csv)
debug: write_csv(d_r, zonal_csv)
debug: if (!keep_nc) unlink(dir_nc, recursive = T)
debug: unlink(dir_nc, recursive = T)
debug: return(d_r)
Downloading 1 requests, up to 240 time slices each
Called from: extractr::ed_extract(ed, var = v, sf_zones = ply, bbox = bb, 
    mask_tif = F, rast_tif = glue("{dir_out}/{nms}/{yr}.tif"), 
    zonal_fun = "mean", zonal_csv = glue("{dir_out}/{nms}/{yr}.csv"), 
    dir_nc = glue("{dir_out}/{nms}/{yr}_nc"), keep_nc = F, n_max_vals_per_req = 1e+05, 
    time_min = time_min, time_max = time_max, verbose = T)
debug: while (i_req <= n_reqs) {
    i_t_beg <- (i_req - 1) * n_t_per_req + 1
    i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
    t_req <- times_todo[c(i_t_beg, i_t_end)]
    t_req_str <- format_ISO8601(t_req, usetz = "Z")
    if (verbose) 
        message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
    ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
        ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
        0), nc)
    unlink(ncs0)
    nc_retry <- T
    nc_n_try <- 1
    n_max_retries
    while (nc_retry) {
        res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
            url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
                bbox[["xmax"]]), latitude = c(bbox[["ymin"]], 
                bbox[["ymax"]]), time = t_req_str, fmt = "nc", 
            store = rerddap::disk(path = dir_nc)))
        if (inherits(res, "try-error")) {
            err <- attr(res, "condition")
            msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
            nc_n_try <- nc_n_try + 1
            if (nc_n_try > n_max_retries) {
                stop(msg)
            }
            else {
                message(msg, "\nRETRYing...")
                Sys.sleep(1)
            }
        }
        else {
            nc_retry <- F
        }
    }
    i_req <- i_req + 1
}
debug: i_t_beg <- (i_req - 1) * n_t_per_req + 1
debug: i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
debug: t_req <- times_todo[c(i_t_beg, i_t_end)]
debug: t_req_str <- format_ISO8601(t_req, usetz = "Z")
debug: if (verbose) message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
debug: message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
Fetching request 1 of 1 (2019-01-01 to 2019-12-01) ~ 19:32:41 UTC
debug: ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
    0), nc)
debug: unlink(ncs0)
debug: nc_retry <- T
debug: nc_n_try <- 1
debug: n_max_retries
debug: while (nc_retry) {
    res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
        url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
            bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
        time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
    if (inherits(res, "try-error")) {
        err <- attr(res, "condition")
        msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
        nc_n_try <- nc_n_try + 1
        if (nc_n_try > n_max_retries) {
            stop(msg)
        }
        else {
            message(msg, "\nRETRYing...")
            Sys.sleep(1)
        }
    }
    else {
        nc_retry <- F
    }
}
debug: res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
    url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
        bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
    time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
debug: if (inherits(res, "try-error")) {
    err <- attr(res, "condition")
    msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
    nc_n_try <- nc_n_try + 1
    if (nc_n_try > n_max_retries) {
        stop(msg)
    }
    else {
        message(msg, "\nRETRYing...")
        Sys.sleep(1)
    }
} else {
    nc_retry <- F
}
debug: nc_retry <- F
debug: (while) nc_retry
debug: i_req <- i_req + 1
debug: (while) i_req <= n_reqs
debug: ncs <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size > 
    0), nc)
debug: r <- terra::rast(ncs)
debug: stopifnot(all(class(terra::time(r)) %in% c("POSIXct", "POSIXt")))
debug: idx <- dplyr::pull(dplyr::filter(dplyr::arrange(dplyr::tibble(idx = 1:terra::nlyr(r), 
    time = terra::time(r)), time), !duplicated(time)), idx)
debug: r <- terra::subset(r, idx)
debug: stopifnot(terra::crs(r, proj = T) == wgs84)
debug: if (mask_tif) r <- terra::mask(r, sf_zones)
debug: lyrs <- glue("{var}|{terra::time(r)}")
debug: if (length(dims_other) > 0 && !all(length(dims[dims_other]) == 
    1)) stop(glue("Other dimensions not yet supported: {paste(dims_other, collapse = ',')}"))
debug: names(r) <- lyrs
debug: if (!is.null(rast_tif)) {
    if (fs::file_exists(rast_tif)) {
        r_tmp_tif <- tempfile(fileext = ".tif")
        r_tmp <- c(rast(rast_tif), r)
        r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
        terra::writeRaster(r_tmp, r_tmp_tif)
        fs::file_delete(rast_tif)
        fs::file_move(r_tmp_tif, rast_tif)
        rm(r)
        rm(r_tmp)
    }
    else {
        terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
    }
    r <- terra::rast(rast_tif)
}
debug: if (fs::file_exists(rast_tif)) {
    r_tmp_tif <- tempfile(fileext = ".tif")
    r_tmp <- c(rast(rast_tif), r)
    r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
    terra::writeRaster(r_tmp, r_tmp_tif)
    fs::file_delete(rast_tif)
    fs::file_move(r_tmp_tif, rast_tif)
    rm(r)
    rm(r_tmp)
} else {
    terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
}
debug: terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
debug: r <- terra::rast(rast_tif)
debug: d_r <- mutate(tidyr::pivot_longer(sf::st_drop_geometry(sf::st_as_sf(terra::zonal(x = r, 
    z = terra::vect(dplyr::select(sf_zones, dplyr::all_of(fld_zones))), 
    fun = zonal_fun, exact = T, na.rm = T, as.polygons = T))), 
    cols = -dplyr::any_of(fld_zones), names_to = "lyr", values_to = zonal_fun), 
    time = readr::parse_datetime(str_replace(lyr, glue("{var}\\|(.*)"), 
        "\\1")))
debug: if (!is.null(zonal_csv)) write_csv(d_r, zonal_csv)
debug: write_csv(d_r, zonal_csv)
debug: if (!keep_nc) unlink(dir_nc, recursive = T)
debug: unlink(dir_nc, recursive = T)
debug: return(d_r)
Downloading 1 requests, up to 240 time slices each
Called from: extractr::ed_extract(ed, var = v, sf_zones = ply, bbox = bb, 
    mask_tif = F, rast_tif = glue("{dir_out}/{nms}/{yr}.tif"), 
    zonal_fun = "mean", zonal_csv = glue("{dir_out}/{nms}/{yr}.csv"), 
    dir_nc = glue("{dir_out}/{nms}/{yr}_nc"), keep_nc = F, n_max_vals_per_req = 1e+05, 
    time_min = time_min, time_max = time_max, verbose = T)
debug: while (i_req <= n_reqs) {
    i_t_beg <- (i_req - 1) * n_t_per_req + 1
    i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
    t_req <- times_todo[c(i_t_beg, i_t_end)]
    t_req_str <- format_ISO8601(t_req, usetz = "Z")
    if (verbose) 
        message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
    ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
        ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
        0), nc)
    unlink(ncs0)
    nc_retry <- T
    nc_n_try <- 1
    n_max_retries
    while (nc_retry) {
        res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
            url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
                bbox[["xmax"]]), latitude = c(bbox[["ymin"]], 
                bbox[["ymax"]]), time = t_req_str, fmt = "nc", 
            store = rerddap::disk(path = dir_nc)))
        if (inherits(res, "try-error")) {
            err <- attr(res, "condition")
            msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
            nc_n_try <- nc_n_try + 1
            if (nc_n_try > n_max_retries) {
                stop(msg)
            }
            else {
                message(msg, "\nRETRYing...")
                Sys.sleep(1)
            }
        }
        else {
            nc_retry <- F
        }
    }
    i_req <- i_req + 1
}
debug: i_t_beg <- (i_req - 1) * n_t_per_req + 1
debug: i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
debug: t_req <- times_todo[c(i_t_beg, i_t_end)]
debug: t_req_str <- format_ISO8601(t_req, usetz = "Z")
debug: if (verbose) message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
debug: message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
Fetching request 1 of 1 (2020-01-01 to 2020-12-01) ~ 19:32:43 UTC
debug: ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
    0), nc)
debug: unlink(ncs0)
debug: nc_retry <- T
debug: nc_n_try <- 1
debug: n_max_retries
debug: while (nc_retry) {
    res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
        url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
            bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
        time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
    if (inherits(res, "try-error")) {
        err <- attr(res, "condition")
        msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
        nc_n_try <- nc_n_try + 1
        if (nc_n_try > n_max_retries) {
            stop(msg)
        }
        else {
            message(msg, "\nRETRYing...")
            Sys.sleep(1)
        }
    }
    else {
        nc_retry <- F
    }
}
debug: res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
    url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
        bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
    time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
debug: if (inherits(res, "try-error")) {
    err <- attr(res, "condition")
    msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
    nc_n_try <- nc_n_try + 1
    if (nc_n_try > n_max_retries) {
        stop(msg)
    }
    else {
        message(msg, "\nRETRYing...")
        Sys.sleep(1)
    }
} else {
    nc_retry <- F
}
debug: nc_retry <- F
debug: (while) nc_retry
debug: i_req <- i_req + 1
debug: (while) i_req <= n_reqs
debug: ncs <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size > 
    0), nc)
debug: r <- terra::rast(ncs)
debug: stopifnot(all(class(terra::time(r)) %in% c("POSIXct", "POSIXt")))
debug: idx <- dplyr::pull(dplyr::filter(dplyr::arrange(dplyr::tibble(idx = 1:terra::nlyr(r), 
    time = terra::time(r)), time), !duplicated(time)), idx)
debug: r <- terra::subset(r, idx)
debug: stopifnot(terra::crs(r, proj = T) == wgs84)
debug: if (mask_tif) r <- terra::mask(r, sf_zones)
debug: lyrs <- glue("{var}|{terra::time(r)}")
debug: if (length(dims_other) > 0 && !all(length(dims[dims_other]) == 
    1)) stop(glue("Other dimensions not yet supported: {paste(dims_other, collapse = ',')}"))
debug: names(r) <- lyrs
debug: if (!is.null(rast_tif)) {
    if (fs::file_exists(rast_tif)) {
        r_tmp_tif <- tempfile(fileext = ".tif")
        r_tmp <- c(rast(rast_tif), r)
        r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
        terra::writeRaster(r_tmp, r_tmp_tif)
        fs::file_delete(rast_tif)
        fs::file_move(r_tmp_tif, rast_tif)
        rm(r)
        rm(r_tmp)
    }
    else {
        terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
    }
    r <- terra::rast(rast_tif)
}
debug: if (fs::file_exists(rast_tif)) {
    r_tmp_tif <- tempfile(fileext = ".tif")
    r_tmp <- c(rast(rast_tif), r)
    r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
    terra::writeRaster(r_tmp, r_tmp_tif)
    fs::file_delete(rast_tif)
    fs::file_move(r_tmp_tif, rast_tif)
    rm(r)
    rm(r_tmp)
} else {
    terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
}
debug: terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
debug: r <- terra::rast(rast_tif)
debug: d_r <- mutate(tidyr::pivot_longer(sf::st_drop_geometry(sf::st_as_sf(terra::zonal(x = r, 
    z = terra::vect(dplyr::select(sf_zones, dplyr::all_of(fld_zones))), 
    fun = zonal_fun, exact = T, na.rm = T, as.polygons = T))), 
    cols = -dplyr::any_of(fld_zones), names_to = "lyr", values_to = zonal_fun), 
    time = readr::parse_datetime(str_replace(lyr, glue("{var}\\|(.*)"), 
        "\\1")))
debug: if (!is.null(zonal_csv)) write_csv(d_r, zonal_csv)
debug: write_csv(d_r, zonal_csv)
debug: if (!keep_nc) unlink(dir_nc, recursive = T)
debug: unlink(dir_nc, recursive = T)
debug: return(d_r)
Downloading 1 requests, up to 240 time slices each
Called from: extractr::ed_extract(ed, var = v, sf_zones = ply, bbox = bb, 
    mask_tif = F, rast_tif = glue("{dir_out}/{nms}/{yr}.tif"), 
    zonal_fun = "mean", zonal_csv = glue("{dir_out}/{nms}/{yr}.csv"), 
    dir_nc = glue("{dir_out}/{nms}/{yr}_nc"), keep_nc = F, n_max_vals_per_req = 1e+05, 
    time_min = time_min, time_max = time_max, verbose = T)
debug: while (i_req <= n_reqs) {
    i_t_beg <- (i_req - 1) * n_t_per_req + 1
    i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
    t_req <- times_todo[c(i_t_beg, i_t_end)]
    t_req_str <- format_ISO8601(t_req, usetz = "Z")
    if (verbose) 
        message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
    ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
        ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
        0), nc)
    unlink(ncs0)
    nc_retry <- T
    nc_n_try <- 1
    n_max_retries
    while (nc_retry) {
        res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
            url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
                bbox[["xmax"]]), latitude = c(bbox[["ymin"]], 
                bbox[["ymax"]]), time = t_req_str, fmt = "nc", 
            store = rerddap::disk(path = dir_nc)))
        if (inherits(res, "try-error")) {
            err <- attr(res, "condition")
            msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
            nc_n_try <- nc_n_try + 1
            if (nc_n_try > n_max_retries) {
                stop(msg)
            }
            else {
                message(msg, "\nRETRYing...")
                Sys.sleep(1)
            }
        }
        else {
            nc_retry <- F
        }
    }
    i_req <- i_req + 1
}
debug: i_t_beg <- (i_req - 1) * n_t_per_req + 1
debug: i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
debug: t_req <- times_todo[c(i_t_beg, i_t_end)]
debug: t_req_str <- format_ISO8601(t_req, usetz = "Z")
debug: if (verbose) message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
debug: message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
Fetching request 1 of 1 (2021-01-01 to 2021-12-01) ~ 19:32:45 UTC
debug: ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
    0), nc)
debug: unlink(ncs0)
debug: nc_retry <- T
debug: nc_n_try <- 1
debug: n_max_retries
debug: while (nc_retry) {
    res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
        url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
            bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
        time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
    if (inherits(res, "try-error")) {
        err <- attr(res, "condition")
        msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
        nc_n_try <- nc_n_try + 1
        if (nc_n_try > n_max_retries) {
            stop(msg)
        }
        else {
            message(msg, "\nRETRYing...")
            Sys.sleep(1)
        }
    }
    else {
        nc_retry <- F
    }
}
debug: res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
    url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
        bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
    time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
debug: if (inherits(res, "try-error")) {
    err <- attr(res, "condition")
    msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
    nc_n_try <- nc_n_try + 1
    if (nc_n_try > n_max_retries) {
        stop(msg)
    }
    else {
        message(msg, "\nRETRYing...")
        Sys.sleep(1)
    }
} else {
    nc_retry <- F
}
debug: nc_retry <- F
debug: (while) nc_retry
debug: i_req <- i_req + 1
debug: (while) i_req <= n_reqs
debug: ncs <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size > 
    0), nc)
debug: r <- terra::rast(ncs)
debug: stopifnot(all(class(terra::time(r)) %in% c("POSIXct", "POSIXt")))
debug: idx <- dplyr::pull(dplyr::filter(dplyr::arrange(dplyr::tibble(idx = 1:terra::nlyr(r), 
    time = terra::time(r)), time), !duplicated(time)), idx)
debug: r <- terra::subset(r, idx)
debug: stopifnot(terra::crs(r, proj = T) == wgs84)
debug: if (mask_tif) r <- terra::mask(r, sf_zones)
debug: lyrs <- glue("{var}|{terra::time(r)}")
debug: if (length(dims_other) > 0 && !all(length(dims[dims_other]) == 
    1)) stop(glue("Other dimensions not yet supported: {paste(dims_other, collapse = ',')}"))
debug: names(r) <- lyrs
debug: if (!is.null(rast_tif)) {
    if (fs::file_exists(rast_tif)) {
        r_tmp_tif <- tempfile(fileext = ".tif")
        r_tmp <- c(rast(rast_tif), r)
        r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
        terra::writeRaster(r_tmp, r_tmp_tif)
        fs::file_delete(rast_tif)
        fs::file_move(r_tmp_tif, rast_tif)
        rm(r)
        rm(r_tmp)
    }
    else {
        terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
    }
    r <- terra::rast(rast_tif)
}
debug: if (fs::file_exists(rast_tif)) {
    r_tmp_tif <- tempfile(fileext = ".tif")
    r_tmp <- c(rast(rast_tif), r)
    r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
    terra::writeRaster(r_tmp, r_tmp_tif)
    fs::file_delete(rast_tif)
    fs::file_move(r_tmp_tif, rast_tif)
    rm(r)
    rm(r_tmp)
} else {
    terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
}
debug: terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
debug: r <- terra::rast(rast_tif)
debug: d_r <- mutate(tidyr::pivot_longer(sf::st_drop_geometry(sf::st_as_sf(terra::zonal(x = r, 
    z = terra::vect(dplyr::select(sf_zones, dplyr::all_of(fld_zones))), 
    fun = zonal_fun, exact = T, na.rm = T, as.polygons = T))), 
    cols = -dplyr::any_of(fld_zones), names_to = "lyr", values_to = zonal_fun), 
    time = readr::parse_datetime(str_replace(lyr, glue("{var}\\|(.*)"), 
        "\\1")))
debug: if (!is.null(zonal_csv)) write_csv(d_r, zonal_csv)
debug: write_csv(d_r, zonal_csv)
debug: if (!keep_nc) unlink(dir_nc, recursive = T)
debug: unlink(dir_nc, recursive = T)
debug: return(d_r)
Downloading 1 requests, up to 240 time slices each
Called from: extractr::ed_extract(ed, var = v, sf_zones = ply, bbox = bb, 
    mask_tif = F, rast_tif = glue("{dir_out}/{nms}/{yr}.tif"), 
    zonal_fun = "mean", zonal_csv = glue("{dir_out}/{nms}/{yr}.csv"), 
    dir_nc = glue("{dir_out}/{nms}/{yr}_nc"), keep_nc = F, n_max_vals_per_req = 1e+05, 
    time_min = time_min, time_max = time_max, verbose = T)
debug: while (i_req <= n_reqs) {
    i_t_beg <- (i_req - 1) * n_t_per_req + 1
    i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
    t_req <- times_todo[c(i_t_beg, i_t_end)]
    t_req_str <- format_ISO8601(t_req, usetz = "Z")
    if (verbose) 
        message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
    ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
        ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
        0), nc)
    unlink(ncs0)
    nc_retry <- T
    nc_n_try <- 1
    n_max_retries
    while (nc_retry) {
        res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
            url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
                bbox[["xmax"]]), latitude = c(bbox[["ymin"]], 
                bbox[["ymax"]]), time = t_req_str, fmt = "nc", 
            store = rerddap::disk(path = dir_nc)))
        if (inherits(res, "try-error")) {
            err <- attr(res, "condition")
            msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
            nc_n_try <- nc_n_try + 1
            if (nc_n_try > n_max_retries) {
                stop(msg)
            }
            else {
                message(msg, "\nRETRYing...")
                Sys.sleep(1)
            }
        }
        else {
            nc_retry <- F
        }
    }
    i_req <- i_req + 1
}
debug: i_t_beg <- (i_req - 1) * n_t_per_req + 1
debug: i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
debug: t_req <- times_todo[c(i_t_beg, i_t_end)]
debug: t_req_str <- format_ISO8601(t_req, usetz = "Z")
debug: if (verbose) message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
debug: message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
Fetching request 1 of 1 (2022-01-01 to 2022-12-01) ~ 19:32:47 UTC
debug: ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
    0), nc)
debug: unlink(ncs0)
debug: nc_retry <- T
debug: nc_n_try <- 1
debug: n_max_retries
debug: while (nc_retry) {
    res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
        url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
            bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
        time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
    if (inherits(res, "try-error")) {
        err <- attr(res, "condition")
        msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
        nc_n_try <- nc_n_try + 1
        if (nc_n_try > n_max_retries) {
            stop(msg)
        }
        else {
            message(msg, "\nRETRYing...")
            Sys.sleep(1)
        }
    }
    else {
        nc_retry <- F
    }
}
debug: res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
    url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
        bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
    time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
debug: if (inherits(res, "try-error")) {
    err <- attr(res, "condition")
    msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
    nc_n_try <- nc_n_try + 1
    if (nc_n_try > n_max_retries) {
        stop(msg)
    }
    else {
        message(msg, "\nRETRYing...")
        Sys.sleep(1)
    }
} else {
    nc_retry <- F
}
debug: nc_retry <- F
debug: (while) nc_retry
debug: i_req <- i_req + 1
debug: (while) i_req <= n_reqs
debug: ncs <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size > 
    0), nc)
debug: r <- terra::rast(ncs)
debug: stopifnot(all(class(terra::time(r)) %in% c("POSIXct", "POSIXt")))
debug: idx <- dplyr::pull(dplyr::filter(dplyr::arrange(dplyr::tibble(idx = 1:terra::nlyr(r), 
    time = terra::time(r)), time), !duplicated(time)), idx)
debug: r <- terra::subset(r, idx)
debug: stopifnot(terra::crs(r, proj = T) == wgs84)
debug: if (mask_tif) r <- terra::mask(r, sf_zones)
debug: lyrs <- glue("{var}|{terra::time(r)}")
debug: if (length(dims_other) > 0 && !all(length(dims[dims_other]) == 
    1)) stop(glue("Other dimensions not yet supported: {paste(dims_other, collapse = ',')}"))
debug: names(r) <- lyrs
debug: if (!is.null(rast_tif)) {
    if (fs::file_exists(rast_tif)) {
        r_tmp_tif <- tempfile(fileext = ".tif")
        r_tmp <- c(rast(rast_tif), r)
        r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
        terra::writeRaster(r_tmp, r_tmp_tif)
        fs::file_delete(rast_tif)
        fs::file_move(r_tmp_tif, rast_tif)
        rm(r)
        rm(r_tmp)
    }
    else {
        terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
    }
    r <- terra::rast(rast_tif)
}
debug: if (fs::file_exists(rast_tif)) {
    r_tmp_tif <- tempfile(fileext = ".tif")
    r_tmp <- c(rast(rast_tif), r)
    r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
    terra::writeRaster(r_tmp, r_tmp_tif)
    fs::file_delete(rast_tif)
    fs::file_move(r_tmp_tif, rast_tif)
    rm(r)
    rm(r_tmp)
} else {
    terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
}
debug: terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
debug: r <- terra::rast(rast_tif)
debug: d_r <- mutate(tidyr::pivot_longer(sf::st_drop_geometry(sf::st_as_sf(terra::zonal(x = r, 
    z = terra::vect(dplyr::select(sf_zones, dplyr::all_of(fld_zones))), 
    fun = zonal_fun, exact = T, na.rm = T, as.polygons = T))), 
    cols = -dplyr::any_of(fld_zones), names_to = "lyr", values_to = zonal_fun), 
    time = readr::parse_datetime(str_replace(lyr, glue("{var}\\|(.*)"), 
        "\\1")))
debug: if (!is.null(zonal_csv)) write_csv(d_r, zonal_csv)
debug: write_csv(d_r, zonal_csv)
debug: if (!keep_nc) unlink(dir_nc, recursive = T)
debug: unlink(dir_nc, recursive = T)
debug: return(d_r)
Downloading 1 requests, up to 240 time slices each
Called from: extractr::ed_extract(ed, var = v, sf_zones = ply, bbox = bb, 
    mask_tif = F, rast_tif = glue("{dir_out}/{nms}/{yr}.tif"), 
    zonal_fun = "mean", zonal_csv = glue("{dir_out}/{nms}/{yr}.csv"), 
    dir_nc = glue("{dir_out}/{nms}/{yr}_nc"), keep_nc = F, n_max_vals_per_req = 1e+05, 
    time_min = time_min, time_max = time_max, verbose = T)
debug: while (i_req <= n_reqs) {
    i_t_beg <- (i_req - 1) * n_t_per_req + 1
    i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
    t_req <- times_todo[c(i_t_beg, i_t_end)]
    t_req_str <- format_ISO8601(t_req, usetz = "Z")
    if (verbose) 
        message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
    ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
        ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
        0), nc)
    unlink(ncs0)
    nc_retry <- T
    nc_n_try <- 1
    n_max_retries
    while (nc_retry) {
        res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
            url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
                bbox[["xmax"]]), latitude = c(bbox[["ymin"]], 
                bbox[["ymax"]]), time = t_req_str, fmt = "nc", 
            store = rerddap::disk(path = dir_nc)))
        if (inherits(res, "try-error")) {
            err <- attr(res, "condition")
            msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
            nc_n_try <- nc_n_try + 1
            if (nc_n_try > n_max_retries) {
                stop(msg)
            }
            else {
                message(msg, "\nRETRYing...")
                Sys.sleep(1)
            }
        }
        else {
            nc_retry <- F
        }
    }
    i_req <- i_req + 1
}
debug: i_t_beg <- (i_req - 1) * n_t_per_req + 1
debug: i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
debug: t_req <- times_todo[c(i_t_beg, i_t_end)]
debug: t_req_str <- format_ISO8601(t_req, usetz = "Z")
debug: if (verbose) message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
debug: message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
Fetching request 1 of 1 (2023-01-01 to 2023-12-01) ~ 19:32:49 UTC
debug: ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
    0), nc)
debug: unlink(ncs0)
debug: nc_retry <- T
debug: nc_n_try <- 1
debug: n_max_retries
debug: while (nc_retry) {
    res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
        url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
            bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
        time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
    if (inherits(res, "try-error")) {
        err <- attr(res, "condition")
        msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
        nc_n_try <- nc_n_try + 1
        if (nc_n_try > n_max_retries) {
            stop(msg)
        }
        else {
            message(msg, "\nRETRYing...")
            Sys.sleep(1)
        }
    }
    else {
        nc_retry <- F
    }
}
debug: res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
    url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
        bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
    time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
debug: if (inherits(res, "try-error")) {
    err <- attr(res, "condition")
    msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
    nc_n_try <- nc_n_try + 1
    if (nc_n_try > n_max_retries) {
        stop(msg)
    }
    else {
        message(msg, "\nRETRYing...")
        Sys.sleep(1)
    }
} else {
    nc_retry <- F
}
debug: nc_retry <- F
debug: (while) nc_retry
debug: i_req <- i_req + 1
debug: (while) i_req <= n_reqs
debug: ncs <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size > 
    0), nc)
debug: r <- terra::rast(ncs)
debug: stopifnot(all(class(terra::time(r)) %in% c("POSIXct", "POSIXt")))
debug: idx <- dplyr::pull(dplyr::filter(dplyr::arrange(dplyr::tibble(idx = 1:terra::nlyr(r), 
    time = terra::time(r)), time), !duplicated(time)), idx)
debug: r <- terra::subset(r, idx)
debug: stopifnot(terra::crs(r, proj = T) == wgs84)
debug: if (mask_tif) r <- terra::mask(r, sf_zones)
debug: lyrs <- glue("{var}|{terra::time(r)}")
debug: if (length(dims_other) > 0 && !all(length(dims[dims_other]) == 
    1)) stop(glue("Other dimensions not yet supported: {paste(dims_other, collapse = ',')}"))
debug: names(r) <- lyrs
debug: if (!is.null(rast_tif)) {
    if (fs::file_exists(rast_tif)) {
        r_tmp_tif <- tempfile(fileext = ".tif")
        r_tmp <- c(rast(rast_tif), r)
        r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
        terra::writeRaster(r_tmp, r_tmp_tif)
        fs::file_delete(rast_tif)
        fs::file_move(r_tmp_tif, rast_tif)
        rm(r)
        rm(r_tmp)
    }
    else {
        terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
    }
    r <- terra::rast(rast_tif)
}
debug: if (fs::file_exists(rast_tif)) {
    r_tmp_tif <- tempfile(fileext = ".tif")
    r_tmp <- c(rast(rast_tif), r)
    r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
    terra::writeRaster(r_tmp, r_tmp_tif)
    fs::file_delete(rast_tif)
    fs::file_move(r_tmp_tif, rast_tif)
    rm(r)
    rm(r_tmp)
} else {
    terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
}
debug: terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
debug: r <- terra::rast(rast_tif)
debug: d_r <- mutate(tidyr::pivot_longer(sf::st_drop_geometry(sf::st_as_sf(terra::zonal(x = r, 
    z = terra::vect(dplyr::select(sf_zones, dplyr::all_of(fld_zones))), 
    fun = zonal_fun, exact = T, na.rm = T, as.polygons = T))), 
    cols = -dplyr::any_of(fld_zones), names_to = "lyr", values_to = zonal_fun), 
    time = readr::parse_datetime(str_replace(lyr, glue("{var}\\|(.*)"), 
        "\\1")))
debug: if (!is.null(zonal_csv)) write_csv(d_r, zonal_csv)
debug: write_csv(d_r, zonal_csv)
debug: if (!keep_nc) unlink(dir_nc, recursive = T)
debug: unlink(dir_nc, recursive = T)
debug: return(d_r)
Downloading 1 requests, up to 240 time slices each
Called from: extractr::ed_extract(ed, var = v, sf_zones = ply, bbox = bb, 
    mask_tif = F, rast_tif = glue("{dir_out}/{nms}/{yr}.tif"), 
    zonal_fun = "mean", zonal_csv = glue("{dir_out}/{nms}/{yr}.csv"), 
    dir_nc = glue("{dir_out}/{nms}/{yr}_nc"), keep_nc = F, n_max_vals_per_req = 1e+05, 
    time_min = time_min, time_max = time_max, verbose = T)
debug: while (i_req <= n_reqs) {
    i_t_beg <- (i_req - 1) * n_t_per_req + 1
    i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
    t_req <- times_todo[c(i_t_beg, i_t_end)]
    t_req_str <- format_ISO8601(t_req, usetz = "Z")
    if (verbose) 
        message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
    ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
        ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
        0), nc)
    unlink(ncs0)
    nc_retry <- T
    nc_n_try <- 1
    n_max_retries
    while (nc_retry) {
        res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
            url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
                bbox[["xmax"]]), latitude = c(bbox[["ymin"]], 
                bbox[["ymax"]]), time = t_req_str, fmt = "nc", 
            store = rerddap::disk(path = dir_nc)))
        if (inherits(res, "try-error")) {
            err <- attr(res, "condition")
            msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
            nc_n_try <- nc_n_try + 1
            if (nc_n_try > n_max_retries) {
                stop(msg)
            }
            else {
                message(msg, "\nRETRYing...")
                Sys.sleep(1)
            }
        }
        else {
            nc_retry <- F
        }
    }
    i_req <- i_req + 1
}
debug: i_t_beg <- (i_req - 1) * n_t_per_req + 1
debug: i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
debug: t_req <- times_todo[c(i_t_beg, i_t_end)]
debug: t_req_str <- format_ISO8601(t_req, usetz = "Z")
debug: if (verbose) message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
debug: message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
Fetching request 1 of 1 (2024-01-01 to 2024-12-01) ~ 19:32:52 UTC
debug: ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
    0), nc)
debug: unlink(ncs0)
debug: nc_retry <- T
debug: nc_n_try <- 1
debug: n_max_retries
debug: while (nc_retry) {
    res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
        url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
            bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
        time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
    if (inherits(res, "try-error")) {
        err <- attr(res, "condition")
        msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
        nc_n_try <- nc_n_try + 1
        if (nc_n_try > n_max_retries) {
            stop(msg)
        }
        else {
            message(msg, "\nRETRYing...")
            Sys.sleep(1)
        }
    }
    else {
        nc_retry <- F
    }
}
debug: res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
    url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
        bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
    time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
debug: if (inherits(res, "try-error")) {
    err <- attr(res, "condition")
    msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
    nc_n_try <- nc_n_try + 1
    if (nc_n_try > n_max_retries) {
        stop(msg)
    }
    else {
        message(msg, "\nRETRYing...")
        Sys.sleep(1)
    }
} else {
    nc_retry <- F
}
debug: nc_retry <- F
debug: (while) nc_retry
debug: i_req <- i_req + 1
debug: (while) i_req <= n_reqs
debug: ncs <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size > 
    0), nc)
debug: r <- terra::rast(ncs)
debug: stopifnot(all(class(terra::time(r)) %in% c("POSIXct", "POSIXt")))
debug: idx <- dplyr::pull(dplyr::filter(dplyr::arrange(dplyr::tibble(idx = 1:terra::nlyr(r), 
    time = terra::time(r)), time), !duplicated(time)), idx)
debug: r <- terra::subset(r, idx)
debug: stopifnot(terra::crs(r, proj = T) == wgs84)
debug: if (mask_tif) r <- terra::mask(r, sf_zones)
debug: lyrs <- glue("{var}|{terra::time(r)}")
debug: if (length(dims_other) > 0 && !all(length(dims[dims_other]) == 
    1)) stop(glue("Other dimensions not yet supported: {paste(dims_other, collapse = ',')}"))
debug: names(r) <- lyrs
debug: if (!is.null(rast_tif)) {
    if (fs::file_exists(rast_tif)) {
        r_tmp_tif <- tempfile(fileext = ".tif")
        r_tmp <- c(rast(rast_tif), r)
        r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
        terra::writeRaster(r_tmp, r_tmp_tif)
        fs::file_delete(rast_tif)
        fs::file_move(r_tmp_tif, rast_tif)
        rm(r)
        rm(r_tmp)
    }
    else {
        terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
    }
    r <- terra::rast(rast_tif)
}
debug: if (fs::file_exists(rast_tif)) {
    r_tmp_tif <- tempfile(fileext = ".tif")
    r_tmp <- c(rast(rast_tif), r)
    r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
    terra::writeRaster(r_tmp, r_tmp_tif)
    fs::file_delete(rast_tif)
    fs::file_move(r_tmp_tif, rast_tif)
    rm(r)
    rm(r_tmp)
} else {
    terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
}
debug: terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
debug: r <- terra::rast(rast_tif)
debug: d_r <- mutate(tidyr::pivot_longer(sf::st_drop_geometry(sf::st_as_sf(terra::zonal(x = r, 
    z = terra::vect(dplyr::select(sf_zones, dplyr::all_of(fld_zones))), 
    fun = zonal_fun, exact = T, na.rm = T, as.polygons = T))), 
    cols = -dplyr::any_of(fld_zones), names_to = "lyr", values_to = zonal_fun), 
    time = readr::parse_datetime(str_replace(lyr, glue("{var}\\|(.*)"), 
        "\\1")))
debug: if (!is.null(zonal_csv)) write_csv(d_r, zonal_csv)
debug: write_csv(d_r, zonal_csv)
debug: if (!keep_nc) unlink(dir_nc, recursive = T)
debug: unlink(dir_nc, recursive = T)
debug: return(d_r)
Downloading 1 requests, up to 240 time slices each
Called from: extractr::ed_extract(ed, var = v, sf_zones = ply, bbox = bb, 
    mask_tif = F, rast_tif = glue("{dir_out}/{nms}/{yr}.tif"), 
    zonal_fun = "mean", zonal_csv = glue("{dir_out}/{nms}/{yr}.csv"), 
    dir_nc = glue("{dir_out}/{nms}/{yr}_nc"), keep_nc = F, n_max_vals_per_req = 1e+05, 
    time_min = time_min, time_max = time_max, verbose = T)
debug: while (i_req <= n_reqs) {
    i_t_beg <- (i_req - 1) * n_t_per_req + 1
    i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
    t_req <- times_todo[c(i_t_beg, i_t_end)]
    t_req_str <- format_ISO8601(t_req, usetz = "Z")
    if (verbose) 
        message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
    ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
        ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
        0), nc)
    unlink(ncs0)
    nc_retry <- T
    nc_n_try <- 1
    n_max_retries
    while (nc_retry) {
        res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
            url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
                bbox[["xmax"]]), latitude = c(bbox[["ymin"]], 
                bbox[["ymax"]]), time = t_req_str, fmt = "nc", 
            store = rerddap::disk(path = dir_nc)))
        if (inherits(res, "try-error")) {
            err <- attr(res, "condition")
            msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
            nc_n_try <- nc_n_try + 1
            if (nc_n_try > n_max_retries) {
                stop(msg)
            }
            else {
                message(msg, "\nRETRYing...")
                Sys.sleep(1)
            }
        }
        else {
            nc_retry <- F
        }
    }
    i_req <- i_req + 1
}
debug: i_t_beg <- (i_req - 1) * n_t_per_req + 1
debug: i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
debug: t_req <- times_todo[c(i_t_beg, i_t_end)]
debug: t_req_str <- format_ISO8601(t_req, usetz = "Z")
debug: if (verbose) message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
debug: message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
Fetching request 1 of 1 (2025-01-01 to 2025-07-01) ~ 19:32:54 UTC
debug: ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
    0), nc)
debug: unlink(ncs0)
debug: nc_retry <- T
debug: nc_n_try <- 1
debug: n_max_retries
debug: while (nc_retry) {
    res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
        url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
            bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
        time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
    if (inherits(res, "try-error")) {
        err <- attr(res, "condition")
        msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
        nc_n_try <- nc_n_try + 1
        if (nc_n_try > n_max_retries) {
            stop(msg)
        }
        else {
            message(msg, "\nRETRYing...")
            Sys.sleep(1)
        }
    }
    else {
        nc_retry <- F
    }
}
debug: res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
    url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
        bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
    time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
debug: if (inherits(res, "try-error")) {
    err <- attr(res, "condition")
    msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
    nc_n_try <- nc_n_try + 1
    if (nc_n_try > n_max_retries) {
        stop(msg)
    }
    else {
        message(msg, "\nRETRYing...")
        Sys.sleep(1)
    }
} else {
    nc_retry <- F
}
debug: nc_retry <- F
debug: (while) nc_retry
debug: i_req <- i_req + 1
debug: (while) i_req <= n_reqs
debug: ncs <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size > 
    0), nc)
debug: r <- terra::rast(ncs)
debug: stopifnot(all(class(terra::time(r)) %in% c("POSIXct", "POSIXt")))
debug: idx <- dplyr::pull(dplyr::filter(dplyr::arrange(dplyr::tibble(idx = 1:terra::nlyr(r), 
    time = terra::time(r)), time), !duplicated(time)), idx)
debug: r <- terra::subset(r, idx)
debug: stopifnot(terra::crs(r, proj = T) == wgs84)
debug: if (mask_tif) r <- terra::mask(r, sf_zones)
debug: lyrs <- glue("{var}|{terra::time(r)}")
debug: if (length(dims_other) > 0 && !all(length(dims[dims_other]) == 
    1)) stop(glue("Other dimensions not yet supported: {paste(dims_other, collapse = ',')}"))
debug: names(r) <- lyrs
debug: if (!is.null(rast_tif)) {
    if (fs::file_exists(rast_tif)) {
        r_tmp_tif <- tempfile(fileext = ".tif")
        r_tmp <- c(rast(rast_tif), r)
        r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
        terra::writeRaster(r_tmp, r_tmp_tif)
        fs::file_delete(rast_tif)
        fs::file_move(r_tmp_tif, rast_tif)
        rm(r)
        rm(r_tmp)
    }
    else {
        terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
    }
    r <- terra::rast(rast_tif)
}
debug: if (fs::file_exists(rast_tif)) {
    r_tmp_tif <- tempfile(fileext = ".tif")
    r_tmp <- c(rast(rast_tif), r)
    r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
    terra::writeRaster(r_tmp, r_tmp_tif)
    fs::file_delete(rast_tif)
    fs::file_move(r_tmp_tif, rast_tif)
    rm(r)
    rm(r_tmp)
} else {
    terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
}
debug: terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
debug: r <- terra::rast(rast_tif)
debug: d_r <- mutate(tidyr::pivot_longer(sf::st_drop_geometry(sf::st_as_sf(terra::zonal(x = r, 
    z = terra::vect(dplyr::select(sf_zones, dplyr::all_of(fld_zones))), 
    fun = zonal_fun, exact = T, na.rm = T, as.polygons = T))), 
    cols = -dplyr::any_of(fld_zones), names_to = "lyr", values_to = zonal_fun), 
    time = readr::parse_datetime(str_replace(lyr, glue("{var}\\|(.*)"), 
        "\\1")))
debug: if (!is.null(zonal_csv)) write_csv(d_r, zonal_csv)
debug: write_csv(d_r, zonal_csv)
debug: if (!keep_nc) unlink(dir_nc, recursive = T)
debug: unlink(dir_nc, recursive = T)
debug: return(d_r)
Downloading 1 requests, up to 148 time slices each
Called from: extractr::ed_extract(ed, var = v, sf_zones = ply, bbox = bb, 
    mask_tif = F, rast_tif = glue("{dir_out}/{nms}/{yr}.tif"), 
    zonal_fun = "mean", zonal_csv = glue("{dir_out}/{nms}/{yr}.csv"), 
    dir_nc = glue("{dir_out}/{nms}/{yr}_nc"), keep_nc = F, n_max_vals_per_req = 1e+05, 
    time_min = time_min, time_max = time_max, verbose = T)
debug: while (i_req <= n_reqs) {
    i_t_beg <- (i_req - 1) * n_t_per_req + 1
    i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
    t_req <- times_todo[c(i_t_beg, i_t_end)]
    t_req_str <- format_ISO8601(t_req, usetz = "Z")
    if (verbose) 
        message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
    ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
        ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
        0), nc)
    unlink(ncs0)
    nc_retry <- T
    nc_n_try <- 1
    n_max_retries
    while (nc_retry) {
        res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
            url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
                bbox[["xmax"]]), latitude = c(bbox[["ymin"]], 
                bbox[["ymax"]]), time = t_req_str, fmt = "nc", 
            store = rerddap::disk(path = dir_nc)))
        if (inherits(res, "try-error")) {
            err <- attr(res, "condition")
            msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
            nc_n_try <- nc_n_try + 1
            if (nc_n_try > n_max_retries) {
                stop(msg)
            }
            else {
                message(msg, "\nRETRYing...")
                Sys.sleep(1)
            }
        }
        else {
            nc_retry <- F
        }
    }
    i_req <- i_req + 1
}
debug: i_t_beg <- (i_req - 1) * n_t_per_req + 1
debug: i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
debug: t_req <- times_todo[c(i_t_beg, i_t_end)]
debug: t_req_str <- format_ISO8601(t_req, usetz = "Z")
debug: if (verbose) message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
debug: message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
Fetching request 1 of 1 (1998-01-01 to 1998-12-01) ~ 19:32:55 UTC
debug: ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
    0), nc)
debug: unlink(ncs0)
debug: nc_retry <- T
debug: nc_n_try <- 1
debug: n_max_retries
debug: while (nc_retry) {
    res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
        url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
            bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
        time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
    if (inherits(res, "try-error")) {
        err <- attr(res, "condition")
        msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
        nc_n_try <- nc_n_try + 1
        if (nc_n_try > n_max_retries) {
            stop(msg)
        }
        else {
            message(msg, "\nRETRYing...")
            Sys.sleep(1)
        }
    }
    else {
        nc_retry <- F
    }
}
debug: res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
    url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
        bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
    time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
debug: if (inherits(res, "try-error")) {
    err <- attr(res, "condition")
    msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
    nc_n_try <- nc_n_try + 1
    if (nc_n_try > n_max_retries) {
        stop(msg)
    }
    else {
        message(msg, "\nRETRYing...")
        Sys.sleep(1)
    }
} else {
    nc_retry <- F
}
debug: nc_retry <- F
debug: (while) nc_retry
debug: i_req <- i_req + 1
debug: (while) i_req <= n_reqs
debug: ncs <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size > 
    0), nc)
debug: r <- terra::rast(ncs)
debug: stopifnot(all(class(terra::time(r)) %in% c("POSIXct", "POSIXt")))
debug: idx <- dplyr::pull(dplyr::filter(dplyr::arrange(dplyr::tibble(idx = 1:terra::nlyr(r), 
    time = terra::time(r)), time), !duplicated(time)), idx)
debug: r <- terra::subset(r, idx)
debug: stopifnot(terra::crs(r, proj = T) == wgs84)
debug: if (mask_tif) r <- terra::mask(r, sf_zones)
debug: lyrs <- glue("{var}|{terra::time(r)}")
debug: if (length(dims_other) > 0 && !all(length(dims[dims_other]) == 
    1)) stop(glue("Other dimensions not yet supported: {paste(dims_other, collapse = ',')}"))
debug: names(r) <- lyrs
debug: if (!is.null(rast_tif)) {
    if (fs::file_exists(rast_tif)) {
        r_tmp_tif <- tempfile(fileext = ".tif")
        r_tmp <- c(rast(rast_tif), r)
        r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
        terra::writeRaster(r_tmp, r_tmp_tif)
        fs::file_delete(rast_tif)
        fs::file_move(r_tmp_tif, rast_tif)
        rm(r)
        rm(r_tmp)
    }
    else {
        terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
    }
    r <- terra::rast(rast_tif)
}
debug: if (fs::file_exists(rast_tif)) {
    r_tmp_tif <- tempfile(fileext = ".tif")
    r_tmp <- c(rast(rast_tif), r)
    r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
    terra::writeRaster(r_tmp, r_tmp_tif)
    fs::file_delete(rast_tif)
    fs::file_move(r_tmp_tif, rast_tif)
    rm(r)
    rm(r_tmp)
} else {
    terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
}
debug: terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
debug: r <- terra::rast(rast_tif)
debug: d_r <- mutate(tidyr::pivot_longer(sf::st_drop_geometry(sf::st_as_sf(terra::zonal(x = r, 
    z = terra::vect(dplyr::select(sf_zones, dplyr::all_of(fld_zones))), 
    fun = zonal_fun, exact = T, na.rm = T, as.polygons = T))), 
    cols = -dplyr::any_of(fld_zones), names_to = "lyr", values_to = zonal_fun), 
    time = readr::parse_datetime(str_replace(lyr, glue("{var}\\|(.*)"), 
        "\\1")))
debug: if (!is.null(zonal_csv)) write_csv(d_r, zonal_csv)
debug: write_csv(d_r, zonal_csv)
debug: if (!keep_nc) unlink(dir_nc, recursive = T)
debug: unlink(dir_nc, recursive = T)
debug: return(d_r)
Downloading 1 requests, up to 148 time slices each
Called from: extractr::ed_extract(ed, var = v, sf_zones = ply, bbox = bb, 
    mask_tif = F, rast_tif = glue("{dir_out}/{nms}/{yr}.tif"), 
    zonal_fun = "mean", zonal_csv = glue("{dir_out}/{nms}/{yr}.csv"), 
    dir_nc = glue("{dir_out}/{nms}/{yr}_nc"), keep_nc = F, n_max_vals_per_req = 1e+05, 
    time_min = time_min, time_max = time_max, verbose = T)
debug: while (i_req <= n_reqs) {
    i_t_beg <- (i_req - 1) * n_t_per_req + 1
    i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
    t_req <- times_todo[c(i_t_beg, i_t_end)]
    t_req_str <- format_ISO8601(t_req, usetz = "Z")
    if (verbose) 
        message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
    ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
        ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
        0), nc)
    unlink(ncs0)
    nc_retry <- T
    nc_n_try <- 1
    n_max_retries
    while (nc_retry) {
        res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
            url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
                bbox[["xmax"]]), latitude = c(bbox[["ymin"]], 
                bbox[["ymax"]]), time = t_req_str, fmt = "nc", 
            store = rerddap::disk(path = dir_nc)))
        if (inherits(res, "try-error")) {
            err <- attr(res, "condition")
            msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
            nc_n_try <- nc_n_try + 1
            if (nc_n_try > n_max_retries) {
                stop(msg)
            }
            else {
                message(msg, "\nRETRYing...")
                Sys.sleep(1)
            }
        }
        else {
            nc_retry <- F
        }
    }
    i_req <- i_req + 1
}
debug: i_t_beg <- (i_req - 1) * n_t_per_req + 1
debug: i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
debug: t_req <- times_todo[c(i_t_beg, i_t_end)]
debug: t_req_str <- format_ISO8601(t_req, usetz = "Z")
debug: if (verbose) message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
debug: message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
Fetching request 1 of 1 (1999-01-01 to 1999-12-01) ~ 19:32:58 UTC
debug: ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
    0), nc)
debug: unlink(ncs0)
debug: nc_retry <- T
debug: nc_n_try <- 1
debug: n_max_retries
debug: while (nc_retry) {
    res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
        url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
            bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
        time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
    if (inherits(res, "try-error")) {
        err <- attr(res, "condition")
        msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
        nc_n_try <- nc_n_try + 1
        if (nc_n_try > n_max_retries) {
            stop(msg)
        }
        else {
            message(msg, "\nRETRYing...")
            Sys.sleep(1)
        }
    }
    else {
        nc_retry <- F
    }
}
debug: res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
    url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
        bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
    time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
debug: if (inherits(res, "try-error")) {
    err <- attr(res, "condition")
    msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
    nc_n_try <- nc_n_try + 1
    if (nc_n_try > n_max_retries) {
        stop(msg)
    }
    else {
        message(msg, "\nRETRYing...")
        Sys.sleep(1)
    }
} else {
    nc_retry <- F
}
debug: nc_retry <- F
debug: (while) nc_retry
debug: i_req <- i_req + 1
debug: (while) i_req <= n_reqs
debug: ncs <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size > 
    0), nc)
debug: r <- terra::rast(ncs)
debug: stopifnot(all(class(terra::time(r)) %in% c("POSIXct", "POSIXt")))
debug: idx <- dplyr::pull(dplyr::filter(dplyr::arrange(dplyr::tibble(idx = 1:terra::nlyr(r), 
    time = terra::time(r)), time), !duplicated(time)), idx)
debug: r <- terra::subset(r, idx)
debug: stopifnot(terra::crs(r, proj = T) == wgs84)
debug: if (mask_tif) r <- terra::mask(r, sf_zones)
debug: lyrs <- glue("{var}|{terra::time(r)}")
debug: if (length(dims_other) > 0 && !all(length(dims[dims_other]) == 
    1)) stop(glue("Other dimensions not yet supported: {paste(dims_other, collapse = ',')}"))
debug: names(r) <- lyrs
debug: if (!is.null(rast_tif)) {
    if (fs::file_exists(rast_tif)) {
        r_tmp_tif <- tempfile(fileext = ".tif")
        r_tmp <- c(rast(rast_tif), r)
        r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
        terra::writeRaster(r_tmp, r_tmp_tif)
        fs::file_delete(rast_tif)
        fs::file_move(r_tmp_tif, rast_tif)
        rm(r)
        rm(r_tmp)
    }
    else {
        terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
    }
    r <- terra::rast(rast_tif)
}
debug: if (fs::file_exists(rast_tif)) {
    r_tmp_tif <- tempfile(fileext = ".tif")
    r_tmp <- c(rast(rast_tif), r)
    r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
    terra::writeRaster(r_tmp, r_tmp_tif)
    fs::file_delete(rast_tif)
    fs::file_move(r_tmp_tif, rast_tif)
    rm(r)
    rm(r_tmp)
} else {
    terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
}
debug: terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
debug: r <- terra::rast(rast_tif)
debug: d_r <- mutate(tidyr::pivot_longer(sf::st_drop_geometry(sf::st_as_sf(terra::zonal(x = r, 
    z = terra::vect(dplyr::select(sf_zones, dplyr::all_of(fld_zones))), 
    fun = zonal_fun, exact = T, na.rm = T, as.polygons = T))), 
    cols = -dplyr::any_of(fld_zones), names_to = "lyr", values_to = zonal_fun), 
    time = readr::parse_datetime(str_replace(lyr, glue("{var}\\|(.*)"), 
        "\\1")))
debug: if (!is.null(zonal_csv)) write_csv(d_r, zonal_csv)
debug: write_csv(d_r, zonal_csv)
debug: if (!keep_nc) unlink(dir_nc, recursive = T)
debug: unlink(dir_nc, recursive = T)
debug: return(d_r)
Downloading 1 requests, up to 148 time slices each
Called from: extractr::ed_extract(ed, var = v, sf_zones = ply, bbox = bb, 
    mask_tif = F, rast_tif = glue("{dir_out}/{nms}/{yr}.tif"), 
    zonal_fun = "mean", zonal_csv = glue("{dir_out}/{nms}/{yr}.csv"), 
    dir_nc = glue("{dir_out}/{nms}/{yr}_nc"), keep_nc = F, n_max_vals_per_req = 1e+05, 
    time_min = time_min, time_max = time_max, verbose = T)
debug: while (i_req <= n_reqs) {
    i_t_beg <- (i_req - 1) * n_t_per_req + 1
    i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
    t_req <- times_todo[c(i_t_beg, i_t_end)]
    t_req_str <- format_ISO8601(t_req, usetz = "Z")
    if (verbose) 
        message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
    ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
        ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
        0), nc)
    unlink(ncs0)
    nc_retry <- T
    nc_n_try <- 1
    n_max_retries
    while (nc_retry) {
        res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
            url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
                bbox[["xmax"]]), latitude = c(bbox[["ymin"]], 
                bbox[["ymax"]]), time = t_req_str, fmt = "nc", 
            store = rerddap::disk(path = dir_nc)))
        if (inherits(res, "try-error")) {
            err <- attr(res, "condition")
            msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
            nc_n_try <- nc_n_try + 1
            if (nc_n_try > n_max_retries) {
                stop(msg)
            }
            else {
                message(msg, "\nRETRYing...")
                Sys.sleep(1)
            }
        }
        else {
            nc_retry <- F
        }
    }
    i_req <- i_req + 1
}
debug: i_t_beg <- (i_req - 1) * n_t_per_req + 1
debug: i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
debug: t_req <- times_todo[c(i_t_beg, i_t_end)]
debug: t_req_str <- format_ISO8601(t_req, usetz = "Z")
debug: if (verbose) message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
debug: message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
Fetching request 1 of 1 (2000-01-01 to 2000-12-01) ~ 19:33:02 UTC
debug: ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
    0), nc)
debug: unlink(ncs0)
debug: nc_retry <- T
debug: nc_n_try <- 1
debug: n_max_retries
debug: while (nc_retry) {
    res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
        url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
            bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
        time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
    if (inherits(res, "try-error")) {
        err <- attr(res, "condition")
        msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
        nc_n_try <- nc_n_try + 1
        if (nc_n_try > n_max_retries) {
            stop(msg)
        }
        else {
            message(msg, "\nRETRYing...")
            Sys.sleep(1)
        }
    }
    else {
        nc_retry <- F
    }
}
debug: res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
    url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
        bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
    time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
debug: if (inherits(res, "try-error")) {
    err <- attr(res, "condition")
    msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
    nc_n_try <- nc_n_try + 1
    if (nc_n_try > n_max_retries) {
        stop(msg)
    }
    else {
        message(msg, "\nRETRYing...")
        Sys.sleep(1)
    }
} else {
    nc_retry <- F
}
debug: nc_retry <- F
debug: (while) nc_retry
debug: i_req <- i_req + 1
debug: (while) i_req <= n_reqs
debug: ncs <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size > 
    0), nc)
debug: r <- terra::rast(ncs)
debug: stopifnot(all(class(terra::time(r)) %in% c("POSIXct", "POSIXt")))
debug: idx <- dplyr::pull(dplyr::filter(dplyr::arrange(dplyr::tibble(idx = 1:terra::nlyr(r), 
    time = terra::time(r)), time), !duplicated(time)), idx)
debug: r <- terra::subset(r, idx)
debug: stopifnot(terra::crs(r, proj = T) == wgs84)
debug: if (mask_tif) r <- terra::mask(r, sf_zones)
debug: lyrs <- glue("{var}|{terra::time(r)}")
debug: if (length(dims_other) > 0 && !all(length(dims[dims_other]) == 
    1)) stop(glue("Other dimensions not yet supported: {paste(dims_other, collapse = ',')}"))
debug: names(r) <- lyrs
debug: if (!is.null(rast_tif)) {
    if (fs::file_exists(rast_tif)) {
        r_tmp_tif <- tempfile(fileext = ".tif")
        r_tmp <- c(rast(rast_tif), r)
        r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
        terra::writeRaster(r_tmp, r_tmp_tif)
        fs::file_delete(rast_tif)
        fs::file_move(r_tmp_tif, rast_tif)
        rm(r)
        rm(r_tmp)
    }
    else {
        terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
    }
    r <- terra::rast(rast_tif)
}
debug: if (fs::file_exists(rast_tif)) {
    r_tmp_tif <- tempfile(fileext = ".tif")
    r_tmp <- c(rast(rast_tif), r)
    r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
    terra::writeRaster(r_tmp, r_tmp_tif)
    fs::file_delete(rast_tif)
    fs::file_move(r_tmp_tif, rast_tif)
    rm(r)
    rm(r_tmp)
} else {
    terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
}
debug: terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
debug: r <- terra::rast(rast_tif)
debug: d_r <- mutate(tidyr::pivot_longer(sf::st_drop_geometry(sf::st_as_sf(terra::zonal(x = r, 
    z = terra::vect(dplyr::select(sf_zones, dplyr::all_of(fld_zones))), 
    fun = zonal_fun, exact = T, na.rm = T, as.polygons = T))), 
    cols = -dplyr::any_of(fld_zones), names_to = "lyr", values_to = zonal_fun), 
    time = readr::parse_datetime(str_replace(lyr, glue("{var}\\|(.*)"), 
        "\\1")))
debug: if (!is.null(zonal_csv)) write_csv(d_r, zonal_csv)
debug: write_csv(d_r, zonal_csv)
debug: if (!keep_nc) unlink(dir_nc, recursive = T)
debug: unlink(dir_nc, recursive = T)
debug: return(d_r)
Downloading 1 requests, up to 148 time slices each
Called from: extractr::ed_extract(ed, var = v, sf_zones = ply, bbox = bb, 
    mask_tif = F, rast_tif = glue("{dir_out}/{nms}/{yr}.tif"), 
    zonal_fun = "mean", zonal_csv = glue("{dir_out}/{nms}/{yr}.csv"), 
    dir_nc = glue("{dir_out}/{nms}/{yr}_nc"), keep_nc = F, n_max_vals_per_req = 1e+05, 
    time_min = time_min, time_max = time_max, verbose = T)
debug: while (i_req <= n_reqs) {
    i_t_beg <- (i_req - 1) * n_t_per_req + 1
    i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
    t_req <- times_todo[c(i_t_beg, i_t_end)]
    t_req_str <- format_ISO8601(t_req, usetz = "Z")
    if (verbose) 
        message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
    ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
        ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
        0), nc)
    unlink(ncs0)
    nc_retry <- T
    nc_n_try <- 1
    n_max_retries
    while (nc_retry) {
        res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
            url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
                bbox[["xmax"]]), latitude = c(bbox[["ymin"]], 
                bbox[["ymax"]]), time = t_req_str, fmt = "nc", 
            store = rerddap::disk(path = dir_nc)))
        if (inherits(res, "try-error")) {
            err <- attr(res, "condition")
            msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
            nc_n_try <- nc_n_try + 1
            if (nc_n_try > n_max_retries) {
                stop(msg)
            }
            else {
                message(msg, "\nRETRYing...")
                Sys.sleep(1)
            }
        }
        else {
            nc_retry <- F
        }
    }
    i_req <- i_req + 1
}
debug: i_t_beg <- (i_req - 1) * n_t_per_req + 1
debug: i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
debug: t_req <- times_todo[c(i_t_beg, i_t_end)]
debug: t_req_str <- format_ISO8601(t_req, usetz = "Z")
debug: if (verbose) message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
debug: message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
Fetching request 1 of 1 (2001-01-01 to 2001-12-01) ~ 19:33:05 UTC
debug: ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
    0), nc)
debug: unlink(ncs0)
debug: nc_retry <- T
debug: nc_n_try <- 1
debug: n_max_retries
debug: while (nc_retry) {
    res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
        url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
            bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
        time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
    if (inherits(res, "try-error")) {
        err <- attr(res, "condition")
        msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
        nc_n_try <- nc_n_try + 1
        if (nc_n_try > n_max_retries) {
            stop(msg)
        }
        else {
            message(msg, "\nRETRYing...")
            Sys.sleep(1)
        }
    }
    else {
        nc_retry <- F
    }
}
debug: res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
    url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
        bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
    time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
debug: if (inherits(res, "try-error")) {
    err <- attr(res, "condition")
    msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
    nc_n_try <- nc_n_try + 1
    if (nc_n_try > n_max_retries) {
        stop(msg)
    }
    else {
        message(msg, "\nRETRYing...")
        Sys.sleep(1)
    }
} else {
    nc_retry <- F
}
debug: nc_retry <- F
debug: (while) nc_retry
debug: i_req <- i_req + 1
debug: (while) i_req <= n_reqs
debug: ncs <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size > 
    0), nc)
debug: r <- terra::rast(ncs)
debug: stopifnot(all(class(terra::time(r)) %in% c("POSIXct", "POSIXt")))
debug: idx <- dplyr::pull(dplyr::filter(dplyr::arrange(dplyr::tibble(idx = 1:terra::nlyr(r), 
    time = terra::time(r)), time), !duplicated(time)), idx)
debug: r <- terra::subset(r, idx)
debug: stopifnot(terra::crs(r, proj = T) == wgs84)
debug: if (mask_tif) r <- terra::mask(r, sf_zones)
debug: lyrs <- glue("{var}|{terra::time(r)}")
debug: if (length(dims_other) > 0 && !all(length(dims[dims_other]) == 
    1)) stop(glue("Other dimensions not yet supported: {paste(dims_other, collapse = ',')}"))
debug: names(r) <- lyrs
debug: if (!is.null(rast_tif)) {
    if (fs::file_exists(rast_tif)) {
        r_tmp_tif <- tempfile(fileext = ".tif")
        r_tmp <- c(rast(rast_tif), r)
        r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
        terra::writeRaster(r_tmp, r_tmp_tif)
        fs::file_delete(rast_tif)
        fs::file_move(r_tmp_tif, rast_tif)
        rm(r)
        rm(r_tmp)
    }
    else {
        terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
    }
    r <- terra::rast(rast_tif)
}
debug: if (fs::file_exists(rast_tif)) {
    r_tmp_tif <- tempfile(fileext = ".tif")
    r_tmp <- c(rast(rast_tif), r)
    r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
    terra::writeRaster(r_tmp, r_tmp_tif)
    fs::file_delete(rast_tif)
    fs::file_move(r_tmp_tif, rast_tif)
    rm(r)
    rm(r_tmp)
} else {
    terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
}
debug: terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
debug: r <- terra::rast(rast_tif)
debug: d_r <- mutate(tidyr::pivot_longer(sf::st_drop_geometry(sf::st_as_sf(terra::zonal(x = r, 
    z = terra::vect(dplyr::select(sf_zones, dplyr::all_of(fld_zones))), 
    fun = zonal_fun, exact = T, na.rm = T, as.polygons = T))), 
    cols = -dplyr::any_of(fld_zones), names_to = "lyr", values_to = zonal_fun), 
    time = readr::parse_datetime(str_replace(lyr, glue("{var}\\|(.*)"), 
        "\\1")))
debug: if (!is.null(zonal_csv)) write_csv(d_r, zonal_csv)
debug: write_csv(d_r, zonal_csv)
debug: if (!keep_nc) unlink(dir_nc, recursive = T)
debug: unlink(dir_nc, recursive = T)
debug: return(d_r)
Downloading 1 requests, up to 148 time slices each
Called from: extractr::ed_extract(ed, var = v, sf_zones = ply, bbox = bb, 
    mask_tif = F, rast_tif = glue("{dir_out}/{nms}/{yr}.tif"), 
    zonal_fun = "mean", zonal_csv = glue("{dir_out}/{nms}/{yr}.csv"), 
    dir_nc = glue("{dir_out}/{nms}/{yr}_nc"), keep_nc = F, n_max_vals_per_req = 1e+05, 
    time_min = time_min, time_max = time_max, verbose = T)
debug: while (i_req <= n_reqs) {
    i_t_beg <- (i_req - 1) * n_t_per_req + 1
    i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
    t_req <- times_todo[c(i_t_beg, i_t_end)]
    t_req_str <- format_ISO8601(t_req, usetz = "Z")
    if (verbose) 
        message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
    ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
        ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
        0), nc)
    unlink(ncs0)
    nc_retry <- T
    nc_n_try <- 1
    n_max_retries
    while (nc_retry) {
        res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
            url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
                bbox[["xmax"]]), latitude = c(bbox[["ymin"]], 
                bbox[["ymax"]]), time = t_req_str, fmt = "nc", 
            store = rerddap::disk(path = dir_nc)))
        if (inherits(res, "try-error")) {
            err <- attr(res, "condition")
            msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
            nc_n_try <- nc_n_try + 1
            if (nc_n_try > n_max_retries) {
                stop(msg)
            }
            else {
                message(msg, "\nRETRYing...")
                Sys.sleep(1)
            }
        }
        else {
            nc_retry <- F
        }
    }
    i_req <- i_req + 1
}
debug: i_t_beg <- (i_req - 1) * n_t_per_req + 1
debug: i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
debug: t_req <- times_todo[c(i_t_beg, i_t_end)]
debug: t_req_str <- format_ISO8601(t_req, usetz = "Z")
debug: if (verbose) message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
debug: message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
Fetching request 1 of 1 (2002-01-01 to 2002-12-01) ~ 19:33:09 UTC
debug: ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
    0), nc)
debug: unlink(ncs0)
debug: nc_retry <- T
debug: nc_n_try <- 1
debug: n_max_retries
debug: while (nc_retry) {
    res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
        url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
            bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
        time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
    if (inherits(res, "try-error")) {
        err <- attr(res, "condition")
        msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
        nc_n_try <- nc_n_try + 1
        if (nc_n_try > n_max_retries) {
            stop(msg)
        }
        else {
            message(msg, "\nRETRYing...")
            Sys.sleep(1)
        }
    }
    else {
        nc_retry <- F
    }
}
debug: res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
    url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
        bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
    time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
debug: if (inherits(res, "try-error")) {
    err <- attr(res, "condition")
    msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
    nc_n_try <- nc_n_try + 1
    if (nc_n_try > n_max_retries) {
        stop(msg)
    }
    else {
        message(msg, "\nRETRYing...")
        Sys.sleep(1)
    }
} else {
    nc_retry <- F
}
debug: nc_retry <- F
debug: (while) nc_retry
debug: i_req <- i_req + 1
debug: (while) i_req <= n_reqs
debug: ncs <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size > 
    0), nc)
debug: r <- terra::rast(ncs)
debug: stopifnot(all(class(terra::time(r)) %in% c("POSIXct", "POSIXt")))
debug: idx <- dplyr::pull(dplyr::filter(dplyr::arrange(dplyr::tibble(idx = 1:terra::nlyr(r), 
    time = terra::time(r)), time), !duplicated(time)), idx)
debug: r <- terra::subset(r, idx)
debug: stopifnot(terra::crs(r, proj = T) == wgs84)
debug: if (mask_tif) r <- terra::mask(r, sf_zones)
debug: lyrs <- glue("{var}|{terra::time(r)}")
debug: if (length(dims_other) > 0 && !all(length(dims[dims_other]) == 
    1)) stop(glue("Other dimensions not yet supported: {paste(dims_other, collapse = ',')}"))
debug: names(r) <- lyrs
debug: if (!is.null(rast_tif)) {
    if (fs::file_exists(rast_tif)) {
        r_tmp_tif <- tempfile(fileext = ".tif")
        r_tmp <- c(rast(rast_tif), r)
        r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
        terra::writeRaster(r_tmp, r_tmp_tif)
        fs::file_delete(rast_tif)
        fs::file_move(r_tmp_tif, rast_tif)
        rm(r)
        rm(r_tmp)
    }
    else {
        terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
    }
    r <- terra::rast(rast_tif)
}
debug: if (fs::file_exists(rast_tif)) {
    r_tmp_tif <- tempfile(fileext = ".tif")
    r_tmp <- c(rast(rast_tif), r)
    r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
    terra::writeRaster(r_tmp, r_tmp_tif)
    fs::file_delete(rast_tif)
    fs::file_move(r_tmp_tif, rast_tif)
    rm(r)
    rm(r_tmp)
} else {
    terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
}
debug: terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
debug: r <- terra::rast(rast_tif)
debug: d_r <- mutate(tidyr::pivot_longer(sf::st_drop_geometry(sf::st_as_sf(terra::zonal(x = r, 
    z = terra::vect(dplyr::select(sf_zones, dplyr::all_of(fld_zones))), 
    fun = zonal_fun, exact = T, na.rm = T, as.polygons = T))), 
    cols = -dplyr::any_of(fld_zones), names_to = "lyr", values_to = zonal_fun), 
    time = readr::parse_datetime(str_replace(lyr, glue("{var}\\|(.*)"), 
        "\\1")))
debug: if (!is.null(zonal_csv)) write_csv(d_r, zonal_csv)
debug: write_csv(d_r, zonal_csv)
debug: if (!keep_nc) unlink(dir_nc, recursive = T)
debug: unlink(dir_nc, recursive = T)
debug: return(d_r)
Downloading 1 requests, up to 148 time slices each
Called from: extractr::ed_extract(ed, var = v, sf_zones = ply, bbox = bb, 
    mask_tif = F, rast_tif = glue("{dir_out}/{nms}/{yr}.tif"), 
    zonal_fun = "mean", zonal_csv = glue("{dir_out}/{nms}/{yr}.csv"), 
    dir_nc = glue("{dir_out}/{nms}/{yr}_nc"), keep_nc = F, n_max_vals_per_req = 1e+05, 
    time_min = time_min, time_max = time_max, verbose = T)
debug: while (i_req <= n_reqs) {
    i_t_beg <- (i_req - 1) * n_t_per_req + 1
    i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
    t_req <- times_todo[c(i_t_beg, i_t_end)]
    t_req_str <- format_ISO8601(t_req, usetz = "Z")
    if (verbose) 
        message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
    ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
        ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
        0), nc)
    unlink(ncs0)
    nc_retry <- T
    nc_n_try <- 1
    n_max_retries
    while (nc_retry) {
        res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
            url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
                bbox[["xmax"]]), latitude = c(bbox[["ymin"]], 
                bbox[["ymax"]]), time = t_req_str, fmt = "nc", 
            store = rerddap::disk(path = dir_nc)))
        if (inherits(res, "try-error")) {
            err <- attr(res, "condition")
            msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
            nc_n_try <- nc_n_try + 1
            if (nc_n_try > n_max_retries) {
                stop(msg)
            }
            else {
                message(msg, "\nRETRYing...")
                Sys.sleep(1)
            }
        }
        else {
            nc_retry <- F
        }
    }
    i_req <- i_req + 1
}
debug: i_t_beg <- (i_req - 1) * n_t_per_req + 1
debug: i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
debug: t_req <- times_todo[c(i_t_beg, i_t_end)]
debug: t_req_str <- format_ISO8601(t_req, usetz = "Z")
debug: if (verbose) message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
debug: message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
Fetching request 1 of 1 (2003-01-01 to 2003-12-01) ~ 19:33:12 UTC
debug: ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
    0), nc)
debug: unlink(ncs0)
debug: nc_retry <- T
debug: nc_n_try <- 1
debug: n_max_retries
debug: while (nc_retry) {
    res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
        url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
            bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
        time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
    if (inherits(res, "try-error")) {
        err <- attr(res, "condition")
        msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
        nc_n_try <- nc_n_try + 1
        if (nc_n_try > n_max_retries) {
            stop(msg)
        }
        else {
            message(msg, "\nRETRYing...")
            Sys.sleep(1)
        }
    }
    else {
        nc_retry <- F
    }
}
debug: res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
    url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
        bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
    time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
debug: if (inherits(res, "try-error")) {
    err <- attr(res, "condition")
    msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
    nc_n_try <- nc_n_try + 1
    if (nc_n_try > n_max_retries) {
        stop(msg)
    }
    else {
        message(msg, "\nRETRYing...")
        Sys.sleep(1)
    }
} else {
    nc_retry <- F
}
debug: nc_retry <- F
debug: (while) nc_retry
debug: i_req <- i_req + 1
debug: (while) i_req <= n_reqs
debug: ncs <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size > 
    0), nc)
debug: r <- terra::rast(ncs)
debug: stopifnot(all(class(terra::time(r)) %in% c("POSIXct", "POSIXt")))
debug: idx <- dplyr::pull(dplyr::filter(dplyr::arrange(dplyr::tibble(idx = 1:terra::nlyr(r), 
    time = terra::time(r)), time), !duplicated(time)), idx)
debug: r <- terra::subset(r, idx)
debug: stopifnot(terra::crs(r, proj = T) == wgs84)
debug: if (mask_tif) r <- terra::mask(r, sf_zones)
debug: lyrs <- glue("{var}|{terra::time(r)}")
debug: if (length(dims_other) > 0 && !all(length(dims[dims_other]) == 
    1)) stop(glue("Other dimensions not yet supported: {paste(dims_other, collapse = ',')}"))
debug: names(r) <- lyrs
debug: if (!is.null(rast_tif)) {
    if (fs::file_exists(rast_tif)) {
        r_tmp_tif <- tempfile(fileext = ".tif")
        r_tmp <- c(rast(rast_tif), r)
        r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
        terra::writeRaster(r_tmp, r_tmp_tif)
        fs::file_delete(rast_tif)
        fs::file_move(r_tmp_tif, rast_tif)
        rm(r)
        rm(r_tmp)
    }
    else {
        terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
    }
    r <- terra::rast(rast_tif)
}
debug: if (fs::file_exists(rast_tif)) {
    r_tmp_tif <- tempfile(fileext = ".tif")
    r_tmp <- c(rast(rast_tif), r)
    r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
    terra::writeRaster(r_tmp, r_tmp_tif)
    fs::file_delete(rast_tif)
    fs::file_move(r_tmp_tif, rast_tif)
    rm(r)
    rm(r_tmp)
} else {
    terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
}
debug: terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
debug: r <- terra::rast(rast_tif)
debug: d_r <- mutate(tidyr::pivot_longer(sf::st_drop_geometry(sf::st_as_sf(terra::zonal(x = r, 
    z = terra::vect(dplyr::select(sf_zones, dplyr::all_of(fld_zones))), 
    fun = zonal_fun, exact = T, na.rm = T, as.polygons = T))), 
    cols = -dplyr::any_of(fld_zones), names_to = "lyr", values_to = zonal_fun), 
    time = readr::parse_datetime(str_replace(lyr, glue("{var}\\|(.*)"), 
        "\\1")))
debug: if (!is.null(zonal_csv)) write_csv(d_r, zonal_csv)
debug: write_csv(d_r, zonal_csv)
debug: if (!keep_nc) unlink(dir_nc, recursive = T)
debug: unlink(dir_nc, recursive = T)
debug: return(d_r)
Downloading 1 requests, up to 148 time slices each
Called from: extractr::ed_extract(ed, var = v, sf_zones = ply, bbox = bb, 
    mask_tif = F, rast_tif = glue("{dir_out}/{nms}/{yr}.tif"), 
    zonal_fun = "mean", zonal_csv = glue("{dir_out}/{nms}/{yr}.csv"), 
    dir_nc = glue("{dir_out}/{nms}/{yr}_nc"), keep_nc = F, n_max_vals_per_req = 1e+05, 
    time_min = time_min, time_max = time_max, verbose = T)
debug: while (i_req <= n_reqs) {
    i_t_beg <- (i_req - 1) * n_t_per_req + 1
    i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
    t_req <- times_todo[c(i_t_beg, i_t_end)]
    t_req_str <- format_ISO8601(t_req, usetz = "Z")
    if (verbose) 
        message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
    ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
        ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
        0), nc)
    unlink(ncs0)
    nc_retry <- T
    nc_n_try <- 1
    n_max_retries
    while (nc_retry) {
        res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
            url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
                bbox[["xmax"]]), latitude = c(bbox[["ymin"]], 
                bbox[["ymax"]]), time = t_req_str, fmt = "nc", 
            store = rerddap::disk(path = dir_nc)))
        if (inherits(res, "try-error")) {
            err <- attr(res, "condition")
            msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
            nc_n_try <- nc_n_try + 1
            if (nc_n_try > n_max_retries) {
                stop(msg)
            }
            else {
                message(msg, "\nRETRYing...")
                Sys.sleep(1)
            }
        }
        else {
            nc_retry <- F
        }
    }
    i_req <- i_req + 1
}
debug: i_t_beg <- (i_req - 1) * n_t_per_req + 1
debug: i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
debug: t_req <- times_todo[c(i_t_beg, i_t_end)]
debug: t_req_str <- format_ISO8601(t_req, usetz = "Z")
debug: if (verbose) message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
debug: message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
Fetching request 1 of 1 (2004-01-01 to 2004-12-01) ~ 19:33:15 UTC
debug: ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
    0), nc)
debug: unlink(ncs0)
debug: nc_retry <- T
debug: nc_n_try <- 1
debug: n_max_retries
debug: while (nc_retry) {
    res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
        url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
            bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
        time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
    if (inherits(res, "try-error")) {
        err <- attr(res, "condition")
        msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
        nc_n_try <- nc_n_try + 1
        if (nc_n_try > n_max_retries) {
            stop(msg)
        }
        else {
            message(msg, "\nRETRYing...")
            Sys.sleep(1)
        }
    }
    else {
        nc_retry <- F
    }
}
debug: res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
    url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
        bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
    time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
debug: if (inherits(res, "try-error")) {
    err <- attr(res, "condition")
    msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
    nc_n_try <- nc_n_try + 1
    if (nc_n_try > n_max_retries) {
        stop(msg)
    }
    else {
        message(msg, "\nRETRYing...")
        Sys.sleep(1)
    }
} else {
    nc_retry <- F
}
debug: nc_retry <- F
debug: (while) nc_retry
debug: i_req <- i_req + 1
debug: (while) i_req <= n_reqs
debug: ncs <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size > 
    0), nc)
debug: r <- terra::rast(ncs)
debug: stopifnot(all(class(terra::time(r)) %in% c("POSIXct", "POSIXt")))
debug: idx <- dplyr::pull(dplyr::filter(dplyr::arrange(dplyr::tibble(idx = 1:terra::nlyr(r), 
    time = terra::time(r)), time), !duplicated(time)), idx)
debug: r <- terra::subset(r, idx)
debug: stopifnot(terra::crs(r, proj = T) == wgs84)
debug: if (mask_tif) r <- terra::mask(r, sf_zones)
debug: lyrs <- glue("{var}|{terra::time(r)}")
debug: if (length(dims_other) > 0 && !all(length(dims[dims_other]) == 
    1)) stop(glue("Other dimensions not yet supported: {paste(dims_other, collapse = ',')}"))
debug: names(r) <- lyrs
debug: if (!is.null(rast_tif)) {
    if (fs::file_exists(rast_tif)) {
        r_tmp_tif <- tempfile(fileext = ".tif")
        r_tmp <- c(rast(rast_tif), r)
        r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
        terra::writeRaster(r_tmp, r_tmp_tif)
        fs::file_delete(rast_tif)
        fs::file_move(r_tmp_tif, rast_tif)
        rm(r)
        rm(r_tmp)
    }
    else {
        terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
    }
    r <- terra::rast(rast_tif)
}
debug: if (fs::file_exists(rast_tif)) {
    r_tmp_tif <- tempfile(fileext = ".tif")
    r_tmp <- c(rast(rast_tif), r)
    r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
    terra::writeRaster(r_tmp, r_tmp_tif)
    fs::file_delete(rast_tif)
    fs::file_move(r_tmp_tif, rast_tif)
    rm(r)
    rm(r_tmp)
} else {
    terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
}
debug: terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
debug: r <- terra::rast(rast_tif)
debug: d_r <- mutate(tidyr::pivot_longer(sf::st_drop_geometry(sf::st_as_sf(terra::zonal(x = r, 
    z = terra::vect(dplyr::select(sf_zones, dplyr::all_of(fld_zones))), 
    fun = zonal_fun, exact = T, na.rm = T, as.polygons = T))), 
    cols = -dplyr::any_of(fld_zones), names_to = "lyr", values_to = zonal_fun), 
    time = readr::parse_datetime(str_replace(lyr, glue("{var}\\|(.*)"), 
        "\\1")))
debug: if (!is.null(zonal_csv)) write_csv(d_r, zonal_csv)
debug: write_csv(d_r, zonal_csv)
debug: if (!keep_nc) unlink(dir_nc, recursive = T)
debug: unlink(dir_nc, recursive = T)
debug: return(d_r)
Downloading 1 requests, up to 148 time slices each
Called from: extractr::ed_extract(ed, var = v, sf_zones = ply, bbox = bb, 
    mask_tif = F, rast_tif = glue("{dir_out}/{nms}/{yr}.tif"), 
    zonal_fun = "mean", zonal_csv = glue("{dir_out}/{nms}/{yr}.csv"), 
    dir_nc = glue("{dir_out}/{nms}/{yr}_nc"), keep_nc = F, n_max_vals_per_req = 1e+05, 
    time_min = time_min, time_max = time_max, verbose = T)
debug: while (i_req <= n_reqs) {
    i_t_beg <- (i_req - 1) * n_t_per_req + 1
    i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
    t_req <- times_todo[c(i_t_beg, i_t_end)]
    t_req_str <- format_ISO8601(t_req, usetz = "Z")
    if (verbose) 
        message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
    ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
        ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
        0), nc)
    unlink(ncs0)
    nc_retry <- T
    nc_n_try <- 1
    n_max_retries
    while (nc_retry) {
        res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
            url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
                bbox[["xmax"]]), latitude = c(bbox[["ymin"]], 
                bbox[["ymax"]]), time = t_req_str, fmt = "nc", 
            store = rerddap::disk(path = dir_nc)))
        if (inherits(res, "try-error")) {
            err <- attr(res, "condition")
            msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
            nc_n_try <- nc_n_try + 1
            if (nc_n_try > n_max_retries) {
                stop(msg)
            }
            else {
                message(msg, "\nRETRYing...")
                Sys.sleep(1)
            }
        }
        else {
            nc_retry <- F
        }
    }
    i_req <- i_req + 1
}
debug: i_t_beg <- (i_req - 1) * n_t_per_req + 1
debug: i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
debug: t_req <- times_todo[c(i_t_beg, i_t_end)]
debug: t_req_str <- format_ISO8601(t_req, usetz = "Z")
debug: if (verbose) message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
debug: message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
Fetching request 1 of 1 (2005-01-01 to 2005-12-01) ~ 19:33:18 UTC
debug: ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
    0), nc)
debug: unlink(ncs0)
debug: nc_retry <- T
debug: nc_n_try <- 1
debug: n_max_retries
debug: while (nc_retry) {
    res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
        url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
            bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
        time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
    if (inherits(res, "try-error")) {
        err <- attr(res, "condition")
        msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
        nc_n_try <- nc_n_try + 1
        if (nc_n_try > n_max_retries) {
            stop(msg)
        }
        else {
            message(msg, "\nRETRYing...")
            Sys.sleep(1)
        }
    }
    else {
        nc_retry <- F
    }
}
debug: res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
    url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
        bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
    time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
debug: if (inherits(res, "try-error")) {
    err <- attr(res, "condition")
    msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
    nc_n_try <- nc_n_try + 1
    if (nc_n_try > n_max_retries) {
        stop(msg)
    }
    else {
        message(msg, "\nRETRYing...")
        Sys.sleep(1)
    }
} else {
    nc_retry <- F
}
debug: nc_retry <- F
debug: (while) nc_retry
debug: i_req <- i_req + 1
debug: (while) i_req <= n_reqs
debug: ncs <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size > 
    0), nc)
debug: r <- terra::rast(ncs)
debug: stopifnot(all(class(terra::time(r)) %in% c("POSIXct", "POSIXt")))
debug: idx <- dplyr::pull(dplyr::filter(dplyr::arrange(dplyr::tibble(idx = 1:terra::nlyr(r), 
    time = terra::time(r)), time), !duplicated(time)), idx)
debug: r <- terra::subset(r, idx)
debug: stopifnot(terra::crs(r, proj = T) == wgs84)
debug: if (mask_tif) r <- terra::mask(r, sf_zones)
debug: lyrs <- glue("{var}|{terra::time(r)}")
debug: if (length(dims_other) > 0 && !all(length(dims[dims_other]) == 
    1)) stop(glue("Other dimensions not yet supported: {paste(dims_other, collapse = ',')}"))
debug: names(r) <- lyrs
debug: if (!is.null(rast_tif)) {
    if (fs::file_exists(rast_tif)) {
        r_tmp_tif <- tempfile(fileext = ".tif")
        r_tmp <- c(rast(rast_tif), r)
        r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
        terra::writeRaster(r_tmp, r_tmp_tif)
        fs::file_delete(rast_tif)
        fs::file_move(r_tmp_tif, rast_tif)
        rm(r)
        rm(r_tmp)
    }
    else {
        terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
    }
    r <- terra::rast(rast_tif)
}
debug: if (fs::file_exists(rast_tif)) {
    r_tmp_tif <- tempfile(fileext = ".tif")
    r_tmp <- c(rast(rast_tif), r)
    r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
    terra::writeRaster(r_tmp, r_tmp_tif)
    fs::file_delete(rast_tif)
    fs::file_move(r_tmp_tif, rast_tif)
    rm(r)
    rm(r_tmp)
} else {
    terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
}
debug: terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
debug: r <- terra::rast(rast_tif)
debug: d_r <- mutate(tidyr::pivot_longer(sf::st_drop_geometry(sf::st_as_sf(terra::zonal(x = r, 
    z = terra::vect(dplyr::select(sf_zones, dplyr::all_of(fld_zones))), 
    fun = zonal_fun, exact = T, na.rm = T, as.polygons = T))), 
    cols = -dplyr::any_of(fld_zones), names_to = "lyr", values_to = zonal_fun), 
    time = readr::parse_datetime(str_replace(lyr, glue("{var}\\|(.*)"), 
        "\\1")))
debug: if (!is.null(zonal_csv)) write_csv(d_r, zonal_csv)
debug: write_csv(d_r, zonal_csv)
debug: if (!keep_nc) unlink(dir_nc, recursive = T)
debug: unlink(dir_nc, recursive = T)
debug: return(d_r)
Downloading 1 requests, up to 148 time slices each
Called from: extractr::ed_extract(ed, var = v, sf_zones = ply, bbox = bb, 
    mask_tif = F, rast_tif = glue("{dir_out}/{nms}/{yr}.tif"), 
    zonal_fun = "mean", zonal_csv = glue("{dir_out}/{nms}/{yr}.csv"), 
    dir_nc = glue("{dir_out}/{nms}/{yr}_nc"), keep_nc = F, n_max_vals_per_req = 1e+05, 
    time_min = time_min, time_max = time_max, verbose = T)
debug: while (i_req <= n_reqs) {
    i_t_beg <- (i_req - 1) * n_t_per_req + 1
    i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
    t_req <- times_todo[c(i_t_beg, i_t_end)]
    t_req_str <- format_ISO8601(t_req, usetz = "Z")
    if (verbose) 
        message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
    ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
        ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
        0), nc)
    unlink(ncs0)
    nc_retry <- T
    nc_n_try <- 1
    n_max_retries
    while (nc_retry) {
        res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
            url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
                bbox[["xmax"]]), latitude = c(bbox[["ymin"]], 
                bbox[["ymax"]]), time = t_req_str, fmt = "nc", 
            store = rerddap::disk(path = dir_nc)))
        if (inherits(res, "try-error")) {
            err <- attr(res, "condition")
            msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
            nc_n_try <- nc_n_try + 1
            if (nc_n_try > n_max_retries) {
                stop(msg)
            }
            else {
                message(msg, "\nRETRYing...")
                Sys.sleep(1)
            }
        }
        else {
            nc_retry <- F
        }
    }
    i_req <- i_req + 1
}
debug: i_t_beg <- (i_req - 1) * n_t_per_req + 1
debug: i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
debug: t_req <- times_todo[c(i_t_beg, i_t_end)]
debug: t_req_str <- format_ISO8601(t_req, usetz = "Z")
debug: if (verbose) message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
debug: message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
Fetching request 1 of 1 (2006-01-01 to 2006-12-01) ~ 19:33:21 UTC
debug: ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
    0), nc)
debug: unlink(ncs0)
debug: nc_retry <- T
debug: nc_n_try <- 1
debug: n_max_retries
debug: while (nc_retry) {
    res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
        url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
            bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
        time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
    if (inherits(res, "try-error")) {
        err <- attr(res, "condition")
        msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
        nc_n_try <- nc_n_try + 1
        if (nc_n_try > n_max_retries) {
            stop(msg)
        }
        else {
            message(msg, "\nRETRYing...")
            Sys.sleep(1)
        }
    }
    else {
        nc_retry <- F
    }
}
debug: res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
    url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
        bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
    time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
debug: if (inherits(res, "try-error")) {
    err <- attr(res, "condition")
    msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
    nc_n_try <- nc_n_try + 1
    if (nc_n_try > n_max_retries) {
        stop(msg)
    }
    else {
        message(msg, "\nRETRYing...")
        Sys.sleep(1)
    }
} else {
    nc_retry <- F
}
debug: nc_retry <- F
debug: (while) nc_retry
debug: i_req <- i_req + 1
debug: (while) i_req <= n_reqs
debug: ncs <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size > 
    0), nc)
debug: r <- terra::rast(ncs)
debug: stopifnot(all(class(terra::time(r)) %in% c("POSIXct", "POSIXt")))
debug: idx <- dplyr::pull(dplyr::filter(dplyr::arrange(dplyr::tibble(idx = 1:terra::nlyr(r), 
    time = terra::time(r)), time), !duplicated(time)), idx)
debug: r <- terra::subset(r, idx)
debug: stopifnot(terra::crs(r, proj = T) == wgs84)
debug: if (mask_tif) r <- terra::mask(r, sf_zones)
debug: lyrs <- glue("{var}|{terra::time(r)}")
debug: if (length(dims_other) > 0 && !all(length(dims[dims_other]) == 
    1)) stop(glue("Other dimensions not yet supported: {paste(dims_other, collapse = ',')}"))
debug: names(r) <- lyrs
debug: if (!is.null(rast_tif)) {
    if (fs::file_exists(rast_tif)) {
        r_tmp_tif <- tempfile(fileext = ".tif")
        r_tmp <- c(rast(rast_tif), r)
        r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
        terra::writeRaster(r_tmp, r_tmp_tif)
        fs::file_delete(rast_tif)
        fs::file_move(r_tmp_tif, rast_tif)
        rm(r)
        rm(r_tmp)
    }
    else {
        terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
    }
    r <- terra::rast(rast_tif)
}
debug: if (fs::file_exists(rast_tif)) {
    r_tmp_tif <- tempfile(fileext = ".tif")
    r_tmp <- c(rast(rast_tif), r)
    r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
    terra::writeRaster(r_tmp, r_tmp_tif)
    fs::file_delete(rast_tif)
    fs::file_move(r_tmp_tif, rast_tif)
    rm(r)
    rm(r_tmp)
} else {
    terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
}
debug: terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
debug: r <- terra::rast(rast_tif)
debug: d_r <- mutate(tidyr::pivot_longer(sf::st_drop_geometry(sf::st_as_sf(terra::zonal(x = r, 
    z = terra::vect(dplyr::select(sf_zones, dplyr::all_of(fld_zones))), 
    fun = zonal_fun, exact = T, na.rm = T, as.polygons = T))), 
    cols = -dplyr::any_of(fld_zones), names_to = "lyr", values_to = zonal_fun), 
    time = readr::parse_datetime(str_replace(lyr, glue("{var}\\|(.*)"), 
        "\\1")))
debug: if (!is.null(zonal_csv)) write_csv(d_r, zonal_csv)
debug: write_csv(d_r, zonal_csv)
debug: if (!keep_nc) unlink(dir_nc, recursive = T)
debug: unlink(dir_nc, recursive = T)
debug: return(d_r)
Downloading 1 requests, up to 148 time slices each
Called from: extractr::ed_extract(ed, var = v, sf_zones = ply, bbox = bb, 
    mask_tif = F, rast_tif = glue("{dir_out}/{nms}/{yr}.tif"), 
    zonal_fun = "mean", zonal_csv = glue("{dir_out}/{nms}/{yr}.csv"), 
    dir_nc = glue("{dir_out}/{nms}/{yr}_nc"), keep_nc = F, n_max_vals_per_req = 1e+05, 
    time_min = time_min, time_max = time_max, verbose = T)
debug: while (i_req <= n_reqs) {
    i_t_beg <- (i_req - 1) * n_t_per_req + 1
    i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
    t_req <- times_todo[c(i_t_beg, i_t_end)]
    t_req_str <- format_ISO8601(t_req, usetz = "Z")
    if (verbose) 
        message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
    ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
        ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
        0), nc)
    unlink(ncs0)
    nc_retry <- T
    nc_n_try <- 1
    n_max_retries
    while (nc_retry) {
        res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
            url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
                bbox[["xmax"]]), latitude = c(bbox[["ymin"]], 
                bbox[["ymax"]]), time = t_req_str, fmt = "nc", 
            store = rerddap::disk(path = dir_nc)))
        if (inherits(res, "try-error")) {
            err <- attr(res, "condition")
            msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
            nc_n_try <- nc_n_try + 1
            if (nc_n_try > n_max_retries) {
                stop(msg)
            }
            else {
                message(msg, "\nRETRYing...")
                Sys.sleep(1)
            }
        }
        else {
            nc_retry <- F
        }
    }
    i_req <- i_req + 1
}
debug: i_t_beg <- (i_req - 1) * n_t_per_req + 1
debug: i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
debug: t_req <- times_todo[c(i_t_beg, i_t_end)]
debug: t_req_str <- format_ISO8601(t_req, usetz = "Z")
debug: if (verbose) message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
debug: message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
Fetching request 1 of 1 (2007-01-01 to 2007-12-01) ~ 19:33:24 UTC
debug: ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
    0), nc)
debug: unlink(ncs0)
debug: nc_retry <- T
debug: nc_n_try <- 1
debug: n_max_retries
debug: while (nc_retry) {
    res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
        url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
            bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
        time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
    if (inherits(res, "try-error")) {
        err <- attr(res, "condition")
        msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
        nc_n_try <- nc_n_try + 1
        if (nc_n_try > n_max_retries) {
            stop(msg)
        }
        else {
            message(msg, "\nRETRYing...")
            Sys.sleep(1)
        }
    }
    else {
        nc_retry <- F
    }
}
debug: res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
    url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
        bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
    time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
debug: if (inherits(res, "try-error")) {
    err <- attr(res, "condition")
    msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
    nc_n_try <- nc_n_try + 1
    if (nc_n_try > n_max_retries) {
        stop(msg)
    }
    else {
        message(msg, "\nRETRYing...")
        Sys.sleep(1)
    }
} else {
    nc_retry <- F
}
debug: nc_retry <- F
debug: (while) nc_retry
debug: i_req <- i_req + 1
debug: (while) i_req <= n_reqs
debug: ncs <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size > 
    0), nc)
debug: r <- terra::rast(ncs)
debug: stopifnot(all(class(terra::time(r)) %in% c("POSIXct", "POSIXt")))
debug: idx <- dplyr::pull(dplyr::filter(dplyr::arrange(dplyr::tibble(idx = 1:terra::nlyr(r), 
    time = terra::time(r)), time), !duplicated(time)), idx)
debug: r <- terra::subset(r, idx)
debug: stopifnot(terra::crs(r, proj = T) == wgs84)
debug: if (mask_tif) r <- terra::mask(r, sf_zones)
debug: lyrs <- glue("{var}|{terra::time(r)}")
debug: if (length(dims_other) > 0 && !all(length(dims[dims_other]) == 
    1)) stop(glue("Other dimensions not yet supported: {paste(dims_other, collapse = ',')}"))
debug: names(r) <- lyrs
debug: if (!is.null(rast_tif)) {
    if (fs::file_exists(rast_tif)) {
        r_tmp_tif <- tempfile(fileext = ".tif")
        r_tmp <- c(rast(rast_tif), r)
        r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
        terra::writeRaster(r_tmp, r_tmp_tif)
        fs::file_delete(rast_tif)
        fs::file_move(r_tmp_tif, rast_tif)
        rm(r)
        rm(r_tmp)
    }
    else {
        terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
    }
    r <- terra::rast(rast_tif)
}
debug: if (fs::file_exists(rast_tif)) {
    r_tmp_tif <- tempfile(fileext = ".tif")
    r_tmp <- c(rast(rast_tif), r)
    r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
    terra::writeRaster(r_tmp, r_tmp_tif)
    fs::file_delete(rast_tif)
    fs::file_move(r_tmp_tif, rast_tif)
    rm(r)
    rm(r_tmp)
} else {
    terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
}
debug: terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
debug: r <- terra::rast(rast_tif)
debug: d_r <- mutate(tidyr::pivot_longer(sf::st_drop_geometry(sf::st_as_sf(terra::zonal(x = r, 
    z = terra::vect(dplyr::select(sf_zones, dplyr::all_of(fld_zones))), 
    fun = zonal_fun, exact = T, na.rm = T, as.polygons = T))), 
    cols = -dplyr::any_of(fld_zones), names_to = "lyr", values_to = zonal_fun), 
    time = readr::parse_datetime(str_replace(lyr, glue("{var}\\|(.*)"), 
        "\\1")))
debug: if (!is.null(zonal_csv)) write_csv(d_r, zonal_csv)
debug: write_csv(d_r, zonal_csv)
debug: if (!keep_nc) unlink(dir_nc, recursive = T)
debug: unlink(dir_nc, recursive = T)
debug: return(d_r)
Downloading 1 requests, up to 148 time slices each
Called from: extractr::ed_extract(ed, var = v, sf_zones = ply, bbox = bb, 
    mask_tif = F, rast_tif = glue("{dir_out}/{nms}/{yr}.tif"), 
    zonal_fun = "mean", zonal_csv = glue("{dir_out}/{nms}/{yr}.csv"), 
    dir_nc = glue("{dir_out}/{nms}/{yr}_nc"), keep_nc = F, n_max_vals_per_req = 1e+05, 
    time_min = time_min, time_max = time_max, verbose = T)
debug: while (i_req <= n_reqs) {
    i_t_beg <- (i_req - 1) * n_t_per_req + 1
    i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
    t_req <- times_todo[c(i_t_beg, i_t_end)]
    t_req_str <- format_ISO8601(t_req, usetz = "Z")
    if (verbose) 
        message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
    ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
        ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
        0), nc)
    unlink(ncs0)
    nc_retry <- T
    nc_n_try <- 1
    n_max_retries
    while (nc_retry) {
        res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
            url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
                bbox[["xmax"]]), latitude = c(bbox[["ymin"]], 
                bbox[["ymax"]]), time = t_req_str, fmt = "nc", 
            store = rerddap::disk(path = dir_nc)))
        if (inherits(res, "try-error")) {
            err <- attr(res, "condition")
            msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
            nc_n_try <- nc_n_try + 1
            if (nc_n_try > n_max_retries) {
                stop(msg)
            }
            else {
                message(msg, "\nRETRYing...")
                Sys.sleep(1)
            }
        }
        else {
            nc_retry <- F
        }
    }
    i_req <- i_req + 1
}
debug: i_t_beg <- (i_req - 1) * n_t_per_req + 1
debug: i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
debug: t_req <- times_todo[c(i_t_beg, i_t_end)]
debug: t_req_str <- format_ISO8601(t_req, usetz = "Z")
debug: if (verbose) message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
debug: message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
Fetching request 1 of 1 (2008-01-01 to 2008-12-01) ~ 19:33:28 UTC
debug: ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
    0), nc)
debug: unlink(ncs0)
debug: nc_retry <- T
debug: nc_n_try <- 1
debug: n_max_retries
debug: while (nc_retry) {
    res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
        url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
            bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
        time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
    if (inherits(res, "try-error")) {
        err <- attr(res, "condition")
        msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
        nc_n_try <- nc_n_try + 1
        if (nc_n_try > n_max_retries) {
            stop(msg)
        }
        else {
            message(msg, "\nRETRYing...")
            Sys.sleep(1)
        }
    }
    else {
        nc_retry <- F
    }
}
debug: res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
    url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
        bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
    time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
debug: if (inherits(res, "try-error")) {
    err <- attr(res, "condition")
    msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
    nc_n_try <- nc_n_try + 1
    if (nc_n_try > n_max_retries) {
        stop(msg)
    }
    else {
        message(msg, "\nRETRYing...")
        Sys.sleep(1)
    }
} else {
    nc_retry <- F
}
debug: nc_retry <- F
debug: (while) nc_retry
debug: i_req <- i_req + 1
debug: (while) i_req <= n_reqs
debug: ncs <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size > 
    0), nc)
debug: r <- terra::rast(ncs)
debug: stopifnot(all(class(terra::time(r)) %in% c("POSIXct", "POSIXt")))
debug: idx <- dplyr::pull(dplyr::filter(dplyr::arrange(dplyr::tibble(idx = 1:terra::nlyr(r), 
    time = terra::time(r)), time), !duplicated(time)), idx)
debug: r <- terra::subset(r, idx)
debug: stopifnot(terra::crs(r, proj = T) == wgs84)
debug: if (mask_tif) r <- terra::mask(r, sf_zones)
debug: lyrs <- glue("{var}|{terra::time(r)}")
debug: if (length(dims_other) > 0 && !all(length(dims[dims_other]) == 
    1)) stop(glue("Other dimensions not yet supported: {paste(dims_other, collapse = ',')}"))
debug: names(r) <- lyrs
debug: if (!is.null(rast_tif)) {
    if (fs::file_exists(rast_tif)) {
        r_tmp_tif <- tempfile(fileext = ".tif")
        r_tmp <- c(rast(rast_tif), r)
        r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
        terra::writeRaster(r_tmp, r_tmp_tif)
        fs::file_delete(rast_tif)
        fs::file_move(r_tmp_tif, rast_tif)
        rm(r)
        rm(r_tmp)
    }
    else {
        terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
    }
    r <- terra::rast(rast_tif)
}
debug: if (fs::file_exists(rast_tif)) {
    r_tmp_tif <- tempfile(fileext = ".tif")
    r_tmp <- c(rast(rast_tif), r)
    r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
    terra::writeRaster(r_tmp, r_tmp_tif)
    fs::file_delete(rast_tif)
    fs::file_move(r_tmp_tif, rast_tif)
    rm(r)
    rm(r_tmp)
} else {
    terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
}
debug: terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
debug: r <- terra::rast(rast_tif)
debug: d_r <- mutate(tidyr::pivot_longer(sf::st_drop_geometry(sf::st_as_sf(terra::zonal(x = r, 
    z = terra::vect(dplyr::select(sf_zones, dplyr::all_of(fld_zones))), 
    fun = zonal_fun, exact = T, na.rm = T, as.polygons = T))), 
    cols = -dplyr::any_of(fld_zones), names_to = "lyr", values_to = zonal_fun), 
    time = readr::parse_datetime(str_replace(lyr, glue("{var}\\|(.*)"), 
        "\\1")))
debug: if (!is.null(zonal_csv)) write_csv(d_r, zonal_csv)
debug: write_csv(d_r, zonal_csv)
debug: if (!keep_nc) unlink(dir_nc, recursive = T)
debug: unlink(dir_nc, recursive = T)
debug: return(d_r)
Downloading 1 requests, up to 148 time slices each
Called from: extractr::ed_extract(ed, var = v, sf_zones = ply, bbox = bb, 
    mask_tif = F, rast_tif = glue("{dir_out}/{nms}/{yr}.tif"), 
    zonal_fun = "mean", zonal_csv = glue("{dir_out}/{nms}/{yr}.csv"), 
    dir_nc = glue("{dir_out}/{nms}/{yr}_nc"), keep_nc = F, n_max_vals_per_req = 1e+05, 
    time_min = time_min, time_max = time_max, verbose = T)
debug: while (i_req <= n_reqs) {
    i_t_beg <- (i_req - 1) * n_t_per_req + 1
    i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
    t_req <- times_todo[c(i_t_beg, i_t_end)]
    t_req_str <- format_ISO8601(t_req, usetz = "Z")
    if (verbose) 
        message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
    ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
        ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
        0), nc)
    unlink(ncs0)
    nc_retry <- T
    nc_n_try <- 1
    n_max_retries
    while (nc_retry) {
        res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
            url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
                bbox[["xmax"]]), latitude = c(bbox[["ymin"]], 
                bbox[["ymax"]]), time = t_req_str, fmt = "nc", 
            store = rerddap::disk(path = dir_nc)))
        if (inherits(res, "try-error")) {
            err <- attr(res, "condition")
            msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
            nc_n_try <- nc_n_try + 1
            if (nc_n_try > n_max_retries) {
                stop(msg)
            }
            else {
                message(msg, "\nRETRYing...")
                Sys.sleep(1)
            }
        }
        else {
            nc_retry <- F
        }
    }
    i_req <- i_req + 1
}
debug: i_t_beg <- (i_req - 1) * n_t_per_req + 1
debug: i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
debug: t_req <- times_todo[c(i_t_beg, i_t_end)]
debug: t_req_str <- format_ISO8601(t_req, usetz = "Z")
debug: if (verbose) message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
debug: message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
Fetching request 1 of 1 (2009-01-01 to 2009-12-01) ~ 19:33:31 UTC
debug: ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
    0), nc)
debug: unlink(ncs0)
debug: nc_retry <- T
debug: nc_n_try <- 1
debug: n_max_retries
debug: while (nc_retry) {
    res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
        url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
            bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
        time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
    if (inherits(res, "try-error")) {
        err <- attr(res, "condition")
        msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
        nc_n_try <- nc_n_try + 1
        if (nc_n_try > n_max_retries) {
            stop(msg)
        }
        else {
            message(msg, "\nRETRYing...")
            Sys.sleep(1)
        }
    }
    else {
        nc_retry <- F
    }
}
debug: res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
    url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
        bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
    time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
debug: if (inherits(res, "try-error")) {
    err <- attr(res, "condition")
    msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
    nc_n_try <- nc_n_try + 1
    if (nc_n_try > n_max_retries) {
        stop(msg)
    }
    else {
        message(msg, "\nRETRYing...")
        Sys.sleep(1)
    }
} else {
    nc_retry <- F
}
debug: nc_retry <- F
debug: (while) nc_retry
debug: i_req <- i_req + 1
debug: (while) i_req <= n_reqs
debug: ncs <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size > 
    0), nc)
debug: r <- terra::rast(ncs)
debug: stopifnot(all(class(terra::time(r)) %in% c("POSIXct", "POSIXt")))
debug: idx <- dplyr::pull(dplyr::filter(dplyr::arrange(dplyr::tibble(idx = 1:terra::nlyr(r), 
    time = terra::time(r)), time), !duplicated(time)), idx)
debug: r <- terra::subset(r, idx)
debug: stopifnot(terra::crs(r, proj = T) == wgs84)
debug: if (mask_tif) r <- terra::mask(r, sf_zones)
debug: lyrs <- glue("{var}|{terra::time(r)}")
debug: if (length(dims_other) > 0 && !all(length(dims[dims_other]) == 
    1)) stop(glue("Other dimensions not yet supported: {paste(dims_other, collapse = ',')}"))
debug: names(r) <- lyrs
debug: if (!is.null(rast_tif)) {
    if (fs::file_exists(rast_tif)) {
        r_tmp_tif <- tempfile(fileext = ".tif")
        r_tmp <- c(rast(rast_tif), r)
        r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
        terra::writeRaster(r_tmp, r_tmp_tif)
        fs::file_delete(rast_tif)
        fs::file_move(r_tmp_tif, rast_tif)
        rm(r)
        rm(r_tmp)
    }
    else {
        terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
    }
    r <- terra::rast(rast_tif)
}
debug: if (fs::file_exists(rast_tif)) {
    r_tmp_tif <- tempfile(fileext = ".tif")
    r_tmp <- c(rast(rast_tif), r)
    r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
    terra::writeRaster(r_tmp, r_tmp_tif)
    fs::file_delete(rast_tif)
    fs::file_move(r_tmp_tif, rast_tif)
    rm(r)
    rm(r_tmp)
} else {
    terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
}
debug: terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
debug: r <- terra::rast(rast_tif)
debug: d_r <- mutate(tidyr::pivot_longer(sf::st_drop_geometry(sf::st_as_sf(terra::zonal(x = r, 
    z = terra::vect(dplyr::select(sf_zones, dplyr::all_of(fld_zones))), 
    fun = zonal_fun, exact = T, na.rm = T, as.polygons = T))), 
    cols = -dplyr::any_of(fld_zones), names_to = "lyr", values_to = zonal_fun), 
    time = readr::parse_datetime(str_replace(lyr, glue("{var}\\|(.*)"), 
        "\\1")))
debug: if (!is.null(zonal_csv)) write_csv(d_r, zonal_csv)
debug: write_csv(d_r, zonal_csv)
debug: if (!keep_nc) unlink(dir_nc, recursive = T)
debug: unlink(dir_nc, recursive = T)
debug: return(d_r)
Downloading 1 requests, up to 148 time slices each
Called from: extractr::ed_extract(ed, var = v, sf_zones = ply, bbox = bb, 
    mask_tif = F, rast_tif = glue("{dir_out}/{nms}/{yr}.tif"), 
    zonal_fun = "mean", zonal_csv = glue("{dir_out}/{nms}/{yr}.csv"), 
    dir_nc = glue("{dir_out}/{nms}/{yr}_nc"), keep_nc = F, n_max_vals_per_req = 1e+05, 
    time_min = time_min, time_max = time_max, verbose = T)
debug: while (i_req <= n_reqs) {
    i_t_beg <- (i_req - 1) * n_t_per_req + 1
    i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
    t_req <- times_todo[c(i_t_beg, i_t_end)]
    t_req_str <- format_ISO8601(t_req, usetz = "Z")
    if (verbose) 
        message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
    ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
        ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
        0), nc)
    unlink(ncs0)
    nc_retry <- T
    nc_n_try <- 1
    n_max_retries
    while (nc_retry) {
        res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
            url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
                bbox[["xmax"]]), latitude = c(bbox[["ymin"]], 
                bbox[["ymax"]]), time = t_req_str, fmt = "nc", 
            store = rerddap::disk(path = dir_nc)))
        if (inherits(res, "try-error")) {
            err <- attr(res, "condition")
            msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
            nc_n_try <- nc_n_try + 1
            if (nc_n_try > n_max_retries) {
                stop(msg)
            }
            else {
                message(msg, "\nRETRYing...")
                Sys.sleep(1)
            }
        }
        else {
            nc_retry <- F
        }
    }
    i_req <- i_req + 1
}
debug: i_t_beg <- (i_req - 1) * n_t_per_req + 1
debug: i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
debug: t_req <- times_todo[c(i_t_beg, i_t_end)]
debug: t_req_str <- format_ISO8601(t_req, usetz = "Z")
debug: if (verbose) message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
debug: message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
Fetching request 1 of 1 (2010-01-01 to 2010-12-01) ~ 19:33:34 UTC
debug: ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
    0), nc)
debug: unlink(ncs0)
debug: nc_retry <- T
debug: nc_n_try <- 1
debug: n_max_retries
debug: while (nc_retry) {
    res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
        url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
            bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
        time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
    if (inherits(res, "try-error")) {
        err <- attr(res, "condition")
        msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
        nc_n_try <- nc_n_try + 1
        if (nc_n_try > n_max_retries) {
            stop(msg)
        }
        else {
            message(msg, "\nRETRYing...")
            Sys.sleep(1)
        }
    }
    else {
        nc_retry <- F
    }
}
debug: res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
    url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
        bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
    time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
debug: if (inherits(res, "try-error")) {
    err <- attr(res, "condition")
    msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
    nc_n_try <- nc_n_try + 1
    if (nc_n_try > n_max_retries) {
        stop(msg)
    }
    else {
        message(msg, "\nRETRYing...")
        Sys.sleep(1)
    }
} else {
    nc_retry <- F
}
debug: nc_retry <- F
debug: (while) nc_retry
debug: i_req <- i_req + 1
debug: (while) i_req <= n_reqs
debug: ncs <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size > 
    0), nc)
debug: r <- terra::rast(ncs)
debug: stopifnot(all(class(terra::time(r)) %in% c("POSIXct", "POSIXt")))
debug: idx <- dplyr::pull(dplyr::filter(dplyr::arrange(dplyr::tibble(idx = 1:terra::nlyr(r), 
    time = terra::time(r)), time), !duplicated(time)), idx)
debug: r <- terra::subset(r, idx)
debug: stopifnot(terra::crs(r, proj = T) == wgs84)
debug: if (mask_tif) r <- terra::mask(r, sf_zones)
debug: lyrs <- glue("{var}|{terra::time(r)}")
debug: if (length(dims_other) > 0 && !all(length(dims[dims_other]) == 
    1)) stop(glue("Other dimensions not yet supported: {paste(dims_other, collapse = ',')}"))
debug: names(r) <- lyrs
debug: if (!is.null(rast_tif)) {
    if (fs::file_exists(rast_tif)) {
        r_tmp_tif <- tempfile(fileext = ".tif")
        r_tmp <- c(rast(rast_tif), r)
        r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
        terra::writeRaster(r_tmp, r_tmp_tif)
        fs::file_delete(rast_tif)
        fs::file_move(r_tmp_tif, rast_tif)
        rm(r)
        rm(r_tmp)
    }
    else {
        terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
    }
    r <- terra::rast(rast_tif)
}
debug: if (fs::file_exists(rast_tif)) {
    r_tmp_tif <- tempfile(fileext = ".tif")
    r_tmp <- c(rast(rast_tif), r)
    r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
    terra::writeRaster(r_tmp, r_tmp_tif)
    fs::file_delete(rast_tif)
    fs::file_move(r_tmp_tif, rast_tif)
    rm(r)
    rm(r_tmp)
} else {
    terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
}
debug: terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
debug: r <- terra::rast(rast_tif)
debug: d_r <- mutate(tidyr::pivot_longer(sf::st_drop_geometry(sf::st_as_sf(terra::zonal(x = r, 
    z = terra::vect(dplyr::select(sf_zones, dplyr::all_of(fld_zones))), 
    fun = zonal_fun, exact = T, na.rm = T, as.polygons = T))), 
    cols = -dplyr::any_of(fld_zones), names_to = "lyr", values_to = zonal_fun), 
    time = readr::parse_datetime(str_replace(lyr, glue("{var}\\|(.*)"), 
        "\\1")))
debug: if (!is.null(zonal_csv)) write_csv(d_r, zonal_csv)
debug: write_csv(d_r, zonal_csv)
debug: if (!keep_nc) unlink(dir_nc, recursive = T)
debug: unlink(dir_nc, recursive = T)
debug: return(d_r)
Downloading 1 requests, up to 148 time slices each
Called from: extractr::ed_extract(ed, var = v, sf_zones = ply, bbox = bb, 
    mask_tif = F, rast_tif = glue("{dir_out}/{nms}/{yr}.tif"), 
    zonal_fun = "mean", zonal_csv = glue("{dir_out}/{nms}/{yr}.csv"), 
    dir_nc = glue("{dir_out}/{nms}/{yr}_nc"), keep_nc = F, n_max_vals_per_req = 1e+05, 
    time_min = time_min, time_max = time_max, verbose = T)
debug: while (i_req <= n_reqs) {
    i_t_beg <- (i_req - 1) * n_t_per_req + 1
    i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
    t_req <- times_todo[c(i_t_beg, i_t_end)]
    t_req_str <- format_ISO8601(t_req, usetz = "Z")
    if (verbose) 
        message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
    ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
        ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
        0), nc)
    unlink(ncs0)
    nc_retry <- T
    nc_n_try <- 1
    n_max_retries
    while (nc_retry) {
        res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
            url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
                bbox[["xmax"]]), latitude = c(bbox[["ymin"]], 
                bbox[["ymax"]]), time = t_req_str, fmt = "nc", 
            store = rerddap::disk(path = dir_nc)))
        if (inherits(res, "try-error")) {
            err <- attr(res, "condition")
            msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
            nc_n_try <- nc_n_try + 1
            if (nc_n_try > n_max_retries) {
                stop(msg)
            }
            else {
                message(msg, "\nRETRYing...")
                Sys.sleep(1)
            }
        }
        else {
            nc_retry <- F
        }
    }
    i_req <- i_req + 1
}
debug: i_t_beg <- (i_req - 1) * n_t_per_req + 1
debug: i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
debug: t_req <- times_todo[c(i_t_beg, i_t_end)]
debug: t_req_str <- format_ISO8601(t_req, usetz = "Z")
debug: if (verbose) message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
debug: message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
Fetching request 1 of 1 (2011-01-01 to 2011-12-01) ~ 19:33:37 UTC
debug: ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
    0), nc)
debug: unlink(ncs0)
debug: nc_retry <- T
debug: nc_n_try <- 1
debug: n_max_retries
debug: while (nc_retry) {
    res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
        url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
            bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
        time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
    if (inherits(res, "try-error")) {
        err <- attr(res, "condition")
        msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
        nc_n_try <- nc_n_try + 1
        if (nc_n_try > n_max_retries) {
            stop(msg)
        }
        else {
            message(msg, "\nRETRYing...")
            Sys.sleep(1)
        }
    }
    else {
        nc_retry <- F
    }
}
debug: res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
    url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
        bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
    time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
debug: if (inherits(res, "try-error")) {
    err <- attr(res, "condition")
    msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
    nc_n_try <- nc_n_try + 1
    if (nc_n_try > n_max_retries) {
        stop(msg)
    }
    else {
        message(msg, "\nRETRYing...")
        Sys.sleep(1)
    }
} else {
    nc_retry <- F
}
debug: nc_retry <- F
debug: (while) nc_retry
debug: i_req <- i_req + 1
debug: (while) i_req <= n_reqs
debug: ncs <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size > 
    0), nc)
debug: r <- terra::rast(ncs)
debug: stopifnot(all(class(terra::time(r)) %in% c("POSIXct", "POSIXt")))
debug: idx <- dplyr::pull(dplyr::filter(dplyr::arrange(dplyr::tibble(idx = 1:terra::nlyr(r), 
    time = terra::time(r)), time), !duplicated(time)), idx)
debug: r <- terra::subset(r, idx)
debug: stopifnot(terra::crs(r, proj = T) == wgs84)
debug: if (mask_tif) r <- terra::mask(r, sf_zones)
debug: lyrs <- glue("{var}|{terra::time(r)}")
debug: if (length(dims_other) > 0 && !all(length(dims[dims_other]) == 
    1)) stop(glue("Other dimensions not yet supported: {paste(dims_other, collapse = ',')}"))
debug: names(r) <- lyrs
debug: if (!is.null(rast_tif)) {
    if (fs::file_exists(rast_tif)) {
        r_tmp_tif <- tempfile(fileext = ".tif")
        r_tmp <- c(rast(rast_tif), r)
        r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
        terra::writeRaster(r_tmp, r_tmp_tif)
        fs::file_delete(rast_tif)
        fs::file_move(r_tmp_tif, rast_tif)
        rm(r)
        rm(r_tmp)
    }
    else {
        terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
    }
    r <- terra::rast(rast_tif)
}
debug: if (fs::file_exists(rast_tif)) {
    r_tmp_tif <- tempfile(fileext = ".tif")
    r_tmp <- c(rast(rast_tif), r)
    r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
    terra::writeRaster(r_tmp, r_tmp_tif)
    fs::file_delete(rast_tif)
    fs::file_move(r_tmp_tif, rast_tif)
    rm(r)
    rm(r_tmp)
} else {
    terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
}
debug: terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
debug: r <- terra::rast(rast_tif)
debug: d_r <- mutate(tidyr::pivot_longer(sf::st_drop_geometry(sf::st_as_sf(terra::zonal(x = r, 
    z = terra::vect(dplyr::select(sf_zones, dplyr::all_of(fld_zones))), 
    fun = zonal_fun, exact = T, na.rm = T, as.polygons = T))), 
    cols = -dplyr::any_of(fld_zones), names_to = "lyr", values_to = zonal_fun), 
    time = readr::parse_datetime(str_replace(lyr, glue("{var}\\|(.*)"), 
        "\\1")))
debug: if (!is.null(zonal_csv)) write_csv(d_r, zonal_csv)
debug: write_csv(d_r, zonal_csv)
debug: if (!keep_nc) unlink(dir_nc, recursive = T)
debug: unlink(dir_nc, recursive = T)
debug: return(d_r)
Downloading 1 requests, up to 148 time slices each
Called from: extractr::ed_extract(ed, var = v, sf_zones = ply, bbox = bb, 
    mask_tif = F, rast_tif = glue("{dir_out}/{nms}/{yr}.tif"), 
    zonal_fun = "mean", zonal_csv = glue("{dir_out}/{nms}/{yr}.csv"), 
    dir_nc = glue("{dir_out}/{nms}/{yr}_nc"), keep_nc = F, n_max_vals_per_req = 1e+05, 
    time_min = time_min, time_max = time_max, verbose = T)
debug: while (i_req <= n_reqs) {
    i_t_beg <- (i_req - 1) * n_t_per_req + 1
    i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
    t_req <- times_todo[c(i_t_beg, i_t_end)]
    t_req_str <- format_ISO8601(t_req, usetz = "Z")
    if (verbose) 
        message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
    ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
        ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
        0), nc)
    unlink(ncs0)
    nc_retry <- T
    nc_n_try <- 1
    n_max_retries
    while (nc_retry) {
        res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
            url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
                bbox[["xmax"]]), latitude = c(bbox[["ymin"]], 
                bbox[["ymax"]]), time = t_req_str, fmt = "nc", 
            store = rerddap::disk(path = dir_nc)))
        if (inherits(res, "try-error")) {
            err <- attr(res, "condition")
            msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
            nc_n_try <- nc_n_try + 1
            if (nc_n_try > n_max_retries) {
                stop(msg)
            }
            else {
                message(msg, "\nRETRYing...")
                Sys.sleep(1)
            }
        }
        else {
            nc_retry <- F
        }
    }
    i_req <- i_req + 1
}
debug: i_t_beg <- (i_req - 1) * n_t_per_req + 1
debug: i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
debug: t_req <- times_todo[c(i_t_beg, i_t_end)]
debug: t_req_str <- format_ISO8601(t_req, usetz = "Z")
debug: if (verbose) message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
debug: message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
Fetching request 1 of 1 (2012-01-01 to 2012-12-01) ~ 19:33:41 UTC
debug: ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
    0), nc)
debug: unlink(ncs0)
debug: nc_retry <- T
debug: nc_n_try <- 1
debug: n_max_retries
debug: while (nc_retry) {
    res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
        url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
            bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
        time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
    if (inherits(res, "try-error")) {
        err <- attr(res, "condition")
        msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
        nc_n_try <- nc_n_try + 1
        if (nc_n_try > n_max_retries) {
            stop(msg)
        }
        else {
            message(msg, "\nRETRYing...")
            Sys.sleep(1)
        }
    }
    else {
        nc_retry <- F
    }
}
debug: res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
    url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
        bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
    time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
debug: if (inherits(res, "try-error")) {
    err <- attr(res, "condition")
    msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
    nc_n_try <- nc_n_try + 1
    if (nc_n_try > n_max_retries) {
        stop(msg)
    }
    else {
        message(msg, "\nRETRYing...")
        Sys.sleep(1)
    }
} else {
    nc_retry <- F
}
debug: nc_retry <- F
debug: (while) nc_retry
debug: i_req <- i_req + 1
debug: (while) i_req <= n_reqs
debug: ncs <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size > 
    0), nc)
debug: r <- terra::rast(ncs)
debug: stopifnot(all(class(terra::time(r)) %in% c("POSIXct", "POSIXt")))
debug: idx <- dplyr::pull(dplyr::filter(dplyr::arrange(dplyr::tibble(idx = 1:terra::nlyr(r), 
    time = terra::time(r)), time), !duplicated(time)), idx)
debug: r <- terra::subset(r, idx)
debug: stopifnot(terra::crs(r, proj = T) == wgs84)
debug: if (mask_tif) r <- terra::mask(r, sf_zones)
debug: lyrs <- glue("{var}|{terra::time(r)}")
debug: if (length(dims_other) > 0 && !all(length(dims[dims_other]) == 
    1)) stop(glue("Other dimensions not yet supported: {paste(dims_other, collapse = ',')}"))
debug: names(r) <- lyrs
debug: if (!is.null(rast_tif)) {
    if (fs::file_exists(rast_tif)) {
        r_tmp_tif <- tempfile(fileext = ".tif")
        r_tmp <- c(rast(rast_tif), r)
        r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
        terra::writeRaster(r_tmp, r_tmp_tif)
        fs::file_delete(rast_tif)
        fs::file_move(r_tmp_tif, rast_tif)
        rm(r)
        rm(r_tmp)
    }
    else {
        terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
    }
    r <- terra::rast(rast_tif)
}
debug: if (fs::file_exists(rast_tif)) {
    r_tmp_tif <- tempfile(fileext = ".tif")
    r_tmp <- c(rast(rast_tif), r)
    r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
    terra::writeRaster(r_tmp, r_tmp_tif)
    fs::file_delete(rast_tif)
    fs::file_move(r_tmp_tif, rast_tif)
    rm(r)
    rm(r_tmp)
} else {
    terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
}
debug: terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
debug: r <- terra::rast(rast_tif)
debug: d_r <- mutate(tidyr::pivot_longer(sf::st_drop_geometry(sf::st_as_sf(terra::zonal(x = r, 
    z = terra::vect(dplyr::select(sf_zones, dplyr::all_of(fld_zones))), 
    fun = zonal_fun, exact = T, na.rm = T, as.polygons = T))), 
    cols = -dplyr::any_of(fld_zones), names_to = "lyr", values_to = zonal_fun), 
    time = readr::parse_datetime(str_replace(lyr, glue("{var}\\|(.*)"), 
        "\\1")))
debug: if (!is.null(zonal_csv)) write_csv(d_r, zonal_csv)
debug: write_csv(d_r, zonal_csv)
debug: if (!keep_nc) unlink(dir_nc, recursive = T)
debug: unlink(dir_nc, recursive = T)
debug: return(d_r)
Downloading 1 requests, up to 148 time slices each
Called from: extractr::ed_extract(ed, var = v, sf_zones = ply, bbox = bb, 
    mask_tif = F, rast_tif = glue("{dir_out}/{nms}/{yr}.tif"), 
    zonal_fun = "mean", zonal_csv = glue("{dir_out}/{nms}/{yr}.csv"), 
    dir_nc = glue("{dir_out}/{nms}/{yr}_nc"), keep_nc = F, n_max_vals_per_req = 1e+05, 
    time_min = time_min, time_max = time_max, verbose = T)
debug: while (i_req <= n_reqs) {
    i_t_beg <- (i_req - 1) * n_t_per_req + 1
    i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
    t_req <- times_todo[c(i_t_beg, i_t_end)]
    t_req_str <- format_ISO8601(t_req, usetz = "Z")
    if (verbose) 
        message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
    ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
        ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
        0), nc)
    unlink(ncs0)
    nc_retry <- T
    nc_n_try <- 1
    n_max_retries
    while (nc_retry) {
        res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
            url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
                bbox[["xmax"]]), latitude = c(bbox[["ymin"]], 
                bbox[["ymax"]]), time = t_req_str, fmt = "nc", 
            store = rerddap::disk(path = dir_nc)))
        if (inherits(res, "try-error")) {
            err <- attr(res, "condition")
            msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
            nc_n_try <- nc_n_try + 1
            if (nc_n_try > n_max_retries) {
                stop(msg)
            }
            else {
                message(msg, "\nRETRYing...")
                Sys.sleep(1)
            }
        }
        else {
            nc_retry <- F
        }
    }
    i_req <- i_req + 1
}
debug: i_t_beg <- (i_req - 1) * n_t_per_req + 1
debug: i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
debug: t_req <- times_todo[c(i_t_beg, i_t_end)]
debug: t_req_str <- format_ISO8601(t_req, usetz = "Z")
debug: if (verbose) message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
debug: message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
Fetching request 1 of 1 (2013-01-01 to 2013-12-01) ~ 19:33:44 UTC
debug: ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
    0), nc)
debug: unlink(ncs0)
debug: nc_retry <- T
debug: nc_n_try <- 1
debug: n_max_retries
debug: while (nc_retry) {
    res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
        url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
            bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
        time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
    if (inherits(res, "try-error")) {
        err <- attr(res, "condition")
        msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
        nc_n_try <- nc_n_try + 1
        if (nc_n_try > n_max_retries) {
            stop(msg)
        }
        else {
            message(msg, "\nRETRYing...")
            Sys.sleep(1)
        }
    }
    else {
        nc_retry <- F
    }
}
debug: res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
    url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
        bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
    time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
debug: if (inherits(res, "try-error")) {
    err <- attr(res, "condition")
    msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
    nc_n_try <- nc_n_try + 1
    if (nc_n_try > n_max_retries) {
        stop(msg)
    }
    else {
        message(msg, "\nRETRYing...")
        Sys.sleep(1)
    }
} else {
    nc_retry <- F
}
debug: nc_retry <- F
debug: (while) nc_retry
debug: i_req <- i_req + 1
debug: (while) i_req <= n_reqs
debug: ncs <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size > 
    0), nc)
debug: r <- terra::rast(ncs)
debug: stopifnot(all(class(terra::time(r)) %in% c("POSIXct", "POSIXt")))
debug: idx <- dplyr::pull(dplyr::filter(dplyr::arrange(dplyr::tibble(idx = 1:terra::nlyr(r), 
    time = terra::time(r)), time), !duplicated(time)), idx)
debug: r <- terra::subset(r, idx)
debug: stopifnot(terra::crs(r, proj = T) == wgs84)
debug: if (mask_tif) r <- terra::mask(r, sf_zones)
debug: lyrs <- glue("{var}|{terra::time(r)}")
debug: if (length(dims_other) > 0 && !all(length(dims[dims_other]) == 
    1)) stop(glue("Other dimensions not yet supported: {paste(dims_other, collapse = ',')}"))
debug: names(r) <- lyrs
debug: if (!is.null(rast_tif)) {
    if (fs::file_exists(rast_tif)) {
        r_tmp_tif <- tempfile(fileext = ".tif")
        r_tmp <- c(rast(rast_tif), r)
        r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
        terra::writeRaster(r_tmp, r_tmp_tif)
        fs::file_delete(rast_tif)
        fs::file_move(r_tmp_tif, rast_tif)
        rm(r)
        rm(r_tmp)
    }
    else {
        terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
    }
    r <- terra::rast(rast_tif)
}
debug: if (fs::file_exists(rast_tif)) {
    r_tmp_tif <- tempfile(fileext = ".tif")
    r_tmp <- c(rast(rast_tif), r)
    r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
    terra::writeRaster(r_tmp, r_tmp_tif)
    fs::file_delete(rast_tif)
    fs::file_move(r_tmp_tif, rast_tif)
    rm(r)
    rm(r_tmp)
} else {
    terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
}
debug: terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
debug: r <- terra::rast(rast_tif)
debug: d_r <- mutate(tidyr::pivot_longer(sf::st_drop_geometry(sf::st_as_sf(terra::zonal(x = r, 
    z = terra::vect(dplyr::select(sf_zones, dplyr::all_of(fld_zones))), 
    fun = zonal_fun, exact = T, na.rm = T, as.polygons = T))), 
    cols = -dplyr::any_of(fld_zones), names_to = "lyr", values_to = zonal_fun), 
    time = readr::parse_datetime(str_replace(lyr, glue("{var}\\|(.*)"), 
        "\\1")))
debug: if (!is.null(zonal_csv)) write_csv(d_r, zonal_csv)
debug: write_csv(d_r, zonal_csv)
debug: if (!keep_nc) unlink(dir_nc, recursive = T)
debug: unlink(dir_nc, recursive = T)
debug: return(d_r)
Downloading 1 requests, up to 148 time slices each
Called from: extractr::ed_extract(ed, var = v, sf_zones = ply, bbox = bb, 
    mask_tif = F, rast_tif = glue("{dir_out}/{nms}/{yr}.tif"), 
    zonal_fun = "mean", zonal_csv = glue("{dir_out}/{nms}/{yr}.csv"), 
    dir_nc = glue("{dir_out}/{nms}/{yr}_nc"), keep_nc = F, n_max_vals_per_req = 1e+05, 
    time_min = time_min, time_max = time_max, verbose = T)
debug: while (i_req <= n_reqs) {
    i_t_beg <- (i_req - 1) * n_t_per_req + 1
    i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
    t_req <- times_todo[c(i_t_beg, i_t_end)]
    t_req_str <- format_ISO8601(t_req, usetz = "Z")
    if (verbose) 
        message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
    ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
        ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
        0), nc)
    unlink(ncs0)
    nc_retry <- T
    nc_n_try <- 1
    n_max_retries
    while (nc_retry) {
        res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
            url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
                bbox[["xmax"]]), latitude = c(bbox[["ymin"]], 
                bbox[["ymax"]]), time = t_req_str, fmt = "nc", 
            store = rerddap::disk(path = dir_nc)))
        if (inherits(res, "try-error")) {
            err <- attr(res, "condition")
            msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
            nc_n_try <- nc_n_try + 1
            if (nc_n_try > n_max_retries) {
                stop(msg)
            }
            else {
                message(msg, "\nRETRYing...")
                Sys.sleep(1)
            }
        }
        else {
            nc_retry <- F
        }
    }
    i_req <- i_req + 1
}
debug: i_t_beg <- (i_req - 1) * n_t_per_req + 1
debug: i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
debug: t_req <- times_todo[c(i_t_beg, i_t_end)]
debug: t_req_str <- format_ISO8601(t_req, usetz = "Z")
debug: if (verbose) message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
debug: message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
Fetching request 1 of 1 (2014-01-01 to 2014-12-01) ~ 19:33:47 UTC
debug: ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
    0), nc)
debug: unlink(ncs0)
debug: nc_retry <- T
debug: nc_n_try <- 1
debug: n_max_retries
debug: while (nc_retry) {
    res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
        url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
            bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
        time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
    if (inherits(res, "try-error")) {
        err <- attr(res, "condition")
        msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
        nc_n_try <- nc_n_try + 1
        if (nc_n_try > n_max_retries) {
            stop(msg)
        }
        else {
            message(msg, "\nRETRYing...")
            Sys.sleep(1)
        }
    }
    else {
        nc_retry <- F
    }
}
debug: res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
    url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
        bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
    time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
debug: if (inherits(res, "try-error")) {
    err <- attr(res, "condition")
    msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
    nc_n_try <- nc_n_try + 1
    if (nc_n_try > n_max_retries) {
        stop(msg)
    }
    else {
        message(msg, "\nRETRYing...")
        Sys.sleep(1)
    }
} else {
    nc_retry <- F
}
debug: nc_retry <- F
debug: (while) nc_retry
debug: i_req <- i_req + 1
debug: (while) i_req <= n_reqs
debug: ncs <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size > 
    0), nc)
debug: r <- terra::rast(ncs)
debug: stopifnot(all(class(terra::time(r)) %in% c("POSIXct", "POSIXt")))
debug: idx <- dplyr::pull(dplyr::filter(dplyr::arrange(dplyr::tibble(idx = 1:terra::nlyr(r), 
    time = terra::time(r)), time), !duplicated(time)), idx)
debug: r <- terra::subset(r, idx)
debug: stopifnot(terra::crs(r, proj = T) == wgs84)
debug: if (mask_tif) r <- terra::mask(r, sf_zones)
debug: lyrs <- glue("{var}|{terra::time(r)}")
debug: if (length(dims_other) > 0 && !all(length(dims[dims_other]) == 
    1)) stop(glue("Other dimensions not yet supported: {paste(dims_other, collapse = ',')}"))
debug: names(r) <- lyrs
debug: if (!is.null(rast_tif)) {
    if (fs::file_exists(rast_tif)) {
        r_tmp_tif <- tempfile(fileext = ".tif")
        r_tmp <- c(rast(rast_tif), r)
        r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
        terra::writeRaster(r_tmp, r_tmp_tif)
        fs::file_delete(rast_tif)
        fs::file_move(r_tmp_tif, rast_tif)
        rm(r)
        rm(r_tmp)
    }
    else {
        terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
    }
    r <- terra::rast(rast_tif)
}
debug: if (fs::file_exists(rast_tif)) {
    r_tmp_tif <- tempfile(fileext = ".tif")
    r_tmp <- c(rast(rast_tif), r)
    r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
    terra::writeRaster(r_tmp, r_tmp_tif)
    fs::file_delete(rast_tif)
    fs::file_move(r_tmp_tif, rast_tif)
    rm(r)
    rm(r_tmp)
} else {
    terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
}
debug: terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
debug: r <- terra::rast(rast_tif)
debug: d_r <- mutate(tidyr::pivot_longer(sf::st_drop_geometry(sf::st_as_sf(terra::zonal(x = r, 
    z = terra::vect(dplyr::select(sf_zones, dplyr::all_of(fld_zones))), 
    fun = zonal_fun, exact = T, na.rm = T, as.polygons = T))), 
    cols = -dplyr::any_of(fld_zones), names_to = "lyr", values_to = zonal_fun), 
    time = readr::parse_datetime(str_replace(lyr, glue("{var}\\|(.*)"), 
        "\\1")))
debug: if (!is.null(zonal_csv)) write_csv(d_r, zonal_csv)
debug: write_csv(d_r, zonal_csv)
debug: if (!keep_nc) unlink(dir_nc, recursive = T)
debug: unlink(dir_nc, recursive = T)
debug: return(d_r)
Downloading 1 requests, up to 148 time slices each
Called from: extractr::ed_extract(ed, var = v, sf_zones = ply, bbox = bb, 
    mask_tif = F, rast_tif = glue("{dir_out}/{nms}/{yr}.tif"), 
    zonal_fun = "mean", zonal_csv = glue("{dir_out}/{nms}/{yr}.csv"), 
    dir_nc = glue("{dir_out}/{nms}/{yr}_nc"), keep_nc = F, n_max_vals_per_req = 1e+05, 
    time_min = time_min, time_max = time_max, verbose = T)
debug: while (i_req <= n_reqs) {
    i_t_beg <- (i_req - 1) * n_t_per_req + 1
    i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
    t_req <- times_todo[c(i_t_beg, i_t_end)]
    t_req_str <- format_ISO8601(t_req, usetz = "Z")
    if (verbose) 
        message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
    ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
        ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
        0), nc)
    unlink(ncs0)
    nc_retry <- T
    nc_n_try <- 1
    n_max_retries
    while (nc_retry) {
        res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
            url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
                bbox[["xmax"]]), latitude = c(bbox[["ymin"]], 
                bbox[["ymax"]]), time = t_req_str, fmt = "nc", 
            store = rerddap::disk(path = dir_nc)))
        if (inherits(res, "try-error")) {
            err <- attr(res, "condition")
            msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
            nc_n_try <- nc_n_try + 1
            if (nc_n_try > n_max_retries) {
                stop(msg)
            }
            else {
                message(msg, "\nRETRYing...")
                Sys.sleep(1)
            }
        }
        else {
            nc_retry <- F
        }
    }
    i_req <- i_req + 1
}
debug: i_t_beg <- (i_req - 1) * n_t_per_req + 1
debug: i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
debug: t_req <- times_todo[c(i_t_beg, i_t_end)]
debug: t_req_str <- format_ISO8601(t_req, usetz = "Z")
debug: if (verbose) message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
debug: message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
Fetching request 1 of 1 (2015-01-01 to 2015-12-01) ~ 19:33:50 UTC
debug: ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
    0), nc)
debug: unlink(ncs0)
debug: nc_retry <- T
debug: nc_n_try <- 1
debug: n_max_retries
debug: while (nc_retry) {
    res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
        url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
            bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
        time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
    if (inherits(res, "try-error")) {
        err <- attr(res, "condition")
        msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
        nc_n_try <- nc_n_try + 1
        if (nc_n_try > n_max_retries) {
            stop(msg)
        }
        else {
            message(msg, "\nRETRYing...")
            Sys.sleep(1)
        }
    }
    else {
        nc_retry <- F
    }
}
debug: res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
    url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
        bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
    time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
debug: if (inherits(res, "try-error")) {
    err <- attr(res, "condition")
    msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
    nc_n_try <- nc_n_try + 1
    if (nc_n_try > n_max_retries) {
        stop(msg)
    }
    else {
        message(msg, "\nRETRYing...")
        Sys.sleep(1)
    }
} else {
    nc_retry <- F
}
debug: nc_retry <- F
debug: (while) nc_retry
debug: i_req <- i_req + 1
debug: (while) i_req <= n_reqs
debug: ncs <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size > 
    0), nc)
debug: r <- terra::rast(ncs)
debug: stopifnot(all(class(terra::time(r)) %in% c("POSIXct", "POSIXt")))
debug: idx <- dplyr::pull(dplyr::filter(dplyr::arrange(dplyr::tibble(idx = 1:terra::nlyr(r), 
    time = terra::time(r)), time), !duplicated(time)), idx)
debug: r <- terra::subset(r, idx)
debug: stopifnot(terra::crs(r, proj = T) == wgs84)
debug: if (mask_tif) r <- terra::mask(r, sf_zones)
debug: lyrs <- glue("{var}|{terra::time(r)}")
debug: if (length(dims_other) > 0 && !all(length(dims[dims_other]) == 
    1)) stop(glue("Other dimensions not yet supported: {paste(dims_other, collapse = ',')}"))
debug: names(r) <- lyrs
debug: if (!is.null(rast_tif)) {
    if (fs::file_exists(rast_tif)) {
        r_tmp_tif <- tempfile(fileext = ".tif")
        r_tmp <- c(rast(rast_tif), r)
        r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
        terra::writeRaster(r_tmp, r_tmp_tif)
        fs::file_delete(rast_tif)
        fs::file_move(r_tmp_tif, rast_tif)
        rm(r)
        rm(r_tmp)
    }
    else {
        terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
    }
    r <- terra::rast(rast_tif)
}
debug: if (fs::file_exists(rast_tif)) {
    r_tmp_tif <- tempfile(fileext = ".tif")
    r_tmp <- c(rast(rast_tif), r)
    r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
    terra::writeRaster(r_tmp, r_tmp_tif)
    fs::file_delete(rast_tif)
    fs::file_move(r_tmp_tif, rast_tif)
    rm(r)
    rm(r_tmp)
} else {
    terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
}
debug: terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
debug: r <- terra::rast(rast_tif)
debug: d_r <- mutate(tidyr::pivot_longer(sf::st_drop_geometry(sf::st_as_sf(terra::zonal(x = r, 
    z = terra::vect(dplyr::select(sf_zones, dplyr::all_of(fld_zones))), 
    fun = zonal_fun, exact = T, na.rm = T, as.polygons = T))), 
    cols = -dplyr::any_of(fld_zones), names_to = "lyr", values_to = zonal_fun), 
    time = readr::parse_datetime(str_replace(lyr, glue("{var}\\|(.*)"), 
        "\\1")))
debug: if (!is.null(zonal_csv)) write_csv(d_r, zonal_csv)
debug: write_csv(d_r, zonal_csv)
debug: if (!keep_nc) unlink(dir_nc, recursive = T)
debug: unlink(dir_nc, recursive = T)
debug: return(d_r)
Downloading 1 requests, up to 148 time slices each
Called from: extractr::ed_extract(ed, var = v, sf_zones = ply, bbox = bb, 
    mask_tif = F, rast_tif = glue("{dir_out}/{nms}/{yr}.tif"), 
    zonal_fun = "mean", zonal_csv = glue("{dir_out}/{nms}/{yr}.csv"), 
    dir_nc = glue("{dir_out}/{nms}/{yr}_nc"), keep_nc = F, n_max_vals_per_req = 1e+05, 
    time_min = time_min, time_max = time_max, verbose = T)
debug: while (i_req <= n_reqs) {
    i_t_beg <- (i_req - 1) * n_t_per_req + 1
    i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
    t_req <- times_todo[c(i_t_beg, i_t_end)]
    t_req_str <- format_ISO8601(t_req, usetz = "Z")
    if (verbose) 
        message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
    ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
        ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
        0), nc)
    unlink(ncs0)
    nc_retry <- T
    nc_n_try <- 1
    n_max_retries
    while (nc_retry) {
        res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
            url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
                bbox[["xmax"]]), latitude = c(bbox[["ymin"]], 
                bbox[["ymax"]]), time = t_req_str, fmt = "nc", 
            store = rerddap::disk(path = dir_nc)))
        if (inherits(res, "try-error")) {
            err <- attr(res, "condition")
            msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
            nc_n_try <- nc_n_try + 1
            if (nc_n_try > n_max_retries) {
                stop(msg)
            }
            else {
                message(msg, "\nRETRYing...")
                Sys.sleep(1)
            }
        }
        else {
            nc_retry <- F
        }
    }
    i_req <- i_req + 1
}
debug: i_t_beg <- (i_req - 1) * n_t_per_req + 1
debug: i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
debug: t_req <- times_todo[c(i_t_beg, i_t_end)]
debug: t_req_str <- format_ISO8601(t_req, usetz = "Z")
debug: if (verbose) message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
debug: message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
Fetching request 1 of 1 (2016-01-01 to 2016-12-01) ~ 19:33:53 UTC
debug: ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
    0), nc)
debug: unlink(ncs0)
debug: nc_retry <- T
debug: nc_n_try <- 1
debug: n_max_retries
debug: while (nc_retry) {
    res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
        url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
            bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
        time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
    if (inherits(res, "try-error")) {
        err <- attr(res, "condition")
        msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
        nc_n_try <- nc_n_try + 1
        if (nc_n_try > n_max_retries) {
            stop(msg)
        }
        else {
            message(msg, "\nRETRYing...")
            Sys.sleep(1)
        }
    }
    else {
        nc_retry <- F
    }
}
debug: res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
    url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
        bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
    time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
debug: if (inherits(res, "try-error")) {
    err <- attr(res, "condition")
    msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
    nc_n_try <- nc_n_try + 1
    if (nc_n_try > n_max_retries) {
        stop(msg)
    }
    else {
        message(msg, "\nRETRYing...")
        Sys.sleep(1)
    }
} else {
    nc_retry <- F
}
debug: nc_retry <- F
debug: (while) nc_retry
debug: i_req <- i_req + 1
debug: (while) i_req <= n_reqs
debug: ncs <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size > 
    0), nc)
debug: r <- terra::rast(ncs)
debug: stopifnot(all(class(terra::time(r)) %in% c("POSIXct", "POSIXt")))
debug: idx <- dplyr::pull(dplyr::filter(dplyr::arrange(dplyr::tibble(idx = 1:terra::nlyr(r), 
    time = terra::time(r)), time), !duplicated(time)), idx)
debug: r <- terra::subset(r, idx)
debug: stopifnot(terra::crs(r, proj = T) == wgs84)
debug: if (mask_tif) r <- terra::mask(r, sf_zones)
debug: lyrs <- glue("{var}|{terra::time(r)}")
debug: if (length(dims_other) > 0 && !all(length(dims[dims_other]) == 
    1)) stop(glue("Other dimensions not yet supported: {paste(dims_other, collapse = ',')}"))
debug: names(r) <- lyrs
debug: if (!is.null(rast_tif)) {
    if (fs::file_exists(rast_tif)) {
        r_tmp_tif <- tempfile(fileext = ".tif")
        r_tmp <- c(rast(rast_tif), r)
        r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
        terra::writeRaster(r_tmp, r_tmp_tif)
        fs::file_delete(rast_tif)
        fs::file_move(r_tmp_tif, rast_tif)
        rm(r)
        rm(r_tmp)
    }
    else {
        terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
    }
    r <- terra::rast(rast_tif)
}
debug: if (fs::file_exists(rast_tif)) {
    r_tmp_tif <- tempfile(fileext = ".tif")
    r_tmp <- c(rast(rast_tif), r)
    r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
    terra::writeRaster(r_tmp, r_tmp_tif)
    fs::file_delete(rast_tif)
    fs::file_move(r_tmp_tif, rast_tif)
    rm(r)
    rm(r_tmp)
} else {
    terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
}
debug: terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
debug: r <- terra::rast(rast_tif)
debug: d_r <- mutate(tidyr::pivot_longer(sf::st_drop_geometry(sf::st_as_sf(terra::zonal(x = r, 
    z = terra::vect(dplyr::select(sf_zones, dplyr::all_of(fld_zones))), 
    fun = zonal_fun, exact = T, na.rm = T, as.polygons = T))), 
    cols = -dplyr::any_of(fld_zones), names_to = "lyr", values_to = zonal_fun), 
    time = readr::parse_datetime(str_replace(lyr, glue("{var}\\|(.*)"), 
        "\\1")))
debug: if (!is.null(zonal_csv)) write_csv(d_r, zonal_csv)
debug: write_csv(d_r, zonal_csv)
debug: if (!keep_nc) unlink(dir_nc, recursive = T)
debug: unlink(dir_nc, recursive = T)
debug: return(d_r)
Downloading 1 requests, up to 148 time slices each
Called from: extractr::ed_extract(ed, var = v, sf_zones = ply, bbox = bb, 
    mask_tif = F, rast_tif = glue("{dir_out}/{nms}/{yr}.tif"), 
    zonal_fun = "mean", zonal_csv = glue("{dir_out}/{nms}/{yr}.csv"), 
    dir_nc = glue("{dir_out}/{nms}/{yr}_nc"), keep_nc = F, n_max_vals_per_req = 1e+05, 
    time_min = time_min, time_max = time_max, verbose = T)
debug: while (i_req <= n_reqs) {
    i_t_beg <- (i_req - 1) * n_t_per_req + 1
    i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
    t_req <- times_todo[c(i_t_beg, i_t_end)]
    t_req_str <- format_ISO8601(t_req, usetz = "Z")
    if (verbose) 
        message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
    ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
        ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
        0), nc)
    unlink(ncs0)
    nc_retry <- T
    nc_n_try <- 1
    n_max_retries
    while (nc_retry) {
        res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
            url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
                bbox[["xmax"]]), latitude = c(bbox[["ymin"]], 
                bbox[["ymax"]]), time = t_req_str, fmt = "nc", 
            store = rerddap::disk(path = dir_nc)))
        if (inherits(res, "try-error")) {
            err <- attr(res, "condition")
            msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
            nc_n_try <- nc_n_try + 1
            if (nc_n_try > n_max_retries) {
                stop(msg)
            }
            else {
                message(msg, "\nRETRYing...")
                Sys.sleep(1)
            }
        }
        else {
            nc_retry <- F
        }
    }
    i_req <- i_req + 1
}
debug: i_t_beg <- (i_req - 1) * n_t_per_req + 1
debug: i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
debug: t_req <- times_todo[c(i_t_beg, i_t_end)]
debug: t_req_str <- format_ISO8601(t_req, usetz = "Z")
debug: if (verbose) message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
debug: message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
Fetching request 1 of 1 (2017-01-01 to 2017-12-01) ~ 19:33:56 UTC
debug: ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
    0), nc)
debug: unlink(ncs0)
debug: nc_retry <- T
debug: nc_n_try <- 1
debug: n_max_retries
debug: while (nc_retry) {
    res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
        url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
            bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
        time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
    if (inherits(res, "try-error")) {
        err <- attr(res, "condition")
        msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
        nc_n_try <- nc_n_try + 1
        if (nc_n_try > n_max_retries) {
            stop(msg)
        }
        else {
            message(msg, "\nRETRYing...")
            Sys.sleep(1)
        }
    }
    else {
        nc_retry <- F
    }
}
debug: res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
    url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
        bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
    time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
debug: if (inherits(res, "try-error")) {
    err <- attr(res, "condition")
    msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
    nc_n_try <- nc_n_try + 1
    if (nc_n_try > n_max_retries) {
        stop(msg)
    }
    else {
        message(msg, "\nRETRYing...")
        Sys.sleep(1)
    }
} else {
    nc_retry <- F
}
debug: nc_retry <- F
debug: (while) nc_retry
debug: i_req <- i_req + 1
debug: (while) i_req <= n_reqs
debug: ncs <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size > 
    0), nc)
debug: r <- terra::rast(ncs)
debug: stopifnot(all(class(terra::time(r)) %in% c("POSIXct", "POSIXt")))
debug: idx <- dplyr::pull(dplyr::filter(dplyr::arrange(dplyr::tibble(idx = 1:terra::nlyr(r), 
    time = terra::time(r)), time), !duplicated(time)), idx)
debug: r <- terra::subset(r, idx)
debug: stopifnot(terra::crs(r, proj = T) == wgs84)
debug: if (mask_tif) r <- terra::mask(r, sf_zones)
debug: lyrs <- glue("{var}|{terra::time(r)}")
debug: if (length(dims_other) > 0 && !all(length(dims[dims_other]) == 
    1)) stop(glue("Other dimensions not yet supported: {paste(dims_other, collapse = ',')}"))
debug: names(r) <- lyrs
debug: if (!is.null(rast_tif)) {
    if (fs::file_exists(rast_tif)) {
        r_tmp_tif <- tempfile(fileext = ".tif")
        r_tmp <- c(rast(rast_tif), r)
        r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
        terra::writeRaster(r_tmp, r_tmp_tif)
        fs::file_delete(rast_tif)
        fs::file_move(r_tmp_tif, rast_tif)
        rm(r)
        rm(r_tmp)
    }
    else {
        terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
    }
    r <- terra::rast(rast_tif)
}
debug: if (fs::file_exists(rast_tif)) {
    r_tmp_tif <- tempfile(fileext = ".tif")
    r_tmp <- c(rast(rast_tif), r)
    r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
    terra::writeRaster(r_tmp, r_tmp_tif)
    fs::file_delete(rast_tif)
    fs::file_move(r_tmp_tif, rast_tif)
    rm(r)
    rm(r_tmp)
} else {
    terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
}
debug: terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
debug: r <- terra::rast(rast_tif)
debug: d_r <- mutate(tidyr::pivot_longer(sf::st_drop_geometry(sf::st_as_sf(terra::zonal(x = r, 
    z = terra::vect(dplyr::select(sf_zones, dplyr::all_of(fld_zones))), 
    fun = zonal_fun, exact = T, na.rm = T, as.polygons = T))), 
    cols = -dplyr::any_of(fld_zones), names_to = "lyr", values_to = zonal_fun), 
    time = readr::parse_datetime(str_replace(lyr, glue("{var}\\|(.*)"), 
        "\\1")))
debug: if (!is.null(zonal_csv)) write_csv(d_r, zonal_csv)
debug: write_csv(d_r, zonal_csv)
debug: if (!keep_nc) unlink(dir_nc, recursive = T)
debug: unlink(dir_nc, recursive = T)
debug: return(d_r)
Downloading 1 requests, up to 148 time slices each
Called from: extractr::ed_extract(ed, var = v, sf_zones = ply, bbox = bb, 
    mask_tif = F, rast_tif = glue("{dir_out}/{nms}/{yr}.tif"), 
    zonal_fun = "mean", zonal_csv = glue("{dir_out}/{nms}/{yr}.csv"), 
    dir_nc = glue("{dir_out}/{nms}/{yr}_nc"), keep_nc = F, n_max_vals_per_req = 1e+05, 
    time_min = time_min, time_max = time_max, verbose = T)
debug: while (i_req <= n_reqs) {
    i_t_beg <- (i_req - 1) * n_t_per_req + 1
    i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
    t_req <- times_todo[c(i_t_beg, i_t_end)]
    t_req_str <- format_ISO8601(t_req, usetz = "Z")
    if (verbose) 
        message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
    ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
        ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
        0), nc)
    unlink(ncs0)
    nc_retry <- T
    nc_n_try <- 1
    n_max_retries
    while (nc_retry) {
        res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
            url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
                bbox[["xmax"]]), latitude = c(bbox[["ymin"]], 
                bbox[["ymax"]]), time = t_req_str, fmt = "nc", 
            store = rerddap::disk(path = dir_nc)))
        if (inherits(res, "try-error")) {
            err <- attr(res, "condition")
            msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
            nc_n_try <- nc_n_try + 1
            if (nc_n_try > n_max_retries) {
                stop(msg)
            }
            else {
                message(msg, "\nRETRYing...")
                Sys.sleep(1)
            }
        }
        else {
            nc_retry <- F
        }
    }
    i_req <- i_req + 1
}
debug: i_t_beg <- (i_req - 1) * n_t_per_req + 1
debug: i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
debug: t_req <- times_todo[c(i_t_beg, i_t_end)]
debug: t_req_str <- format_ISO8601(t_req, usetz = "Z")
debug: if (verbose) message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
debug: message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
Fetching request 1 of 1 (2018-01-01 to 2018-12-01) ~ 19:33:59 UTC
debug: ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
    0), nc)
debug: unlink(ncs0)
debug: nc_retry <- T
debug: nc_n_try <- 1
debug: n_max_retries
debug: while (nc_retry) {
    res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
        url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
            bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
        time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
    if (inherits(res, "try-error")) {
        err <- attr(res, "condition")
        msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
        nc_n_try <- nc_n_try + 1
        if (nc_n_try > n_max_retries) {
            stop(msg)
        }
        else {
            message(msg, "\nRETRYing...")
            Sys.sleep(1)
        }
    }
    else {
        nc_retry <- F
    }
}
debug: res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
    url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
        bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
    time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
debug: if (inherits(res, "try-error")) {
    err <- attr(res, "condition")
    msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
    nc_n_try <- nc_n_try + 1
    if (nc_n_try > n_max_retries) {
        stop(msg)
    }
    else {
        message(msg, "\nRETRYing...")
        Sys.sleep(1)
    }
} else {
    nc_retry <- F
}
debug: nc_retry <- F
debug: (while) nc_retry
debug: i_req <- i_req + 1
debug: (while) i_req <= n_reqs
debug: ncs <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size > 
    0), nc)
debug: r <- terra::rast(ncs)
debug: stopifnot(all(class(terra::time(r)) %in% c("POSIXct", "POSIXt")))
debug: idx <- dplyr::pull(dplyr::filter(dplyr::arrange(dplyr::tibble(idx = 1:terra::nlyr(r), 
    time = terra::time(r)), time), !duplicated(time)), idx)
debug: r <- terra::subset(r, idx)
debug: stopifnot(terra::crs(r, proj = T) == wgs84)
debug: if (mask_tif) r <- terra::mask(r, sf_zones)
debug: lyrs <- glue("{var}|{terra::time(r)}")
debug: if (length(dims_other) > 0 && !all(length(dims[dims_other]) == 
    1)) stop(glue("Other dimensions not yet supported: {paste(dims_other, collapse = ',')}"))
debug: names(r) <- lyrs
debug: if (!is.null(rast_tif)) {
    if (fs::file_exists(rast_tif)) {
        r_tmp_tif <- tempfile(fileext = ".tif")
        r_tmp <- c(rast(rast_tif), r)
        r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
        terra::writeRaster(r_tmp, r_tmp_tif)
        fs::file_delete(rast_tif)
        fs::file_move(r_tmp_tif, rast_tif)
        rm(r)
        rm(r_tmp)
    }
    else {
        terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
    }
    r <- terra::rast(rast_tif)
}
debug: if (fs::file_exists(rast_tif)) {
    r_tmp_tif <- tempfile(fileext = ".tif")
    r_tmp <- c(rast(rast_tif), r)
    r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
    terra::writeRaster(r_tmp, r_tmp_tif)
    fs::file_delete(rast_tif)
    fs::file_move(r_tmp_tif, rast_tif)
    rm(r)
    rm(r_tmp)
} else {
    terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
}
debug: terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
debug: r <- terra::rast(rast_tif)
debug: d_r <- mutate(tidyr::pivot_longer(sf::st_drop_geometry(sf::st_as_sf(terra::zonal(x = r, 
    z = terra::vect(dplyr::select(sf_zones, dplyr::all_of(fld_zones))), 
    fun = zonal_fun, exact = T, na.rm = T, as.polygons = T))), 
    cols = -dplyr::any_of(fld_zones), names_to = "lyr", values_to = zonal_fun), 
    time = readr::parse_datetime(str_replace(lyr, glue("{var}\\|(.*)"), 
        "\\1")))
debug: if (!is.null(zonal_csv)) write_csv(d_r, zonal_csv)
debug: write_csv(d_r, zonal_csv)
debug: if (!keep_nc) unlink(dir_nc, recursive = T)
debug: unlink(dir_nc, recursive = T)
debug: return(d_r)
Downloading 1 requests, up to 148 time slices each
Called from: extractr::ed_extract(ed, var = v, sf_zones = ply, bbox = bb, 
    mask_tif = F, rast_tif = glue("{dir_out}/{nms}/{yr}.tif"), 
    zonal_fun = "mean", zonal_csv = glue("{dir_out}/{nms}/{yr}.csv"), 
    dir_nc = glue("{dir_out}/{nms}/{yr}_nc"), keep_nc = F, n_max_vals_per_req = 1e+05, 
    time_min = time_min, time_max = time_max, verbose = T)
debug: while (i_req <= n_reqs) {
    i_t_beg <- (i_req - 1) * n_t_per_req + 1
    i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
    t_req <- times_todo[c(i_t_beg, i_t_end)]
    t_req_str <- format_ISO8601(t_req, usetz = "Z")
    if (verbose) 
        message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
    ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
        ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
        0), nc)
    unlink(ncs0)
    nc_retry <- T
    nc_n_try <- 1
    n_max_retries
    while (nc_retry) {
        res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
            url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
                bbox[["xmax"]]), latitude = c(bbox[["ymin"]], 
                bbox[["ymax"]]), time = t_req_str, fmt = "nc", 
            store = rerddap::disk(path = dir_nc)))
        if (inherits(res, "try-error")) {
            err <- attr(res, "condition")
            msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
            nc_n_try <- nc_n_try + 1
            if (nc_n_try > n_max_retries) {
                stop(msg)
            }
            else {
                message(msg, "\nRETRYing...")
                Sys.sleep(1)
            }
        }
        else {
            nc_retry <- F
        }
    }
    i_req <- i_req + 1
}
debug: i_t_beg <- (i_req - 1) * n_t_per_req + 1
debug: i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
debug: t_req <- times_todo[c(i_t_beg, i_t_end)]
debug: t_req_str <- format_ISO8601(t_req, usetz = "Z")
debug: if (verbose) message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
debug: message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
Fetching request 1 of 1 (2019-01-01 to 2019-12-01) ~ 19:34:02 UTC
debug: ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
    0), nc)
debug: unlink(ncs0)
debug: nc_retry <- T
debug: nc_n_try <- 1
debug: n_max_retries
debug: while (nc_retry) {
    res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
        url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
            bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
        time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
    if (inherits(res, "try-error")) {
        err <- attr(res, "condition")
        msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
        nc_n_try <- nc_n_try + 1
        if (nc_n_try > n_max_retries) {
            stop(msg)
        }
        else {
            message(msg, "\nRETRYing...")
            Sys.sleep(1)
        }
    }
    else {
        nc_retry <- F
    }
}
debug: res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
    url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
        bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
    time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
debug: if (inherits(res, "try-error")) {
    err <- attr(res, "condition")
    msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
    nc_n_try <- nc_n_try + 1
    if (nc_n_try > n_max_retries) {
        stop(msg)
    }
    else {
        message(msg, "\nRETRYing...")
        Sys.sleep(1)
    }
} else {
    nc_retry <- F
}
debug: nc_retry <- F
debug: (while) nc_retry
debug: i_req <- i_req + 1
debug: (while) i_req <= n_reqs
debug: ncs <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size > 
    0), nc)
debug: r <- terra::rast(ncs)
debug: stopifnot(all(class(terra::time(r)) %in% c("POSIXct", "POSIXt")))
debug: idx <- dplyr::pull(dplyr::filter(dplyr::arrange(dplyr::tibble(idx = 1:terra::nlyr(r), 
    time = terra::time(r)), time), !duplicated(time)), idx)
debug: r <- terra::subset(r, idx)
debug: stopifnot(terra::crs(r, proj = T) == wgs84)
debug: if (mask_tif) r <- terra::mask(r, sf_zones)
debug: lyrs <- glue("{var}|{terra::time(r)}")
debug: if (length(dims_other) > 0 && !all(length(dims[dims_other]) == 
    1)) stop(glue("Other dimensions not yet supported: {paste(dims_other, collapse = ',')}"))
debug: names(r) <- lyrs
debug: if (!is.null(rast_tif)) {
    if (fs::file_exists(rast_tif)) {
        r_tmp_tif <- tempfile(fileext = ".tif")
        r_tmp <- c(rast(rast_tif), r)
        r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
        terra::writeRaster(r_tmp, r_tmp_tif)
        fs::file_delete(rast_tif)
        fs::file_move(r_tmp_tif, rast_tif)
        rm(r)
        rm(r_tmp)
    }
    else {
        terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
    }
    r <- terra::rast(rast_tif)
}
debug: if (fs::file_exists(rast_tif)) {
    r_tmp_tif <- tempfile(fileext = ".tif")
    r_tmp <- c(rast(rast_tif), r)
    r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
    terra::writeRaster(r_tmp, r_tmp_tif)
    fs::file_delete(rast_tif)
    fs::file_move(r_tmp_tif, rast_tif)
    rm(r)
    rm(r_tmp)
} else {
    terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
}
debug: terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
debug: r <- terra::rast(rast_tif)
debug: d_r <- mutate(tidyr::pivot_longer(sf::st_drop_geometry(sf::st_as_sf(terra::zonal(x = r, 
    z = terra::vect(dplyr::select(sf_zones, dplyr::all_of(fld_zones))), 
    fun = zonal_fun, exact = T, na.rm = T, as.polygons = T))), 
    cols = -dplyr::any_of(fld_zones), names_to = "lyr", values_to = zonal_fun), 
    time = readr::parse_datetime(str_replace(lyr, glue("{var}\\|(.*)"), 
        "\\1")))
debug: if (!is.null(zonal_csv)) write_csv(d_r, zonal_csv)
debug: write_csv(d_r, zonal_csv)
debug: if (!keep_nc) unlink(dir_nc, recursive = T)
debug: unlink(dir_nc, recursive = T)
debug: return(d_r)
Downloading 1 requests, up to 148 time slices each
Called from: extractr::ed_extract(ed, var = v, sf_zones = ply, bbox = bb, 
    mask_tif = F, rast_tif = glue("{dir_out}/{nms}/{yr}.tif"), 
    zonal_fun = "mean", zonal_csv = glue("{dir_out}/{nms}/{yr}.csv"), 
    dir_nc = glue("{dir_out}/{nms}/{yr}_nc"), keep_nc = F, n_max_vals_per_req = 1e+05, 
    time_min = time_min, time_max = time_max, verbose = T)
debug: while (i_req <= n_reqs) {
    i_t_beg <- (i_req - 1) * n_t_per_req + 1
    i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
    t_req <- times_todo[c(i_t_beg, i_t_end)]
    t_req_str <- format_ISO8601(t_req, usetz = "Z")
    if (verbose) 
        message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
    ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
        ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
        0), nc)
    unlink(ncs0)
    nc_retry <- T
    nc_n_try <- 1
    n_max_retries
    while (nc_retry) {
        res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
            url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
                bbox[["xmax"]]), latitude = c(bbox[["ymin"]], 
                bbox[["ymax"]]), time = t_req_str, fmt = "nc", 
            store = rerddap::disk(path = dir_nc)))
        if (inherits(res, "try-error")) {
            err <- attr(res, "condition")
            msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
            nc_n_try <- nc_n_try + 1
            if (nc_n_try > n_max_retries) {
                stop(msg)
            }
            else {
                message(msg, "\nRETRYing...")
                Sys.sleep(1)
            }
        }
        else {
            nc_retry <- F
        }
    }
    i_req <- i_req + 1
}
debug: i_t_beg <- (i_req - 1) * n_t_per_req + 1
debug: i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
debug: t_req <- times_todo[c(i_t_beg, i_t_end)]
debug: t_req_str <- format_ISO8601(t_req, usetz = "Z")
debug: if (verbose) message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
debug: message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
Fetching request 1 of 1 (2020-01-01 to 2020-12-01) ~ 19:34:07 UTC
debug: ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
    0), nc)
debug: unlink(ncs0)
debug: nc_retry <- T
debug: nc_n_try <- 1
debug: n_max_retries
debug: while (nc_retry) {
    res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
        url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
            bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
        time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
    if (inherits(res, "try-error")) {
        err <- attr(res, "condition")
        msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
        nc_n_try <- nc_n_try + 1
        if (nc_n_try > n_max_retries) {
            stop(msg)
        }
        else {
            message(msg, "\nRETRYing...")
            Sys.sleep(1)
        }
    }
    else {
        nc_retry <- F
    }
}
debug: res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
    url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
        bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
    time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
debug: if (inherits(res, "try-error")) {
    err <- attr(res, "condition")
    msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
    nc_n_try <- nc_n_try + 1
    if (nc_n_try > n_max_retries) {
        stop(msg)
    }
    else {
        message(msg, "\nRETRYing...")
        Sys.sleep(1)
    }
} else {
    nc_retry <- F
}
debug: nc_retry <- F
debug: (while) nc_retry
debug: i_req <- i_req + 1
debug: (while) i_req <= n_reqs
debug: ncs <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size > 
    0), nc)
debug: r <- terra::rast(ncs)
debug: stopifnot(all(class(terra::time(r)) %in% c("POSIXct", "POSIXt")))
debug: idx <- dplyr::pull(dplyr::filter(dplyr::arrange(dplyr::tibble(idx = 1:terra::nlyr(r), 
    time = terra::time(r)), time), !duplicated(time)), idx)
debug: r <- terra::subset(r, idx)
debug: stopifnot(terra::crs(r, proj = T) == wgs84)
debug: if (mask_tif) r <- terra::mask(r, sf_zones)
debug: lyrs <- glue("{var}|{terra::time(r)}")
debug: if (length(dims_other) > 0 && !all(length(dims[dims_other]) == 
    1)) stop(glue("Other dimensions not yet supported: {paste(dims_other, collapse = ',')}"))
debug: names(r) <- lyrs
debug: if (!is.null(rast_tif)) {
    if (fs::file_exists(rast_tif)) {
        r_tmp_tif <- tempfile(fileext = ".tif")
        r_tmp <- c(rast(rast_tif), r)
        r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
        terra::writeRaster(r_tmp, r_tmp_tif)
        fs::file_delete(rast_tif)
        fs::file_move(r_tmp_tif, rast_tif)
        rm(r)
        rm(r_tmp)
    }
    else {
        terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
    }
    r <- terra::rast(rast_tif)
}
debug: if (fs::file_exists(rast_tif)) {
    r_tmp_tif <- tempfile(fileext = ".tif")
    r_tmp <- c(rast(rast_tif), r)
    r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
    terra::writeRaster(r_tmp, r_tmp_tif)
    fs::file_delete(rast_tif)
    fs::file_move(r_tmp_tif, rast_tif)
    rm(r)
    rm(r_tmp)
} else {
    terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
}
debug: terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
debug: r <- terra::rast(rast_tif)
debug: d_r <- mutate(tidyr::pivot_longer(sf::st_drop_geometry(sf::st_as_sf(terra::zonal(x = r, 
    z = terra::vect(dplyr::select(sf_zones, dplyr::all_of(fld_zones))), 
    fun = zonal_fun, exact = T, na.rm = T, as.polygons = T))), 
    cols = -dplyr::any_of(fld_zones), names_to = "lyr", values_to = zonal_fun), 
    time = readr::parse_datetime(str_replace(lyr, glue("{var}\\|(.*)"), 
        "\\1")))
debug: if (!is.null(zonal_csv)) write_csv(d_r, zonal_csv)
debug: write_csv(d_r, zonal_csv)
debug: if (!keep_nc) unlink(dir_nc, recursive = T)
debug: unlink(dir_nc, recursive = T)
debug: return(d_r)
Downloading 1 requests, up to 148 time slices each
Called from: extractr::ed_extract(ed, var = v, sf_zones = ply, bbox = bb, 
    mask_tif = F, rast_tif = glue("{dir_out}/{nms}/{yr}.tif"), 
    zonal_fun = "mean", zonal_csv = glue("{dir_out}/{nms}/{yr}.csv"), 
    dir_nc = glue("{dir_out}/{nms}/{yr}_nc"), keep_nc = F, n_max_vals_per_req = 1e+05, 
    time_min = time_min, time_max = time_max, verbose = T)
debug: while (i_req <= n_reqs) {
    i_t_beg <- (i_req - 1) * n_t_per_req + 1
    i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
    t_req <- times_todo[c(i_t_beg, i_t_end)]
    t_req_str <- format_ISO8601(t_req, usetz = "Z")
    if (verbose) 
        message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
    ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
        ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
        0), nc)
    unlink(ncs0)
    nc_retry <- T
    nc_n_try <- 1
    n_max_retries
    while (nc_retry) {
        res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
            url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
                bbox[["xmax"]]), latitude = c(bbox[["ymin"]], 
                bbox[["ymax"]]), time = t_req_str, fmt = "nc", 
            store = rerddap::disk(path = dir_nc)))
        if (inherits(res, "try-error")) {
            err <- attr(res, "condition")
            msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
            nc_n_try <- nc_n_try + 1
            if (nc_n_try > n_max_retries) {
                stop(msg)
            }
            else {
                message(msg, "\nRETRYing...")
                Sys.sleep(1)
            }
        }
        else {
            nc_retry <- F
        }
    }
    i_req <- i_req + 1
}
debug: i_t_beg <- (i_req - 1) * n_t_per_req + 1
debug: i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
debug: t_req <- times_todo[c(i_t_beg, i_t_end)]
debug: t_req_str <- format_ISO8601(t_req, usetz = "Z")
debug: if (verbose) message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
debug: message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
Fetching request 1 of 1 (2021-01-01 to 2021-12-01) ~ 19:34:10 UTC
debug: ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
    0), nc)
debug: unlink(ncs0)
debug: nc_retry <- T
debug: nc_n_try <- 1
debug: n_max_retries
debug: while (nc_retry) {
    res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
        url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
            bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
        time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
    if (inherits(res, "try-error")) {
        err <- attr(res, "condition")
        msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
        nc_n_try <- nc_n_try + 1
        if (nc_n_try > n_max_retries) {
            stop(msg)
        }
        else {
            message(msg, "\nRETRYing...")
            Sys.sleep(1)
        }
    }
    else {
        nc_retry <- F
    }
}
debug: res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
    url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
        bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
    time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
debug: if (inherits(res, "try-error")) {
    err <- attr(res, "condition")
    msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
    nc_n_try <- nc_n_try + 1
    if (nc_n_try > n_max_retries) {
        stop(msg)
    }
    else {
        message(msg, "\nRETRYing...")
        Sys.sleep(1)
    }
} else {
    nc_retry <- F
}
debug: nc_retry <- F
debug: (while) nc_retry
debug: i_req <- i_req + 1
debug: (while) i_req <= n_reqs
debug: ncs <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size > 
    0), nc)
debug: r <- terra::rast(ncs)
debug: stopifnot(all(class(terra::time(r)) %in% c("POSIXct", "POSIXt")))
debug: idx <- dplyr::pull(dplyr::filter(dplyr::arrange(dplyr::tibble(idx = 1:terra::nlyr(r), 
    time = terra::time(r)), time), !duplicated(time)), idx)
debug: r <- terra::subset(r, idx)
debug: stopifnot(terra::crs(r, proj = T) == wgs84)
debug: if (mask_tif) r <- terra::mask(r, sf_zones)
debug: lyrs <- glue("{var}|{terra::time(r)}")
debug: if (length(dims_other) > 0 && !all(length(dims[dims_other]) == 
    1)) stop(glue("Other dimensions not yet supported: {paste(dims_other, collapse = ',')}"))
debug: names(r) <- lyrs
debug: if (!is.null(rast_tif)) {
    if (fs::file_exists(rast_tif)) {
        r_tmp_tif <- tempfile(fileext = ".tif")
        r_tmp <- c(rast(rast_tif), r)
        r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
        terra::writeRaster(r_tmp, r_tmp_tif)
        fs::file_delete(rast_tif)
        fs::file_move(r_tmp_tif, rast_tif)
        rm(r)
        rm(r_tmp)
    }
    else {
        terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
    }
    r <- terra::rast(rast_tif)
}
debug: if (fs::file_exists(rast_tif)) {
    r_tmp_tif <- tempfile(fileext = ".tif")
    r_tmp <- c(rast(rast_tif), r)
    r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
    terra::writeRaster(r_tmp, r_tmp_tif)
    fs::file_delete(rast_tif)
    fs::file_move(r_tmp_tif, rast_tif)
    rm(r)
    rm(r_tmp)
} else {
    terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
}
debug: terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
debug: r <- terra::rast(rast_tif)
debug: d_r <- mutate(tidyr::pivot_longer(sf::st_drop_geometry(sf::st_as_sf(terra::zonal(x = r, 
    z = terra::vect(dplyr::select(sf_zones, dplyr::all_of(fld_zones))), 
    fun = zonal_fun, exact = T, na.rm = T, as.polygons = T))), 
    cols = -dplyr::any_of(fld_zones), names_to = "lyr", values_to = zonal_fun), 
    time = readr::parse_datetime(str_replace(lyr, glue("{var}\\|(.*)"), 
        "\\1")))
debug: if (!is.null(zonal_csv)) write_csv(d_r, zonal_csv)
debug: write_csv(d_r, zonal_csv)
debug: if (!keep_nc) unlink(dir_nc, recursive = T)
debug: unlink(dir_nc, recursive = T)
debug: return(d_r)
Downloading 1 requests, up to 148 time slices each
Called from: extractr::ed_extract(ed, var = v, sf_zones = ply, bbox = bb, 
    mask_tif = F, rast_tif = glue("{dir_out}/{nms}/{yr}.tif"), 
    zonal_fun = "mean", zonal_csv = glue("{dir_out}/{nms}/{yr}.csv"), 
    dir_nc = glue("{dir_out}/{nms}/{yr}_nc"), keep_nc = F, n_max_vals_per_req = 1e+05, 
    time_min = time_min, time_max = time_max, verbose = T)
debug: while (i_req <= n_reqs) {
    i_t_beg <- (i_req - 1) * n_t_per_req + 1
    i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
    t_req <- times_todo[c(i_t_beg, i_t_end)]
    t_req_str <- format_ISO8601(t_req, usetz = "Z")
    if (verbose) 
        message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
    ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
        ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
        0), nc)
    unlink(ncs0)
    nc_retry <- T
    nc_n_try <- 1
    n_max_retries
    while (nc_retry) {
        res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
            url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
                bbox[["xmax"]]), latitude = c(bbox[["ymin"]], 
                bbox[["ymax"]]), time = t_req_str, fmt = "nc", 
            store = rerddap::disk(path = dir_nc)))
        if (inherits(res, "try-error")) {
            err <- attr(res, "condition")
            msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
            nc_n_try <- nc_n_try + 1
            if (nc_n_try > n_max_retries) {
                stop(msg)
            }
            else {
                message(msg, "\nRETRYing...")
                Sys.sleep(1)
            }
        }
        else {
            nc_retry <- F
        }
    }
    i_req <- i_req + 1
}
debug: i_t_beg <- (i_req - 1) * n_t_per_req + 1
debug: i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
debug: t_req <- times_todo[c(i_t_beg, i_t_end)]
debug: t_req_str <- format_ISO8601(t_req, usetz = "Z")
debug: if (verbose) message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
debug: message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
Fetching request 1 of 1 (2022-01-01 to 2022-12-01) ~ 19:34:13 UTC
debug: ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
    0), nc)
debug: unlink(ncs0)
debug: nc_retry <- T
debug: nc_n_try <- 1
debug: n_max_retries
debug: while (nc_retry) {
    res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
        url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
            bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
        time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
    if (inherits(res, "try-error")) {
        err <- attr(res, "condition")
        msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
        nc_n_try <- nc_n_try + 1
        if (nc_n_try > n_max_retries) {
            stop(msg)
        }
        else {
            message(msg, "\nRETRYing...")
            Sys.sleep(1)
        }
    }
    else {
        nc_retry <- F
    }
}
debug: res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
    url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
        bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
    time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
debug: if (inherits(res, "try-error")) {
    err <- attr(res, "condition")
    msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
    nc_n_try <- nc_n_try + 1
    if (nc_n_try > n_max_retries) {
        stop(msg)
    }
    else {
        message(msg, "\nRETRYing...")
        Sys.sleep(1)
    }
} else {
    nc_retry <- F
}
debug: nc_retry <- F
debug: (while) nc_retry
debug: i_req <- i_req + 1
debug: (while) i_req <= n_reqs
debug: ncs <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size > 
    0), nc)
debug: r <- terra::rast(ncs)
debug: stopifnot(all(class(terra::time(r)) %in% c("POSIXct", "POSIXt")))
debug: idx <- dplyr::pull(dplyr::filter(dplyr::arrange(dplyr::tibble(idx = 1:terra::nlyr(r), 
    time = terra::time(r)), time), !duplicated(time)), idx)
debug: r <- terra::subset(r, idx)
debug: stopifnot(terra::crs(r, proj = T) == wgs84)
debug: if (mask_tif) r <- terra::mask(r, sf_zones)
debug: lyrs <- glue("{var}|{terra::time(r)}")
debug: if (length(dims_other) > 0 && !all(length(dims[dims_other]) == 
    1)) stop(glue("Other dimensions not yet supported: {paste(dims_other, collapse = ',')}"))
debug: names(r) <- lyrs
debug: if (!is.null(rast_tif)) {
    if (fs::file_exists(rast_tif)) {
        r_tmp_tif <- tempfile(fileext = ".tif")
        r_tmp <- c(rast(rast_tif), r)
        r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
        terra::writeRaster(r_tmp, r_tmp_tif)
        fs::file_delete(rast_tif)
        fs::file_move(r_tmp_tif, rast_tif)
        rm(r)
        rm(r_tmp)
    }
    else {
        terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
    }
    r <- terra::rast(rast_tif)
}
debug: if (fs::file_exists(rast_tif)) {
    r_tmp_tif <- tempfile(fileext = ".tif")
    r_tmp <- c(rast(rast_tif), r)
    r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
    terra::writeRaster(r_tmp, r_tmp_tif)
    fs::file_delete(rast_tif)
    fs::file_move(r_tmp_tif, rast_tif)
    rm(r)
    rm(r_tmp)
} else {
    terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
}
debug: terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
debug: r <- terra::rast(rast_tif)
debug: d_r <- mutate(tidyr::pivot_longer(sf::st_drop_geometry(sf::st_as_sf(terra::zonal(x = r, 
    z = terra::vect(dplyr::select(sf_zones, dplyr::all_of(fld_zones))), 
    fun = zonal_fun, exact = T, na.rm = T, as.polygons = T))), 
    cols = -dplyr::any_of(fld_zones), names_to = "lyr", values_to = zonal_fun), 
    time = readr::parse_datetime(str_replace(lyr, glue("{var}\\|(.*)"), 
        "\\1")))
debug: if (!is.null(zonal_csv)) write_csv(d_r, zonal_csv)
debug: write_csv(d_r, zonal_csv)
debug: if (!keep_nc) unlink(dir_nc, recursive = T)
debug: unlink(dir_nc, recursive = T)
debug: return(d_r)
Downloading 1 requests, up to 148 time slices each
Called from: extractr::ed_extract(ed, var = v, sf_zones = ply, bbox = bb, 
    mask_tif = F, rast_tif = glue("{dir_out}/{nms}/{yr}.tif"), 
    zonal_fun = "mean", zonal_csv = glue("{dir_out}/{nms}/{yr}.csv"), 
    dir_nc = glue("{dir_out}/{nms}/{yr}_nc"), keep_nc = F, n_max_vals_per_req = 1e+05, 
    time_min = time_min, time_max = time_max, verbose = T)
debug: while (i_req <= n_reqs) {
    i_t_beg <- (i_req - 1) * n_t_per_req + 1
    i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
    t_req <- times_todo[c(i_t_beg, i_t_end)]
    t_req_str <- format_ISO8601(t_req, usetz = "Z")
    if (verbose) 
        message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
    ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
        ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
        0), nc)
    unlink(ncs0)
    nc_retry <- T
    nc_n_try <- 1
    n_max_retries
    while (nc_retry) {
        res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
            url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
                bbox[["xmax"]]), latitude = c(bbox[["ymin"]], 
                bbox[["ymax"]]), time = t_req_str, fmt = "nc", 
            store = rerddap::disk(path = dir_nc)))
        if (inherits(res, "try-error")) {
            err <- attr(res, "condition")
            msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
            nc_n_try <- nc_n_try + 1
            if (nc_n_try > n_max_retries) {
                stop(msg)
            }
            else {
                message(msg, "\nRETRYing...")
                Sys.sleep(1)
            }
        }
        else {
            nc_retry <- F
        }
    }
    i_req <- i_req + 1
}
debug: i_t_beg <- (i_req - 1) * n_t_per_req + 1
debug: i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
debug: t_req <- times_todo[c(i_t_beg, i_t_end)]
debug: t_req_str <- format_ISO8601(t_req, usetz = "Z")
debug: if (verbose) message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
debug: message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
Fetching request 1 of 1 (2023-01-01 to 2023-12-01) ~ 19:34:16 UTC
debug: ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
    0), nc)
debug: unlink(ncs0)
debug: nc_retry <- T
debug: nc_n_try <- 1
debug: n_max_retries
debug: while (nc_retry) {
    res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
        url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
            bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
        time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
    if (inherits(res, "try-error")) {
        err <- attr(res, "condition")
        msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
        nc_n_try <- nc_n_try + 1
        if (nc_n_try > n_max_retries) {
            stop(msg)
        }
        else {
            message(msg, "\nRETRYing...")
            Sys.sleep(1)
        }
    }
    else {
        nc_retry <- F
    }
}
debug: res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
    url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
        bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
    time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
debug: if (inherits(res, "try-error")) {
    err <- attr(res, "condition")
    msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
    nc_n_try <- nc_n_try + 1
    if (nc_n_try > n_max_retries) {
        stop(msg)
    }
    else {
        message(msg, "\nRETRYing...")
        Sys.sleep(1)
    }
} else {
    nc_retry <- F
}
debug: nc_retry <- F
debug: (while) nc_retry
debug: i_req <- i_req + 1
debug: (while) i_req <= n_reqs
debug: ncs <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size > 
    0), nc)
debug: r <- terra::rast(ncs)
debug: stopifnot(all(class(terra::time(r)) %in% c("POSIXct", "POSIXt")))
debug: idx <- dplyr::pull(dplyr::filter(dplyr::arrange(dplyr::tibble(idx = 1:terra::nlyr(r), 
    time = terra::time(r)), time), !duplicated(time)), idx)
debug: r <- terra::subset(r, idx)
debug: stopifnot(terra::crs(r, proj = T) == wgs84)
debug: if (mask_tif) r <- terra::mask(r, sf_zones)
debug: lyrs <- glue("{var}|{terra::time(r)}")
debug: if (length(dims_other) > 0 && !all(length(dims[dims_other]) == 
    1)) stop(glue("Other dimensions not yet supported: {paste(dims_other, collapse = ',')}"))
debug: names(r) <- lyrs
debug: if (!is.null(rast_tif)) {
    if (fs::file_exists(rast_tif)) {
        r_tmp_tif <- tempfile(fileext = ".tif")
        r_tmp <- c(rast(rast_tif), r)
        r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
        terra::writeRaster(r_tmp, r_tmp_tif)
        fs::file_delete(rast_tif)
        fs::file_move(r_tmp_tif, rast_tif)
        rm(r)
        rm(r_tmp)
    }
    else {
        terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
    }
    r <- terra::rast(rast_tif)
}
debug: if (fs::file_exists(rast_tif)) {
    r_tmp_tif <- tempfile(fileext = ".tif")
    r_tmp <- c(rast(rast_tif), r)
    r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
    terra::writeRaster(r_tmp, r_tmp_tif)
    fs::file_delete(rast_tif)
    fs::file_move(r_tmp_tif, rast_tif)
    rm(r)
    rm(r_tmp)
} else {
    terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
}
debug: terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
debug: r <- terra::rast(rast_tif)
debug: d_r <- mutate(tidyr::pivot_longer(sf::st_drop_geometry(sf::st_as_sf(terra::zonal(x = r, 
    z = terra::vect(dplyr::select(sf_zones, dplyr::all_of(fld_zones))), 
    fun = zonal_fun, exact = T, na.rm = T, as.polygons = T))), 
    cols = -dplyr::any_of(fld_zones), names_to = "lyr", values_to = zonal_fun), 
    time = readr::parse_datetime(str_replace(lyr, glue("{var}\\|(.*)"), 
        "\\1")))
debug: if (!is.null(zonal_csv)) write_csv(d_r, zonal_csv)
debug: write_csv(d_r, zonal_csv)
debug: if (!keep_nc) unlink(dir_nc, recursive = T)
debug: unlink(dir_nc, recursive = T)
debug: return(d_r)
Downloading 1 requests, up to 148 time slices each
Called from: extractr::ed_extract(ed, var = v, sf_zones = ply, bbox = bb, 
    mask_tif = F, rast_tif = glue("{dir_out}/{nms}/{yr}.tif"), 
    zonal_fun = "mean", zonal_csv = glue("{dir_out}/{nms}/{yr}.csv"), 
    dir_nc = glue("{dir_out}/{nms}/{yr}_nc"), keep_nc = F, n_max_vals_per_req = 1e+05, 
    time_min = time_min, time_max = time_max, verbose = T)
debug: while (i_req <= n_reqs) {
    i_t_beg <- (i_req - 1) * n_t_per_req + 1
    i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
    t_req <- times_todo[c(i_t_beg, i_t_end)]
    t_req_str <- format_ISO8601(t_req, usetz = "Z")
    if (verbose) 
        message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
    ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
        ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
        0), nc)
    unlink(ncs0)
    nc_retry <- T
    nc_n_try <- 1
    n_max_retries
    while (nc_retry) {
        res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
            url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
                bbox[["xmax"]]), latitude = c(bbox[["ymin"]], 
                bbox[["ymax"]]), time = t_req_str, fmt = "nc", 
            store = rerddap::disk(path = dir_nc)))
        if (inherits(res, "try-error")) {
            err <- attr(res, "condition")
            msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
            nc_n_try <- nc_n_try + 1
            if (nc_n_try > n_max_retries) {
                stop(msg)
            }
            else {
                message(msg, "\nRETRYing...")
                Sys.sleep(1)
            }
        }
        else {
            nc_retry <- F
        }
    }
    i_req <- i_req + 1
}
debug: i_t_beg <- (i_req - 1) * n_t_per_req + 1
debug: i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
debug: t_req <- times_todo[c(i_t_beg, i_t_end)]
debug: t_req_str <- format_ISO8601(t_req, usetz = "Z")
debug: if (verbose) message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
debug: message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
Fetching request 1 of 1 (2024-01-01 to 2024-12-01) ~ 19:34:20 UTC
debug: ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
    0), nc)
debug: unlink(ncs0)
debug: nc_retry <- T
debug: nc_n_try <- 1
debug: n_max_retries
debug: while (nc_retry) {
    res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
        url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
            bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
        time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
    if (inherits(res, "try-error")) {
        err <- attr(res, "condition")
        msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
        nc_n_try <- nc_n_try + 1
        if (nc_n_try > n_max_retries) {
            stop(msg)
        }
        else {
            message(msg, "\nRETRYing...")
            Sys.sleep(1)
        }
    }
    else {
        nc_retry <- F
    }
}
debug: res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
    url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
        bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
    time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
debug: if (inherits(res, "try-error")) {
    err <- attr(res, "condition")
    msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
    nc_n_try <- nc_n_try + 1
    if (nc_n_try > n_max_retries) {
        stop(msg)
    }
    else {
        message(msg, "\nRETRYing...")
        Sys.sleep(1)
    }
} else {
    nc_retry <- F
}
debug: nc_retry <- F
debug: (while) nc_retry
debug: i_req <- i_req + 1
debug: (while) i_req <= n_reqs
debug: ncs <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size > 
    0), nc)
debug: r <- terra::rast(ncs)
debug: stopifnot(all(class(terra::time(r)) %in% c("POSIXct", "POSIXt")))
debug: idx <- dplyr::pull(dplyr::filter(dplyr::arrange(dplyr::tibble(idx = 1:terra::nlyr(r), 
    time = terra::time(r)), time), !duplicated(time)), idx)
debug: r <- terra::subset(r, idx)
debug: stopifnot(terra::crs(r, proj = T) == wgs84)
debug: if (mask_tif) r <- terra::mask(r, sf_zones)
debug: lyrs <- glue("{var}|{terra::time(r)}")
debug: if (length(dims_other) > 0 && !all(length(dims[dims_other]) == 
    1)) stop(glue("Other dimensions not yet supported: {paste(dims_other, collapse = ',')}"))
debug: names(r) <- lyrs
debug: if (!is.null(rast_tif)) {
    if (fs::file_exists(rast_tif)) {
        r_tmp_tif <- tempfile(fileext = ".tif")
        r_tmp <- c(rast(rast_tif), r)
        r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
        terra::writeRaster(r_tmp, r_tmp_tif)
        fs::file_delete(rast_tif)
        fs::file_move(r_tmp_tif, rast_tif)
        rm(r)
        rm(r_tmp)
    }
    else {
        terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
    }
    r <- terra::rast(rast_tif)
}
debug: if (fs::file_exists(rast_tif)) {
    r_tmp_tif <- tempfile(fileext = ".tif")
    r_tmp <- c(rast(rast_tif), r)
    r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
    terra::writeRaster(r_tmp, r_tmp_tif)
    fs::file_delete(rast_tif)
    fs::file_move(r_tmp_tif, rast_tif)
    rm(r)
    rm(r_tmp)
} else {
    terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
}
debug: terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
debug: r <- terra::rast(rast_tif)
debug: d_r <- mutate(tidyr::pivot_longer(sf::st_drop_geometry(sf::st_as_sf(terra::zonal(x = r, 
    z = terra::vect(dplyr::select(sf_zones, dplyr::all_of(fld_zones))), 
    fun = zonal_fun, exact = T, na.rm = T, as.polygons = T))), 
    cols = -dplyr::any_of(fld_zones), names_to = "lyr", values_to = zonal_fun), 
    time = readr::parse_datetime(str_replace(lyr, glue("{var}\\|(.*)"), 
        "\\1")))
debug: if (!is.null(zonal_csv)) write_csv(d_r, zonal_csv)
debug: write_csv(d_r, zonal_csv)
debug: if (!keep_nc) unlink(dir_nc, recursive = T)
debug: unlink(dir_nc, recursive = T)
debug: return(d_r)
Downloading 1 requests, up to 148 time slices each
Called from: extractr::ed_extract(ed, var = v, sf_zones = ply, bbox = bb, 
    mask_tif = F, rast_tif = glue("{dir_out}/{nms}/{yr}.tif"), 
    zonal_fun = "mean", zonal_csv = glue("{dir_out}/{nms}/{yr}.csv"), 
    dir_nc = glue("{dir_out}/{nms}/{yr}_nc"), keep_nc = F, n_max_vals_per_req = 1e+05, 
    time_min = time_min, time_max = time_max, verbose = T)
debug: while (i_req <= n_reqs) {
    i_t_beg <- (i_req - 1) * n_t_per_req + 1
    i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
    t_req <- times_todo[c(i_t_beg, i_t_end)]
    t_req_str <- format_ISO8601(t_req, usetz = "Z")
    if (verbose) 
        message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
    ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
        ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
        0), nc)
    unlink(ncs0)
    nc_retry <- T
    nc_n_try <- 1
    n_max_retries
    while (nc_retry) {
        res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
            url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
                bbox[["xmax"]]), latitude = c(bbox[["ymin"]], 
                bbox[["ymax"]]), time = t_req_str, fmt = "nc", 
            store = rerddap::disk(path = dir_nc)))
        if (inherits(res, "try-error")) {
            err <- attr(res, "condition")
            msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
            nc_n_try <- nc_n_try + 1
            if (nc_n_try > n_max_retries) {
                stop(msg)
            }
            else {
                message(msg, "\nRETRYing...")
                Sys.sleep(1)
            }
        }
        else {
            nc_retry <- F
        }
    }
    i_req <- i_req + 1
}
debug: i_t_beg <- (i_req - 1) * n_t_per_req + 1
debug: i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
debug: t_req <- times_todo[c(i_t_beg, i_t_end)]
debug: t_req_str <- format_ISO8601(t_req, usetz = "Z")
debug: if (verbose) message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
debug: message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
Fetching request 1 of 1 (2025-01-01 to 2025-07-01) ~ 19:34:23 UTC
debug: ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
    0), nc)
debug: unlink(ncs0)
debug: nc_retry <- T
debug: nc_n_try <- 1
debug: n_max_retries
debug: while (nc_retry) {
    res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
        url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
            bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
        time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
    if (inherits(res, "try-error")) {
        err <- attr(res, "condition")
        msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
        nc_n_try <- nc_n_try + 1
        if (nc_n_try > n_max_retries) {
            stop(msg)
        }
        else {
            message(msg, "\nRETRYing...")
            Sys.sleep(1)
        }
    }
    else {
        nc_retry <- F
    }
}
debug: res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
    url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
        bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
    time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
debug: if (inherits(res, "try-error")) {
    err <- attr(res, "condition")
    msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
    nc_n_try <- nc_n_try + 1
    if (nc_n_try > n_max_retries) {
        stop(msg)
    }
    else {
        message(msg, "\nRETRYing...")
        Sys.sleep(1)
    }
} else {
    nc_retry <- F
}
debug: nc_retry <- F
debug: (while) nc_retry
debug: i_req <- i_req + 1
debug: (while) i_req <= n_reqs
debug: ncs <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size > 
    0), nc)
debug: r <- terra::rast(ncs)
debug: stopifnot(all(class(terra::time(r)) %in% c("POSIXct", "POSIXt")))
debug: idx <- dplyr::pull(dplyr::filter(dplyr::arrange(dplyr::tibble(idx = 1:terra::nlyr(r), 
    time = terra::time(r)), time), !duplicated(time)), idx)
debug: r <- terra::subset(r, idx)
debug: stopifnot(terra::crs(r, proj = T) == wgs84)
debug: if (mask_tif) r <- terra::mask(r, sf_zones)
debug: lyrs <- glue("{var}|{terra::time(r)}")
debug: if (length(dims_other) > 0 && !all(length(dims[dims_other]) == 
    1)) stop(glue("Other dimensions not yet supported: {paste(dims_other, collapse = ',')}"))
debug: names(r) <- lyrs
debug: if (!is.null(rast_tif)) {
    if (fs::file_exists(rast_tif)) {
        r_tmp_tif <- tempfile(fileext = ".tif")
        r_tmp <- c(rast(rast_tif), r)
        r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
        terra::writeRaster(r_tmp, r_tmp_tif)
        fs::file_delete(rast_tif)
        fs::file_move(r_tmp_tif, rast_tif)
        rm(r)
        rm(r_tmp)
    }
    else {
        terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
    }
    r <- terra::rast(rast_tif)
}
debug: if (fs::file_exists(rast_tif)) {
    r_tmp_tif <- tempfile(fileext = ".tif")
    r_tmp <- c(rast(rast_tif), r)
    r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
    terra::writeRaster(r_tmp, r_tmp_tif)
    fs::file_delete(rast_tif)
    fs::file_move(r_tmp_tif, rast_tif)
    rm(r)
    rm(r_tmp)
} else {
    terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
}
debug: terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
debug: r <- terra::rast(rast_tif)
debug: d_r <- mutate(tidyr::pivot_longer(sf::st_drop_geometry(sf::st_as_sf(terra::zonal(x = r, 
    z = terra::vect(dplyr::select(sf_zones, dplyr::all_of(fld_zones))), 
    fun = zonal_fun, exact = T, na.rm = T, as.polygons = T))), 
    cols = -dplyr::any_of(fld_zones), names_to = "lyr", values_to = zonal_fun), 
    time = readr::parse_datetime(str_replace(lyr, glue("{var}\\|(.*)"), 
        "\\1")))
debug: if (!is.null(zonal_csv)) write_csv(d_r, zonal_csv)
debug: write_csv(d_r, zonal_csv)
debug: if (!keep_nc) unlink(dir_nc, recursive = T)
debug: unlink(dir_nc, recursive = T)
debug: return(d_r)
Downloading 1 requests, up to 248 time slices each
Called from: extractr::ed_extract(ed, var = v, sf_zones = ply, bbox = bb, 
    mask_tif = F, rast_tif = glue("{dir_out}/{nms}/{yr}.tif"), 
    zonal_fun = "mean", zonal_csv = glue("{dir_out}/{nms}/{yr}.csv"), 
    dir_nc = glue("{dir_out}/{nms}/{yr}_nc"), keep_nc = F, n_max_vals_per_req = 1e+05, 
    time_min = time_min, time_max = time_max, verbose = T)
debug: while (i_req <= n_reqs) {
    i_t_beg <- (i_req - 1) * n_t_per_req + 1
    i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
    t_req <- times_todo[c(i_t_beg, i_t_end)]
    t_req_str <- format_ISO8601(t_req, usetz = "Z")
    if (verbose) 
        message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
    ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
        ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
        0), nc)
    unlink(ncs0)
    nc_retry <- T
    nc_n_try <- 1
    n_max_retries
    while (nc_retry) {
        res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
            url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
                bbox[["xmax"]]), latitude = c(bbox[["ymin"]], 
                bbox[["ymax"]]), time = t_req_str, fmt = "nc", 
            store = rerddap::disk(path = dir_nc)))
        if (inherits(res, "try-error")) {
            err <- attr(res, "condition")
            msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
            nc_n_try <- nc_n_try + 1
            if (nc_n_try > n_max_retries) {
                stop(msg)
            }
            else {
                message(msg, "\nRETRYing...")
                Sys.sleep(1)
            }
        }
        else {
            nc_retry <- F
        }
    }
    i_req <- i_req + 1
}
debug: i_t_beg <- (i_req - 1) * n_t_per_req + 1
debug: i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
debug: t_req <- times_todo[c(i_t_beg, i_t_end)]
debug: t_req_str <- format_ISO8601(t_req, usetz = "Z")
debug: if (verbose) message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
debug: message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
Fetching request 1 of 1 (1998-01-01 to 1998-12-01) ~ 19:34:26 UTC
debug: ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
    0), nc)
debug: unlink(ncs0)
debug: nc_retry <- T
debug: nc_n_try <- 1
debug: n_max_retries
debug: while (nc_retry) {
    res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
        url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
            bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
        time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
    if (inherits(res, "try-error")) {
        err <- attr(res, "condition")
        msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
        nc_n_try <- nc_n_try + 1
        if (nc_n_try > n_max_retries) {
            stop(msg)
        }
        else {
            message(msg, "\nRETRYing...")
            Sys.sleep(1)
        }
    }
    else {
        nc_retry <- F
    }
}
debug: res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
    url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
        bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
    time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
debug: if (inherits(res, "try-error")) {
    err <- attr(res, "condition")
    msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
    nc_n_try <- nc_n_try + 1
    if (nc_n_try > n_max_retries) {
        stop(msg)
    }
    else {
        message(msg, "\nRETRYing...")
        Sys.sleep(1)
    }
} else {
    nc_retry <- F
}
debug: nc_retry <- F
debug: (while) nc_retry
debug: i_req <- i_req + 1
debug: (while) i_req <= n_reqs
debug: ncs <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size > 
    0), nc)
debug: r <- terra::rast(ncs)
debug: stopifnot(all(class(terra::time(r)) %in% c("POSIXct", "POSIXt")))
debug: idx <- dplyr::pull(dplyr::filter(dplyr::arrange(dplyr::tibble(idx = 1:terra::nlyr(r), 
    time = terra::time(r)), time), !duplicated(time)), idx)
debug: r <- terra::subset(r, idx)
debug: stopifnot(terra::crs(r, proj = T) == wgs84)
debug: if (mask_tif) r <- terra::mask(r, sf_zones)
debug: lyrs <- glue("{var}|{terra::time(r)}")
debug: if (length(dims_other) > 0 && !all(length(dims[dims_other]) == 
    1)) stop(glue("Other dimensions not yet supported: {paste(dims_other, collapse = ',')}"))
debug: names(r) <- lyrs
debug: if (!is.null(rast_tif)) {
    if (fs::file_exists(rast_tif)) {
        r_tmp_tif <- tempfile(fileext = ".tif")
        r_tmp <- c(rast(rast_tif), r)
        r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
        terra::writeRaster(r_tmp, r_tmp_tif)
        fs::file_delete(rast_tif)
        fs::file_move(r_tmp_tif, rast_tif)
        rm(r)
        rm(r_tmp)
    }
    else {
        terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
    }
    r <- terra::rast(rast_tif)
}
debug: if (fs::file_exists(rast_tif)) {
    r_tmp_tif <- tempfile(fileext = ".tif")
    r_tmp <- c(rast(rast_tif), r)
    r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
    terra::writeRaster(r_tmp, r_tmp_tif)
    fs::file_delete(rast_tif)
    fs::file_move(r_tmp_tif, rast_tif)
    rm(r)
    rm(r_tmp)
} else {
    terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
}
debug: terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
debug: r <- terra::rast(rast_tif)
debug: d_r <- mutate(tidyr::pivot_longer(sf::st_drop_geometry(sf::st_as_sf(terra::zonal(x = r, 
    z = terra::vect(dplyr::select(sf_zones, dplyr::all_of(fld_zones))), 
    fun = zonal_fun, exact = T, na.rm = T, as.polygons = T))), 
    cols = -dplyr::any_of(fld_zones), names_to = "lyr", values_to = zonal_fun), 
    time = readr::parse_datetime(str_replace(lyr, glue("{var}\\|(.*)"), 
        "\\1")))
debug: if (!is.null(zonal_csv)) write_csv(d_r, zonal_csv)
debug: write_csv(d_r, zonal_csv)
debug: if (!keep_nc) unlink(dir_nc, recursive = T)
debug: unlink(dir_nc, recursive = T)
debug: return(d_r)
Downloading 1 requests, up to 248 time slices each
Called from: extractr::ed_extract(ed, var = v, sf_zones = ply, bbox = bb, 
    mask_tif = F, rast_tif = glue("{dir_out}/{nms}/{yr}.tif"), 
    zonal_fun = "mean", zonal_csv = glue("{dir_out}/{nms}/{yr}.csv"), 
    dir_nc = glue("{dir_out}/{nms}/{yr}_nc"), keep_nc = F, n_max_vals_per_req = 1e+05, 
    time_min = time_min, time_max = time_max, verbose = T)
debug: while (i_req <= n_reqs) {
    i_t_beg <- (i_req - 1) * n_t_per_req + 1
    i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
    t_req <- times_todo[c(i_t_beg, i_t_end)]
    t_req_str <- format_ISO8601(t_req, usetz = "Z")
    if (verbose) 
        message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
    ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
        ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
        0), nc)
    unlink(ncs0)
    nc_retry <- T
    nc_n_try <- 1
    n_max_retries
    while (nc_retry) {
        res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
            url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
                bbox[["xmax"]]), latitude = c(bbox[["ymin"]], 
                bbox[["ymax"]]), time = t_req_str, fmt = "nc", 
            store = rerddap::disk(path = dir_nc)))
        if (inherits(res, "try-error")) {
            err <- attr(res, "condition")
            msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
            nc_n_try <- nc_n_try + 1
            if (nc_n_try > n_max_retries) {
                stop(msg)
            }
            else {
                message(msg, "\nRETRYing...")
                Sys.sleep(1)
            }
        }
        else {
            nc_retry <- F
        }
    }
    i_req <- i_req + 1
}
debug: i_t_beg <- (i_req - 1) * n_t_per_req + 1
debug: i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
debug: t_req <- times_todo[c(i_t_beg, i_t_end)]
debug: t_req_str <- format_ISO8601(t_req, usetz = "Z")
debug: if (verbose) message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
debug: message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
Fetching request 1 of 1 (1999-01-01 to 1999-12-01) ~ 19:34:28 UTC
debug: ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
    0), nc)
debug: unlink(ncs0)
debug: nc_retry <- T
debug: nc_n_try <- 1
debug: n_max_retries
debug: while (nc_retry) {
    res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
        url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
            bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
        time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
    if (inherits(res, "try-error")) {
        err <- attr(res, "condition")
        msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
        nc_n_try <- nc_n_try + 1
        if (nc_n_try > n_max_retries) {
            stop(msg)
        }
        else {
            message(msg, "\nRETRYing...")
            Sys.sleep(1)
        }
    }
    else {
        nc_retry <- F
    }
}
debug: res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
    url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
        bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
    time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
debug: if (inherits(res, "try-error")) {
    err <- attr(res, "condition")
    msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
    nc_n_try <- nc_n_try + 1
    if (nc_n_try > n_max_retries) {
        stop(msg)
    }
    else {
        message(msg, "\nRETRYing...")
        Sys.sleep(1)
    }
} else {
    nc_retry <- F
}
debug: nc_retry <- F
debug: (while) nc_retry
debug: i_req <- i_req + 1
debug: (while) i_req <= n_reqs
debug: ncs <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size > 
    0), nc)
debug: r <- terra::rast(ncs)
debug: stopifnot(all(class(terra::time(r)) %in% c("POSIXct", "POSIXt")))
debug: idx <- dplyr::pull(dplyr::filter(dplyr::arrange(dplyr::tibble(idx = 1:terra::nlyr(r), 
    time = terra::time(r)), time), !duplicated(time)), idx)
debug: r <- terra::subset(r, idx)
debug: stopifnot(terra::crs(r, proj = T) == wgs84)
debug: if (mask_tif) r <- terra::mask(r, sf_zones)
debug: lyrs <- glue("{var}|{terra::time(r)}")
debug: if (length(dims_other) > 0 && !all(length(dims[dims_other]) == 
    1)) stop(glue("Other dimensions not yet supported: {paste(dims_other, collapse = ',')}"))
debug: names(r) <- lyrs
debug: if (!is.null(rast_tif)) {
    if (fs::file_exists(rast_tif)) {
        r_tmp_tif <- tempfile(fileext = ".tif")
        r_tmp <- c(rast(rast_tif), r)
        r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
        terra::writeRaster(r_tmp, r_tmp_tif)
        fs::file_delete(rast_tif)
        fs::file_move(r_tmp_tif, rast_tif)
        rm(r)
        rm(r_tmp)
    }
    else {
        terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
    }
    r <- terra::rast(rast_tif)
}
debug: if (fs::file_exists(rast_tif)) {
    r_tmp_tif <- tempfile(fileext = ".tif")
    r_tmp <- c(rast(rast_tif), r)
    r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
    terra::writeRaster(r_tmp, r_tmp_tif)
    fs::file_delete(rast_tif)
    fs::file_move(r_tmp_tif, rast_tif)
    rm(r)
    rm(r_tmp)
} else {
    terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
}
debug: terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
debug: r <- terra::rast(rast_tif)
debug: d_r <- mutate(tidyr::pivot_longer(sf::st_drop_geometry(sf::st_as_sf(terra::zonal(x = r, 
    z = terra::vect(dplyr::select(sf_zones, dplyr::all_of(fld_zones))), 
    fun = zonal_fun, exact = T, na.rm = T, as.polygons = T))), 
    cols = -dplyr::any_of(fld_zones), names_to = "lyr", values_to = zonal_fun), 
    time = readr::parse_datetime(str_replace(lyr, glue("{var}\\|(.*)"), 
        "\\1")))
debug: if (!is.null(zonal_csv)) write_csv(d_r, zonal_csv)
debug: write_csv(d_r, zonal_csv)
debug: if (!keep_nc) unlink(dir_nc, recursive = T)
debug: unlink(dir_nc, recursive = T)
debug: return(d_r)
Downloading 1 requests, up to 248 time slices each
Called from: extractr::ed_extract(ed, var = v, sf_zones = ply, bbox = bb, 
    mask_tif = F, rast_tif = glue("{dir_out}/{nms}/{yr}.tif"), 
    zonal_fun = "mean", zonal_csv = glue("{dir_out}/{nms}/{yr}.csv"), 
    dir_nc = glue("{dir_out}/{nms}/{yr}_nc"), keep_nc = F, n_max_vals_per_req = 1e+05, 
    time_min = time_min, time_max = time_max, verbose = T)
debug: while (i_req <= n_reqs) {
    i_t_beg <- (i_req - 1) * n_t_per_req + 1
    i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
    t_req <- times_todo[c(i_t_beg, i_t_end)]
    t_req_str <- format_ISO8601(t_req, usetz = "Z")
    if (verbose) 
        message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
    ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
        ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
        0), nc)
    unlink(ncs0)
    nc_retry <- T
    nc_n_try <- 1
    n_max_retries
    while (nc_retry) {
        res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
            url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
                bbox[["xmax"]]), latitude = c(bbox[["ymin"]], 
                bbox[["ymax"]]), time = t_req_str, fmt = "nc", 
            store = rerddap::disk(path = dir_nc)))
        if (inherits(res, "try-error")) {
            err <- attr(res, "condition")
            msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
            nc_n_try <- nc_n_try + 1
            if (nc_n_try > n_max_retries) {
                stop(msg)
            }
            else {
                message(msg, "\nRETRYing...")
                Sys.sleep(1)
            }
        }
        else {
            nc_retry <- F
        }
    }
    i_req <- i_req + 1
}
debug: i_t_beg <- (i_req - 1) * n_t_per_req + 1
debug: i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
debug: t_req <- times_todo[c(i_t_beg, i_t_end)]
debug: t_req_str <- format_ISO8601(t_req, usetz = "Z")
debug: if (verbose) message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
debug: message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
Fetching request 1 of 1 (2000-01-01 to 2000-12-01) ~ 19:34:30 UTC
debug: ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
    0), nc)
debug: unlink(ncs0)
debug: nc_retry <- T
debug: nc_n_try <- 1
debug: n_max_retries
debug: while (nc_retry) {
    res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
        url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
            bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
        time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
    if (inherits(res, "try-error")) {
        err <- attr(res, "condition")
        msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
        nc_n_try <- nc_n_try + 1
        if (nc_n_try > n_max_retries) {
            stop(msg)
        }
        else {
            message(msg, "\nRETRYing...")
            Sys.sleep(1)
        }
    }
    else {
        nc_retry <- F
    }
}
debug: res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
    url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
        bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
    time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
debug: if (inherits(res, "try-error")) {
    err <- attr(res, "condition")
    msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
    nc_n_try <- nc_n_try + 1
    if (nc_n_try > n_max_retries) {
        stop(msg)
    }
    else {
        message(msg, "\nRETRYing...")
        Sys.sleep(1)
    }
} else {
    nc_retry <- F
}
debug: nc_retry <- F
debug: (while) nc_retry
debug: i_req <- i_req + 1
debug: (while) i_req <= n_reqs
debug: ncs <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size > 
    0), nc)
debug: r <- terra::rast(ncs)
debug: stopifnot(all(class(terra::time(r)) %in% c("POSIXct", "POSIXt")))
debug: idx <- dplyr::pull(dplyr::filter(dplyr::arrange(dplyr::tibble(idx = 1:terra::nlyr(r), 
    time = terra::time(r)), time), !duplicated(time)), idx)
debug: r <- terra::subset(r, idx)
debug: stopifnot(terra::crs(r, proj = T) == wgs84)
debug: if (mask_tif) r <- terra::mask(r, sf_zones)
debug: lyrs <- glue("{var}|{terra::time(r)}")
debug: if (length(dims_other) > 0 && !all(length(dims[dims_other]) == 
    1)) stop(glue("Other dimensions not yet supported: {paste(dims_other, collapse = ',')}"))
debug: names(r) <- lyrs
debug: if (!is.null(rast_tif)) {
    if (fs::file_exists(rast_tif)) {
        r_tmp_tif <- tempfile(fileext = ".tif")
        r_tmp <- c(rast(rast_tif), r)
        r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
        terra::writeRaster(r_tmp, r_tmp_tif)
        fs::file_delete(rast_tif)
        fs::file_move(r_tmp_tif, rast_tif)
        rm(r)
        rm(r_tmp)
    }
    else {
        terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
    }
    r <- terra::rast(rast_tif)
}
debug: if (fs::file_exists(rast_tif)) {
    r_tmp_tif <- tempfile(fileext = ".tif")
    r_tmp <- c(rast(rast_tif), r)
    r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
    terra::writeRaster(r_tmp, r_tmp_tif)
    fs::file_delete(rast_tif)
    fs::file_move(r_tmp_tif, rast_tif)
    rm(r)
    rm(r_tmp)
} else {
    terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
}
debug: terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
debug: r <- terra::rast(rast_tif)
debug: d_r <- mutate(tidyr::pivot_longer(sf::st_drop_geometry(sf::st_as_sf(terra::zonal(x = r, 
    z = terra::vect(dplyr::select(sf_zones, dplyr::all_of(fld_zones))), 
    fun = zonal_fun, exact = T, na.rm = T, as.polygons = T))), 
    cols = -dplyr::any_of(fld_zones), names_to = "lyr", values_to = zonal_fun), 
    time = readr::parse_datetime(str_replace(lyr, glue("{var}\\|(.*)"), 
        "\\1")))
debug: if (!is.null(zonal_csv)) write_csv(d_r, zonal_csv)
debug: write_csv(d_r, zonal_csv)
debug: if (!keep_nc) unlink(dir_nc, recursive = T)
debug: unlink(dir_nc, recursive = T)
debug: return(d_r)
Downloading 1 requests, up to 248 time slices each
Called from: extractr::ed_extract(ed, var = v, sf_zones = ply, bbox = bb, 
    mask_tif = F, rast_tif = glue("{dir_out}/{nms}/{yr}.tif"), 
    zonal_fun = "mean", zonal_csv = glue("{dir_out}/{nms}/{yr}.csv"), 
    dir_nc = glue("{dir_out}/{nms}/{yr}_nc"), keep_nc = F, n_max_vals_per_req = 1e+05, 
    time_min = time_min, time_max = time_max, verbose = T)
debug: while (i_req <= n_reqs) {
    i_t_beg <- (i_req - 1) * n_t_per_req + 1
    i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
    t_req <- times_todo[c(i_t_beg, i_t_end)]
    t_req_str <- format_ISO8601(t_req, usetz = "Z")
    if (verbose) 
        message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
    ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
        ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
        0), nc)
    unlink(ncs0)
    nc_retry <- T
    nc_n_try <- 1
    n_max_retries
    while (nc_retry) {
        res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
            url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
                bbox[["xmax"]]), latitude = c(bbox[["ymin"]], 
                bbox[["ymax"]]), time = t_req_str, fmt = "nc", 
            store = rerddap::disk(path = dir_nc)))
        if (inherits(res, "try-error")) {
            err <- attr(res, "condition")
            msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
            nc_n_try <- nc_n_try + 1
            if (nc_n_try > n_max_retries) {
                stop(msg)
            }
            else {
                message(msg, "\nRETRYing...")
                Sys.sleep(1)
            }
        }
        else {
            nc_retry <- F
        }
    }
    i_req <- i_req + 1
}
debug: i_t_beg <- (i_req - 1) * n_t_per_req + 1
debug: i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
debug: t_req <- times_todo[c(i_t_beg, i_t_end)]
debug: t_req_str <- format_ISO8601(t_req, usetz = "Z")
debug: if (verbose) message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
debug: message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
Fetching request 1 of 1 (2001-01-01 to 2001-12-01) ~ 19:34:32 UTC
debug: ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
    0), nc)
debug: unlink(ncs0)
debug: nc_retry <- T
debug: nc_n_try <- 1
debug: n_max_retries
debug: while (nc_retry) {
    res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
        url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
            bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
        time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
    if (inherits(res, "try-error")) {
        err <- attr(res, "condition")
        msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
        nc_n_try <- nc_n_try + 1
        if (nc_n_try > n_max_retries) {
            stop(msg)
        }
        else {
            message(msg, "\nRETRYing...")
            Sys.sleep(1)
        }
    }
    else {
        nc_retry <- F
    }
}
debug: res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
    url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
        bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
    time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
debug: if (inherits(res, "try-error")) {
    err <- attr(res, "condition")
    msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
    nc_n_try <- nc_n_try + 1
    if (nc_n_try > n_max_retries) {
        stop(msg)
    }
    else {
        message(msg, "\nRETRYing...")
        Sys.sleep(1)
    }
} else {
    nc_retry <- F
}
debug: nc_retry <- F
debug: (while) nc_retry
debug: i_req <- i_req + 1
debug: (while) i_req <= n_reqs
debug: ncs <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size > 
    0), nc)
debug: r <- terra::rast(ncs)
debug: stopifnot(all(class(terra::time(r)) %in% c("POSIXct", "POSIXt")))
debug: idx <- dplyr::pull(dplyr::filter(dplyr::arrange(dplyr::tibble(idx = 1:terra::nlyr(r), 
    time = terra::time(r)), time), !duplicated(time)), idx)
debug: r <- terra::subset(r, idx)
debug: stopifnot(terra::crs(r, proj = T) == wgs84)
debug: if (mask_tif) r <- terra::mask(r, sf_zones)
debug: lyrs <- glue("{var}|{terra::time(r)}")
debug: if (length(dims_other) > 0 && !all(length(dims[dims_other]) == 
    1)) stop(glue("Other dimensions not yet supported: {paste(dims_other, collapse = ',')}"))
debug: names(r) <- lyrs
debug: if (!is.null(rast_tif)) {
    if (fs::file_exists(rast_tif)) {
        r_tmp_tif <- tempfile(fileext = ".tif")
        r_tmp <- c(rast(rast_tif), r)
        r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
        terra::writeRaster(r_tmp, r_tmp_tif)
        fs::file_delete(rast_tif)
        fs::file_move(r_tmp_tif, rast_tif)
        rm(r)
        rm(r_tmp)
    }
    else {
        terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
    }
    r <- terra::rast(rast_tif)
}
debug: if (fs::file_exists(rast_tif)) {
    r_tmp_tif <- tempfile(fileext = ".tif")
    r_tmp <- c(rast(rast_tif), r)
    r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
    terra::writeRaster(r_tmp, r_tmp_tif)
    fs::file_delete(rast_tif)
    fs::file_move(r_tmp_tif, rast_tif)
    rm(r)
    rm(r_tmp)
} else {
    terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
}
debug: terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
debug: r <- terra::rast(rast_tif)
debug: d_r <- mutate(tidyr::pivot_longer(sf::st_drop_geometry(sf::st_as_sf(terra::zonal(x = r, 
    z = terra::vect(dplyr::select(sf_zones, dplyr::all_of(fld_zones))), 
    fun = zonal_fun, exact = T, na.rm = T, as.polygons = T))), 
    cols = -dplyr::any_of(fld_zones), names_to = "lyr", values_to = zonal_fun), 
    time = readr::parse_datetime(str_replace(lyr, glue("{var}\\|(.*)"), 
        "\\1")))
debug: if (!is.null(zonal_csv)) write_csv(d_r, zonal_csv)
debug: write_csv(d_r, zonal_csv)
debug: if (!keep_nc) unlink(dir_nc, recursive = T)
debug: unlink(dir_nc, recursive = T)
debug: return(d_r)
Downloading 1 requests, up to 248 time slices each
Called from: extractr::ed_extract(ed, var = v, sf_zones = ply, bbox = bb, 
    mask_tif = F, rast_tif = glue("{dir_out}/{nms}/{yr}.tif"), 
    zonal_fun = "mean", zonal_csv = glue("{dir_out}/{nms}/{yr}.csv"), 
    dir_nc = glue("{dir_out}/{nms}/{yr}_nc"), keep_nc = F, n_max_vals_per_req = 1e+05, 
    time_min = time_min, time_max = time_max, verbose = T)
debug: while (i_req <= n_reqs) {
    i_t_beg <- (i_req - 1) * n_t_per_req + 1
    i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
    t_req <- times_todo[c(i_t_beg, i_t_end)]
    t_req_str <- format_ISO8601(t_req, usetz = "Z")
    if (verbose) 
        message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
    ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
        ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
        0), nc)
    unlink(ncs0)
    nc_retry <- T
    nc_n_try <- 1
    n_max_retries
    while (nc_retry) {
        res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
            url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
                bbox[["xmax"]]), latitude = c(bbox[["ymin"]], 
                bbox[["ymax"]]), time = t_req_str, fmt = "nc", 
            store = rerddap::disk(path = dir_nc)))
        if (inherits(res, "try-error")) {
            err <- attr(res, "condition")
            msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
            nc_n_try <- nc_n_try + 1
            if (nc_n_try > n_max_retries) {
                stop(msg)
            }
            else {
                message(msg, "\nRETRYing...")
                Sys.sleep(1)
            }
        }
        else {
            nc_retry <- F
        }
    }
    i_req <- i_req + 1
}
debug: i_t_beg <- (i_req - 1) * n_t_per_req + 1
debug: i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
debug: t_req <- times_todo[c(i_t_beg, i_t_end)]
debug: t_req_str <- format_ISO8601(t_req, usetz = "Z")
debug: if (verbose) message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
debug: message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
Fetching request 1 of 1 (2002-01-01 to 2002-12-01) ~ 19:34:34 UTC
debug: ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
    0), nc)
debug: unlink(ncs0)
debug: nc_retry <- T
debug: nc_n_try <- 1
debug: n_max_retries
debug: while (nc_retry) {
    res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
        url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
            bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
        time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
    if (inherits(res, "try-error")) {
        err <- attr(res, "condition")
        msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
        nc_n_try <- nc_n_try + 1
        if (nc_n_try > n_max_retries) {
            stop(msg)
        }
        else {
            message(msg, "\nRETRYing...")
            Sys.sleep(1)
        }
    }
    else {
        nc_retry <- F
    }
}
debug: res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
    url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
        bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
    time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
debug: if (inherits(res, "try-error")) {
    err <- attr(res, "condition")
    msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
    nc_n_try <- nc_n_try + 1
    if (nc_n_try > n_max_retries) {
        stop(msg)
    }
    else {
        message(msg, "\nRETRYing...")
        Sys.sleep(1)
    }
} else {
    nc_retry <- F
}
debug: nc_retry <- F
debug: (while) nc_retry
debug: i_req <- i_req + 1
debug: (while) i_req <= n_reqs
debug: ncs <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size > 
    0), nc)
debug: r <- terra::rast(ncs)
debug: stopifnot(all(class(terra::time(r)) %in% c("POSIXct", "POSIXt")))
debug: idx <- dplyr::pull(dplyr::filter(dplyr::arrange(dplyr::tibble(idx = 1:terra::nlyr(r), 
    time = terra::time(r)), time), !duplicated(time)), idx)
debug: r <- terra::subset(r, idx)
debug: stopifnot(terra::crs(r, proj = T) == wgs84)
debug: if (mask_tif) r <- terra::mask(r, sf_zones)
debug: lyrs <- glue("{var}|{terra::time(r)}")
debug: if (length(dims_other) > 0 && !all(length(dims[dims_other]) == 
    1)) stop(glue("Other dimensions not yet supported: {paste(dims_other, collapse = ',')}"))
debug: names(r) <- lyrs
debug: if (!is.null(rast_tif)) {
    if (fs::file_exists(rast_tif)) {
        r_tmp_tif <- tempfile(fileext = ".tif")
        r_tmp <- c(rast(rast_tif), r)
        r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
        terra::writeRaster(r_tmp, r_tmp_tif)
        fs::file_delete(rast_tif)
        fs::file_move(r_tmp_tif, rast_tif)
        rm(r)
        rm(r_tmp)
    }
    else {
        terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
    }
    r <- terra::rast(rast_tif)
}
debug: if (fs::file_exists(rast_tif)) {
    r_tmp_tif <- tempfile(fileext = ".tif")
    r_tmp <- c(rast(rast_tif), r)
    r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
    terra::writeRaster(r_tmp, r_tmp_tif)
    fs::file_delete(rast_tif)
    fs::file_move(r_tmp_tif, rast_tif)
    rm(r)
    rm(r_tmp)
} else {
    terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
}
debug: terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
debug: r <- terra::rast(rast_tif)
debug: d_r <- mutate(tidyr::pivot_longer(sf::st_drop_geometry(sf::st_as_sf(terra::zonal(x = r, 
    z = terra::vect(dplyr::select(sf_zones, dplyr::all_of(fld_zones))), 
    fun = zonal_fun, exact = T, na.rm = T, as.polygons = T))), 
    cols = -dplyr::any_of(fld_zones), names_to = "lyr", values_to = zonal_fun), 
    time = readr::parse_datetime(str_replace(lyr, glue("{var}\\|(.*)"), 
        "\\1")))
debug: if (!is.null(zonal_csv)) write_csv(d_r, zonal_csv)
debug: write_csv(d_r, zonal_csv)
debug: if (!keep_nc) unlink(dir_nc, recursive = T)
debug: unlink(dir_nc, recursive = T)
debug: return(d_r)
Downloading 1 requests, up to 248 time slices each
Called from: extractr::ed_extract(ed, var = v, sf_zones = ply, bbox = bb, 
    mask_tif = F, rast_tif = glue("{dir_out}/{nms}/{yr}.tif"), 
    zonal_fun = "mean", zonal_csv = glue("{dir_out}/{nms}/{yr}.csv"), 
    dir_nc = glue("{dir_out}/{nms}/{yr}_nc"), keep_nc = F, n_max_vals_per_req = 1e+05, 
    time_min = time_min, time_max = time_max, verbose = T)
debug: while (i_req <= n_reqs) {
    i_t_beg <- (i_req - 1) * n_t_per_req + 1
    i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
    t_req <- times_todo[c(i_t_beg, i_t_end)]
    t_req_str <- format_ISO8601(t_req, usetz = "Z")
    if (verbose) 
        message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
    ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
        ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
        0), nc)
    unlink(ncs0)
    nc_retry <- T
    nc_n_try <- 1
    n_max_retries
    while (nc_retry) {
        res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
            url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
                bbox[["xmax"]]), latitude = c(bbox[["ymin"]], 
                bbox[["ymax"]]), time = t_req_str, fmt = "nc", 
            store = rerddap::disk(path = dir_nc)))
        if (inherits(res, "try-error")) {
            err <- attr(res, "condition")
            msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
            nc_n_try <- nc_n_try + 1
            if (nc_n_try > n_max_retries) {
                stop(msg)
            }
            else {
                message(msg, "\nRETRYing...")
                Sys.sleep(1)
            }
        }
        else {
            nc_retry <- F
        }
    }
    i_req <- i_req + 1
}
debug: i_t_beg <- (i_req - 1) * n_t_per_req + 1
debug: i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
debug: t_req <- times_todo[c(i_t_beg, i_t_end)]
debug: t_req_str <- format_ISO8601(t_req, usetz = "Z")
debug: if (verbose) message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
debug: message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
Fetching request 1 of 1 (2003-01-01 to 2003-12-01) ~ 19:34:36 UTC
debug: ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
    0), nc)
debug: unlink(ncs0)
debug: nc_retry <- T
debug: nc_n_try <- 1
debug: n_max_retries
debug: while (nc_retry) {
    res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
        url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
            bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
        time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
    if (inherits(res, "try-error")) {
        err <- attr(res, "condition")
        msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
        nc_n_try <- nc_n_try + 1
        if (nc_n_try > n_max_retries) {
            stop(msg)
        }
        else {
            message(msg, "\nRETRYing...")
            Sys.sleep(1)
        }
    }
    else {
        nc_retry <- F
    }
}
debug: res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
    url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
        bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
    time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
debug: if (inherits(res, "try-error")) {
    err <- attr(res, "condition")
    msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
    nc_n_try <- nc_n_try + 1
    if (nc_n_try > n_max_retries) {
        stop(msg)
    }
    else {
        message(msg, "\nRETRYing...")
        Sys.sleep(1)
    }
} else {
    nc_retry <- F
}
debug: nc_retry <- F
debug: (while) nc_retry
debug: i_req <- i_req + 1
debug: (while) i_req <= n_reqs
debug: ncs <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size > 
    0), nc)
debug: r <- terra::rast(ncs)
debug: stopifnot(all(class(terra::time(r)) %in% c("POSIXct", "POSIXt")))
debug: idx <- dplyr::pull(dplyr::filter(dplyr::arrange(dplyr::tibble(idx = 1:terra::nlyr(r), 
    time = terra::time(r)), time), !duplicated(time)), idx)
debug: r <- terra::subset(r, idx)
debug: stopifnot(terra::crs(r, proj = T) == wgs84)
debug: if (mask_tif) r <- terra::mask(r, sf_zones)
debug: lyrs <- glue("{var}|{terra::time(r)}")
debug: if (length(dims_other) > 0 && !all(length(dims[dims_other]) == 
    1)) stop(glue("Other dimensions not yet supported: {paste(dims_other, collapse = ',')}"))
debug: names(r) <- lyrs
debug: if (!is.null(rast_tif)) {
    if (fs::file_exists(rast_tif)) {
        r_tmp_tif <- tempfile(fileext = ".tif")
        r_tmp <- c(rast(rast_tif), r)
        r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
        terra::writeRaster(r_tmp, r_tmp_tif)
        fs::file_delete(rast_tif)
        fs::file_move(r_tmp_tif, rast_tif)
        rm(r)
        rm(r_tmp)
    }
    else {
        terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
    }
    r <- terra::rast(rast_tif)
}
debug: if (fs::file_exists(rast_tif)) {
    r_tmp_tif <- tempfile(fileext = ".tif")
    r_tmp <- c(rast(rast_tif), r)
    r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
    terra::writeRaster(r_tmp, r_tmp_tif)
    fs::file_delete(rast_tif)
    fs::file_move(r_tmp_tif, rast_tif)
    rm(r)
    rm(r_tmp)
} else {
    terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
}
debug: terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
debug: r <- terra::rast(rast_tif)
debug: d_r <- mutate(tidyr::pivot_longer(sf::st_drop_geometry(sf::st_as_sf(terra::zonal(x = r, 
    z = terra::vect(dplyr::select(sf_zones, dplyr::all_of(fld_zones))), 
    fun = zonal_fun, exact = T, na.rm = T, as.polygons = T))), 
    cols = -dplyr::any_of(fld_zones), names_to = "lyr", values_to = zonal_fun), 
    time = readr::parse_datetime(str_replace(lyr, glue("{var}\\|(.*)"), 
        "\\1")))
debug: if (!is.null(zonal_csv)) write_csv(d_r, zonal_csv)
debug: write_csv(d_r, zonal_csv)
debug: if (!keep_nc) unlink(dir_nc, recursive = T)
debug: unlink(dir_nc, recursive = T)
debug: return(d_r)
Downloading 1 requests, up to 248 time slices each
Called from: extractr::ed_extract(ed, var = v, sf_zones = ply, bbox = bb, 
    mask_tif = F, rast_tif = glue("{dir_out}/{nms}/{yr}.tif"), 
    zonal_fun = "mean", zonal_csv = glue("{dir_out}/{nms}/{yr}.csv"), 
    dir_nc = glue("{dir_out}/{nms}/{yr}_nc"), keep_nc = F, n_max_vals_per_req = 1e+05, 
    time_min = time_min, time_max = time_max, verbose = T)
debug: while (i_req <= n_reqs) {
    i_t_beg <- (i_req - 1) * n_t_per_req + 1
    i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
    t_req <- times_todo[c(i_t_beg, i_t_end)]
    t_req_str <- format_ISO8601(t_req, usetz = "Z")
    if (verbose) 
        message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
    ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
        ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
        0), nc)
    unlink(ncs0)
    nc_retry <- T
    nc_n_try <- 1
    n_max_retries
    while (nc_retry) {
        res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
            url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
                bbox[["xmax"]]), latitude = c(bbox[["ymin"]], 
                bbox[["ymax"]]), time = t_req_str, fmt = "nc", 
            store = rerddap::disk(path = dir_nc)))
        if (inherits(res, "try-error")) {
            err <- attr(res, "condition")
            msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
            nc_n_try <- nc_n_try + 1
            if (nc_n_try > n_max_retries) {
                stop(msg)
            }
            else {
                message(msg, "\nRETRYing...")
                Sys.sleep(1)
            }
        }
        else {
            nc_retry <- F
        }
    }
    i_req <- i_req + 1
}
debug: i_t_beg <- (i_req - 1) * n_t_per_req + 1
debug: i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
debug: t_req <- times_todo[c(i_t_beg, i_t_end)]
debug: t_req_str <- format_ISO8601(t_req, usetz = "Z")
debug: if (verbose) message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
debug: message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
Fetching request 1 of 1 (2004-01-01 to 2004-12-01) ~ 19:34:37 UTC
debug: ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
    0), nc)
debug: unlink(ncs0)
debug: nc_retry <- T
debug: nc_n_try <- 1
debug: n_max_retries
debug: while (nc_retry) {
    res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
        url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
            bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
        time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
    if (inherits(res, "try-error")) {
        err <- attr(res, "condition")
        msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
        nc_n_try <- nc_n_try + 1
        if (nc_n_try > n_max_retries) {
            stop(msg)
        }
        else {
            message(msg, "\nRETRYing...")
            Sys.sleep(1)
        }
    }
    else {
        nc_retry <- F
    }
}
debug: res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
    url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
        bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
    time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
debug: if (inherits(res, "try-error")) {
    err <- attr(res, "condition")
    msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
    nc_n_try <- nc_n_try + 1
    if (nc_n_try > n_max_retries) {
        stop(msg)
    }
    else {
        message(msg, "\nRETRYing...")
        Sys.sleep(1)
    }
} else {
    nc_retry <- F
}
debug: nc_retry <- F
debug: (while) nc_retry
debug: i_req <- i_req + 1
debug: (while) i_req <= n_reqs
debug: ncs <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size > 
    0), nc)
debug: r <- terra::rast(ncs)
debug: stopifnot(all(class(terra::time(r)) %in% c("POSIXct", "POSIXt")))
debug: idx <- dplyr::pull(dplyr::filter(dplyr::arrange(dplyr::tibble(idx = 1:terra::nlyr(r), 
    time = terra::time(r)), time), !duplicated(time)), idx)
debug: r <- terra::subset(r, idx)
debug: stopifnot(terra::crs(r, proj = T) == wgs84)
debug: if (mask_tif) r <- terra::mask(r, sf_zones)
debug: lyrs <- glue("{var}|{terra::time(r)}")
debug: if (length(dims_other) > 0 && !all(length(dims[dims_other]) == 
    1)) stop(glue("Other dimensions not yet supported: {paste(dims_other, collapse = ',')}"))
debug: names(r) <- lyrs
debug: if (!is.null(rast_tif)) {
    if (fs::file_exists(rast_tif)) {
        r_tmp_tif <- tempfile(fileext = ".tif")
        r_tmp <- c(rast(rast_tif), r)
        r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
        terra::writeRaster(r_tmp, r_tmp_tif)
        fs::file_delete(rast_tif)
        fs::file_move(r_tmp_tif, rast_tif)
        rm(r)
        rm(r_tmp)
    }
    else {
        terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
    }
    r <- terra::rast(rast_tif)
}
debug: if (fs::file_exists(rast_tif)) {
    r_tmp_tif <- tempfile(fileext = ".tif")
    r_tmp <- c(rast(rast_tif), r)
    r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
    terra::writeRaster(r_tmp, r_tmp_tif)
    fs::file_delete(rast_tif)
    fs::file_move(r_tmp_tif, rast_tif)
    rm(r)
    rm(r_tmp)
} else {
    terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
}
debug: terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
debug: r <- terra::rast(rast_tif)
debug: d_r <- mutate(tidyr::pivot_longer(sf::st_drop_geometry(sf::st_as_sf(terra::zonal(x = r, 
    z = terra::vect(dplyr::select(sf_zones, dplyr::all_of(fld_zones))), 
    fun = zonal_fun, exact = T, na.rm = T, as.polygons = T))), 
    cols = -dplyr::any_of(fld_zones), names_to = "lyr", values_to = zonal_fun), 
    time = readr::parse_datetime(str_replace(lyr, glue("{var}\\|(.*)"), 
        "\\1")))
debug: if (!is.null(zonal_csv)) write_csv(d_r, zonal_csv)
debug: write_csv(d_r, zonal_csv)
debug: if (!keep_nc) unlink(dir_nc, recursive = T)
debug: unlink(dir_nc, recursive = T)
debug: return(d_r)
Downloading 1 requests, up to 248 time slices each
Called from: extractr::ed_extract(ed, var = v, sf_zones = ply, bbox = bb, 
    mask_tif = F, rast_tif = glue("{dir_out}/{nms}/{yr}.tif"), 
    zonal_fun = "mean", zonal_csv = glue("{dir_out}/{nms}/{yr}.csv"), 
    dir_nc = glue("{dir_out}/{nms}/{yr}_nc"), keep_nc = F, n_max_vals_per_req = 1e+05, 
    time_min = time_min, time_max = time_max, verbose = T)
debug: while (i_req <= n_reqs) {
    i_t_beg <- (i_req - 1) * n_t_per_req + 1
    i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
    t_req <- times_todo[c(i_t_beg, i_t_end)]
    t_req_str <- format_ISO8601(t_req, usetz = "Z")
    if (verbose) 
        message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
    ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
        ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
        0), nc)
    unlink(ncs0)
    nc_retry <- T
    nc_n_try <- 1
    n_max_retries
    while (nc_retry) {
        res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
            url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
                bbox[["xmax"]]), latitude = c(bbox[["ymin"]], 
                bbox[["ymax"]]), time = t_req_str, fmt = "nc", 
            store = rerddap::disk(path = dir_nc)))
        if (inherits(res, "try-error")) {
            err <- attr(res, "condition")
            msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
            nc_n_try <- nc_n_try + 1
            if (nc_n_try > n_max_retries) {
                stop(msg)
            }
            else {
                message(msg, "\nRETRYing...")
                Sys.sleep(1)
            }
        }
        else {
            nc_retry <- F
        }
    }
    i_req <- i_req + 1
}
debug: i_t_beg <- (i_req - 1) * n_t_per_req + 1
debug: i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
debug: t_req <- times_todo[c(i_t_beg, i_t_end)]
debug: t_req_str <- format_ISO8601(t_req, usetz = "Z")
debug: if (verbose) message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
debug: message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
Fetching request 1 of 1 (2005-01-01 to 2005-12-01) ~ 19:34:39 UTC
debug: ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
    0), nc)
debug: unlink(ncs0)
debug: nc_retry <- T
debug: nc_n_try <- 1
debug: n_max_retries
debug: while (nc_retry) {
    res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
        url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
            bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
        time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
    if (inherits(res, "try-error")) {
        err <- attr(res, "condition")
        msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
        nc_n_try <- nc_n_try + 1
        if (nc_n_try > n_max_retries) {
            stop(msg)
        }
        else {
            message(msg, "\nRETRYing...")
            Sys.sleep(1)
        }
    }
    else {
        nc_retry <- F
    }
}
debug: res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
    url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
        bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
    time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
debug: if (inherits(res, "try-error")) {
    err <- attr(res, "condition")
    msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
    nc_n_try <- nc_n_try + 1
    if (nc_n_try > n_max_retries) {
        stop(msg)
    }
    else {
        message(msg, "\nRETRYing...")
        Sys.sleep(1)
    }
} else {
    nc_retry <- F
}
debug: nc_retry <- F
debug: (while) nc_retry
debug: i_req <- i_req + 1
debug: (while) i_req <= n_reqs
debug: ncs <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size > 
    0), nc)
debug: r <- terra::rast(ncs)
debug: stopifnot(all(class(terra::time(r)) %in% c("POSIXct", "POSIXt")))
debug: idx <- dplyr::pull(dplyr::filter(dplyr::arrange(dplyr::tibble(idx = 1:terra::nlyr(r), 
    time = terra::time(r)), time), !duplicated(time)), idx)
debug: r <- terra::subset(r, idx)
debug: stopifnot(terra::crs(r, proj = T) == wgs84)
debug: if (mask_tif) r <- terra::mask(r, sf_zones)
debug: lyrs <- glue("{var}|{terra::time(r)}")
debug: if (length(dims_other) > 0 && !all(length(dims[dims_other]) == 
    1)) stop(glue("Other dimensions not yet supported: {paste(dims_other, collapse = ',')}"))
debug: names(r) <- lyrs
debug: if (!is.null(rast_tif)) {
    if (fs::file_exists(rast_tif)) {
        r_tmp_tif <- tempfile(fileext = ".tif")
        r_tmp <- c(rast(rast_tif), r)
        r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
        terra::writeRaster(r_tmp, r_tmp_tif)
        fs::file_delete(rast_tif)
        fs::file_move(r_tmp_tif, rast_tif)
        rm(r)
        rm(r_tmp)
    }
    else {
        terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
    }
    r <- terra::rast(rast_tif)
}
debug: if (fs::file_exists(rast_tif)) {
    r_tmp_tif <- tempfile(fileext = ".tif")
    r_tmp <- c(rast(rast_tif), r)
    r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
    terra::writeRaster(r_tmp, r_tmp_tif)
    fs::file_delete(rast_tif)
    fs::file_move(r_tmp_tif, rast_tif)
    rm(r)
    rm(r_tmp)
} else {
    terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
}
debug: terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
debug: r <- terra::rast(rast_tif)
debug: d_r <- mutate(tidyr::pivot_longer(sf::st_drop_geometry(sf::st_as_sf(terra::zonal(x = r, 
    z = terra::vect(dplyr::select(sf_zones, dplyr::all_of(fld_zones))), 
    fun = zonal_fun, exact = T, na.rm = T, as.polygons = T))), 
    cols = -dplyr::any_of(fld_zones), names_to = "lyr", values_to = zonal_fun), 
    time = readr::parse_datetime(str_replace(lyr, glue("{var}\\|(.*)"), 
        "\\1")))
debug: if (!is.null(zonal_csv)) write_csv(d_r, zonal_csv)
debug: write_csv(d_r, zonal_csv)
debug: if (!keep_nc) unlink(dir_nc, recursive = T)
debug: unlink(dir_nc, recursive = T)
debug: return(d_r)
Downloading 1 requests, up to 248 time slices each
Called from: extractr::ed_extract(ed, var = v, sf_zones = ply, bbox = bb, 
    mask_tif = F, rast_tif = glue("{dir_out}/{nms}/{yr}.tif"), 
    zonal_fun = "mean", zonal_csv = glue("{dir_out}/{nms}/{yr}.csv"), 
    dir_nc = glue("{dir_out}/{nms}/{yr}_nc"), keep_nc = F, n_max_vals_per_req = 1e+05, 
    time_min = time_min, time_max = time_max, verbose = T)
debug: while (i_req <= n_reqs) {
    i_t_beg <- (i_req - 1) * n_t_per_req + 1
    i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
    t_req <- times_todo[c(i_t_beg, i_t_end)]
    t_req_str <- format_ISO8601(t_req, usetz = "Z")
    if (verbose) 
        message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
    ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
        ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
        0), nc)
    unlink(ncs0)
    nc_retry <- T
    nc_n_try <- 1
    n_max_retries
    while (nc_retry) {
        res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
            url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
                bbox[["xmax"]]), latitude = c(bbox[["ymin"]], 
                bbox[["ymax"]]), time = t_req_str, fmt = "nc", 
            store = rerddap::disk(path = dir_nc)))
        if (inherits(res, "try-error")) {
            err <- attr(res, "condition")
            msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
            nc_n_try <- nc_n_try + 1
            if (nc_n_try > n_max_retries) {
                stop(msg)
            }
            else {
                message(msg, "\nRETRYing...")
                Sys.sleep(1)
            }
        }
        else {
            nc_retry <- F
        }
    }
    i_req <- i_req + 1
}
debug: i_t_beg <- (i_req - 1) * n_t_per_req + 1
debug: i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
debug: t_req <- times_todo[c(i_t_beg, i_t_end)]
debug: t_req_str <- format_ISO8601(t_req, usetz = "Z")
debug: if (verbose) message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
debug: message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
Fetching request 1 of 1 (2006-01-01 to 2006-12-01) ~ 19:34:41 UTC
debug: ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
    0), nc)
debug: unlink(ncs0)
debug: nc_retry <- T
debug: nc_n_try <- 1
debug: n_max_retries
debug: while (nc_retry) {
    res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
        url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
            bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
        time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
    if (inherits(res, "try-error")) {
        err <- attr(res, "condition")
        msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
        nc_n_try <- nc_n_try + 1
        if (nc_n_try > n_max_retries) {
            stop(msg)
        }
        else {
            message(msg, "\nRETRYing...")
            Sys.sleep(1)
        }
    }
    else {
        nc_retry <- F
    }
}
debug: res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
    url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
        bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
    time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
debug: if (inherits(res, "try-error")) {
    err <- attr(res, "condition")
    msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
    nc_n_try <- nc_n_try + 1
    if (nc_n_try > n_max_retries) {
        stop(msg)
    }
    else {
        message(msg, "\nRETRYing...")
        Sys.sleep(1)
    }
} else {
    nc_retry <- F
}
debug: nc_retry <- F
debug: (while) nc_retry
debug: i_req <- i_req + 1
debug: (while) i_req <= n_reqs
debug: ncs <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size > 
    0), nc)
debug: r <- terra::rast(ncs)
debug: stopifnot(all(class(terra::time(r)) %in% c("POSIXct", "POSIXt")))
debug: idx <- dplyr::pull(dplyr::filter(dplyr::arrange(dplyr::tibble(idx = 1:terra::nlyr(r), 
    time = terra::time(r)), time), !duplicated(time)), idx)
debug: r <- terra::subset(r, idx)
debug: stopifnot(terra::crs(r, proj = T) == wgs84)
debug: if (mask_tif) r <- terra::mask(r, sf_zones)
debug: lyrs <- glue("{var}|{terra::time(r)}")
debug: if (length(dims_other) > 0 && !all(length(dims[dims_other]) == 
    1)) stop(glue("Other dimensions not yet supported: {paste(dims_other, collapse = ',')}"))
debug: names(r) <- lyrs
debug: if (!is.null(rast_tif)) {
    if (fs::file_exists(rast_tif)) {
        r_tmp_tif <- tempfile(fileext = ".tif")
        r_tmp <- c(rast(rast_tif), r)
        r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
        terra::writeRaster(r_tmp, r_tmp_tif)
        fs::file_delete(rast_tif)
        fs::file_move(r_tmp_tif, rast_tif)
        rm(r)
        rm(r_tmp)
    }
    else {
        terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
    }
    r <- terra::rast(rast_tif)
}
debug: if (fs::file_exists(rast_tif)) {
    r_tmp_tif <- tempfile(fileext = ".tif")
    r_tmp <- c(rast(rast_tif), r)
    r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
    terra::writeRaster(r_tmp, r_tmp_tif)
    fs::file_delete(rast_tif)
    fs::file_move(r_tmp_tif, rast_tif)
    rm(r)
    rm(r_tmp)
} else {
    terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
}
debug: terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
debug: r <- terra::rast(rast_tif)
debug: d_r <- mutate(tidyr::pivot_longer(sf::st_drop_geometry(sf::st_as_sf(terra::zonal(x = r, 
    z = terra::vect(dplyr::select(sf_zones, dplyr::all_of(fld_zones))), 
    fun = zonal_fun, exact = T, na.rm = T, as.polygons = T))), 
    cols = -dplyr::any_of(fld_zones), names_to = "lyr", values_to = zonal_fun), 
    time = readr::parse_datetime(str_replace(lyr, glue("{var}\\|(.*)"), 
        "\\1")))
debug: if (!is.null(zonal_csv)) write_csv(d_r, zonal_csv)
debug: write_csv(d_r, zonal_csv)
debug: if (!keep_nc) unlink(dir_nc, recursive = T)
debug: unlink(dir_nc, recursive = T)
debug: return(d_r)
Downloading 1 requests, up to 248 time slices each
Called from: extractr::ed_extract(ed, var = v, sf_zones = ply, bbox = bb, 
    mask_tif = F, rast_tif = glue("{dir_out}/{nms}/{yr}.tif"), 
    zonal_fun = "mean", zonal_csv = glue("{dir_out}/{nms}/{yr}.csv"), 
    dir_nc = glue("{dir_out}/{nms}/{yr}_nc"), keep_nc = F, n_max_vals_per_req = 1e+05, 
    time_min = time_min, time_max = time_max, verbose = T)
debug: while (i_req <= n_reqs) {
    i_t_beg <- (i_req - 1) * n_t_per_req + 1
    i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
    t_req <- times_todo[c(i_t_beg, i_t_end)]
    t_req_str <- format_ISO8601(t_req, usetz = "Z")
    if (verbose) 
        message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
    ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
        ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
        0), nc)
    unlink(ncs0)
    nc_retry <- T
    nc_n_try <- 1
    n_max_retries
    while (nc_retry) {
        res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
            url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
                bbox[["xmax"]]), latitude = c(bbox[["ymin"]], 
                bbox[["ymax"]]), time = t_req_str, fmt = "nc", 
            store = rerddap::disk(path = dir_nc)))
        if (inherits(res, "try-error")) {
            err <- attr(res, "condition")
            msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
            nc_n_try <- nc_n_try + 1
            if (nc_n_try > n_max_retries) {
                stop(msg)
            }
            else {
                message(msg, "\nRETRYing...")
                Sys.sleep(1)
            }
        }
        else {
            nc_retry <- F
        }
    }
    i_req <- i_req + 1
}
debug: i_t_beg <- (i_req - 1) * n_t_per_req + 1
debug: i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
debug: t_req <- times_todo[c(i_t_beg, i_t_end)]
debug: t_req_str <- format_ISO8601(t_req, usetz = "Z")
debug: if (verbose) message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
debug: message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
Fetching request 1 of 1 (2007-01-01 to 2007-12-01) ~ 19:34:42 UTC
debug: ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
    0), nc)
debug: unlink(ncs0)
debug: nc_retry <- T
debug: nc_n_try <- 1
debug: n_max_retries
debug: while (nc_retry) {
    res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
        url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
            bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
        time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
    if (inherits(res, "try-error")) {
        err <- attr(res, "condition")
        msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
        nc_n_try <- nc_n_try + 1
        if (nc_n_try > n_max_retries) {
            stop(msg)
        }
        else {
            message(msg, "\nRETRYing...")
            Sys.sleep(1)
        }
    }
    else {
        nc_retry <- F
    }
}
debug: res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
    url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
        bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
    time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
debug: if (inherits(res, "try-error")) {
    err <- attr(res, "condition")
    msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
    nc_n_try <- nc_n_try + 1
    if (nc_n_try > n_max_retries) {
        stop(msg)
    }
    else {
        message(msg, "\nRETRYing...")
        Sys.sleep(1)
    }
} else {
    nc_retry <- F
}
debug: nc_retry <- F
debug: (while) nc_retry
debug: i_req <- i_req + 1
debug: (while) i_req <= n_reqs
debug: ncs <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size > 
    0), nc)
debug: r <- terra::rast(ncs)
debug: stopifnot(all(class(terra::time(r)) %in% c("POSIXct", "POSIXt")))
debug: idx <- dplyr::pull(dplyr::filter(dplyr::arrange(dplyr::tibble(idx = 1:terra::nlyr(r), 
    time = terra::time(r)), time), !duplicated(time)), idx)
debug: r <- terra::subset(r, idx)
debug: stopifnot(terra::crs(r, proj = T) == wgs84)
debug: if (mask_tif) r <- terra::mask(r, sf_zones)
debug: lyrs <- glue("{var}|{terra::time(r)}")
debug: if (length(dims_other) > 0 && !all(length(dims[dims_other]) == 
    1)) stop(glue("Other dimensions not yet supported: {paste(dims_other, collapse = ',')}"))
debug: names(r) <- lyrs
debug: if (!is.null(rast_tif)) {
    if (fs::file_exists(rast_tif)) {
        r_tmp_tif <- tempfile(fileext = ".tif")
        r_tmp <- c(rast(rast_tif), r)
        r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
        terra::writeRaster(r_tmp, r_tmp_tif)
        fs::file_delete(rast_tif)
        fs::file_move(r_tmp_tif, rast_tif)
        rm(r)
        rm(r_tmp)
    }
    else {
        terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
    }
    r <- terra::rast(rast_tif)
}
debug: if (fs::file_exists(rast_tif)) {
    r_tmp_tif <- tempfile(fileext = ".tif")
    r_tmp <- c(rast(rast_tif), r)
    r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
    terra::writeRaster(r_tmp, r_tmp_tif)
    fs::file_delete(rast_tif)
    fs::file_move(r_tmp_tif, rast_tif)
    rm(r)
    rm(r_tmp)
} else {
    terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
}
debug: terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
debug: r <- terra::rast(rast_tif)
debug: d_r <- mutate(tidyr::pivot_longer(sf::st_drop_geometry(sf::st_as_sf(terra::zonal(x = r, 
    z = terra::vect(dplyr::select(sf_zones, dplyr::all_of(fld_zones))), 
    fun = zonal_fun, exact = T, na.rm = T, as.polygons = T))), 
    cols = -dplyr::any_of(fld_zones), names_to = "lyr", values_to = zonal_fun), 
    time = readr::parse_datetime(str_replace(lyr, glue("{var}\\|(.*)"), 
        "\\1")))
debug: if (!is.null(zonal_csv)) write_csv(d_r, zonal_csv)
debug: write_csv(d_r, zonal_csv)
debug: if (!keep_nc) unlink(dir_nc, recursive = T)
debug: unlink(dir_nc, recursive = T)
debug: return(d_r)
Downloading 1 requests, up to 248 time slices each
Called from: extractr::ed_extract(ed, var = v, sf_zones = ply, bbox = bb, 
    mask_tif = F, rast_tif = glue("{dir_out}/{nms}/{yr}.tif"), 
    zonal_fun = "mean", zonal_csv = glue("{dir_out}/{nms}/{yr}.csv"), 
    dir_nc = glue("{dir_out}/{nms}/{yr}_nc"), keep_nc = F, n_max_vals_per_req = 1e+05, 
    time_min = time_min, time_max = time_max, verbose = T)
debug: while (i_req <= n_reqs) {
    i_t_beg <- (i_req - 1) * n_t_per_req + 1
    i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
    t_req <- times_todo[c(i_t_beg, i_t_end)]
    t_req_str <- format_ISO8601(t_req, usetz = "Z")
    if (verbose) 
        message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
    ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
        ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
        0), nc)
    unlink(ncs0)
    nc_retry <- T
    nc_n_try <- 1
    n_max_retries
    while (nc_retry) {
        res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
            url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
                bbox[["xmax"]]), latitude = c(bbox[["ymin"]], 
                bbox[["ymax"]]), time = t_req_str, fmt = "nc", 
            store = rerddap::disk(path = dir_nc)))
        if (inherits(res, "try-error")) {
            err <- attr(res, "condition")
            msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
            nc_n_try <- nc_n_try + 1
            if (nc_n_try > n_max_retries) {
                stop(msg)
            }
            else {
                message(msg, "\nRETRYing...")
                Sys.sleep(1)
            }
        }
        else {
            nc_retry <- F
        }
    }
    i_req <- i_req + 1
}
debug: i_t_beg <- (i_req - 1) * n_t_per_req + 1
debug: i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
debug: t_req <- times_todo[c(i_t_beg, i_t_end)]
debug: t_req_str <- format_ISO8601(t_req, usetz = "Z")
debug: if (verbose) message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
debug: message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
Fetching request 1 of 1 (2008-01-01 to 2008-12-01) ~ 19:34:44 UTC
debug: ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
    0), nc)
debug: unlink(ncs0)
debug: nc_retry <- T
debug: nc_n_try <- 1
debug: n_max_retries
debug: while (nc_retry) {
    res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
        url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
            bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
        time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
    if (inherits(res, "try-error")) {
        err <- attr(res, "condition")
        msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
        nc_n_try <- nc_n_try + 1
        if (nc_n_try > n_max_retries) {
            stop(msg)
        }
        else {
            message(msg, "\nRETRYing...")
            Sys.sleep(1)
        }
    }
    else {
        nc_retry <- F
    }
}
debug: res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
    url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
        bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
    time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
debug: if (inherits(res, "try-error")) {
    err <- attr(res, "condition")
    msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
    nc_n_try <- nc_n_try + 1
    if (nc_n_try > n_max_retries) {
        stop(msg)
    }
    else {
        message(msg, "\nRETRYing...")
        Sys.sleep(1)
    }
} else {
    nc_retry <- F
}
debug: nc_retry <- F
debug: (while) nc_retry
debug: i_req <- i_req + 1
debug: (while) i_req <= n_reqs
debug: ncs <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size > 
    0), nc)
debug: r <- terra::rast(ncs)
debug: stopifnot(all(class(terra::time(r)) %in% c("POSIXct", "POSIXt")))
debug: idx <- dplyr::pull(dplyr::filter(dplyr::arrange(dplyr::tibble(idx = 1:terra::nlyr(r), 
    time = terra::time(r)), time), !duplicated(time)), idx)
debug: r <- terra::subset(r, idx)
debug: stopifnot(terra::crs(r, proj = T) == wgs84)
debug: if (mask_tif) r <- terra::mask(r, sf_zones)
debug: lyrs <- glue("{var}|{terra::time(r)}")
debug: if (length(dims_other) > 0 && !all(length(dims[dims_other]) == 
    1)) stop(glue("Other dimensions not yet supported: {paste(dims_other, collapse = ',')}"))
debug: names(r) <- lyrs
debug: if (!is.null(rast_tif)) {
    if (fs::file_exists(rast_tif)) {
        r_tmp_tif <- tempfile(fileext = ".tif")
        r_tmp <- c(rast(rast_tif), r)
        r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
        terra::writeRaster(r_tmp, r_tmp_tif)
        fs::file_delete(rast_tif)
        fs::file_move(r_tmp_tif, rast_tif)
        rm(r)
        rm(r_tmp)
    }
    else {
        terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
    }
    r <- terra::rast(rast_tif)
}
debug: if (fs::file_exists(rast_tif)) {
    r_tmp_tif <- tempfile(fileext = ".tif")
    r_tmp <- c(rast(rast_tif), r)
    r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
    terra::writeRaster(r_tmp, r_tmp_tif)
    fs::file_delete(rast_tif)
    fs::file_move(r_tmp_tif, rast_tif)
    rm(r)
    rm(r_tmp)
} else {
    terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
}
debug: terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
debug: r <- terra::rast(rast_tif)
debug: d_r <- mutate(tidyr::pivot_longer(sf::st_drop_geometry(sf::st_as_sf(terra::zonal(x = r, 
    z = terra::vect(dplyr::select(sf_zones, dplyr::all_of(fld_zones))), 
    fun = zonal_fun, exact = T, na.rm = T, as.polygons = T))), 
    cols = -dplyr::any_of(fld_zones), names_to = "lyr", values_to = zonal_fun), 
    time = readr::parse_datetime(str_replace(lyr, glue("{var}\\|(.*)"), 
        "\\1")))
debug: if (!is.null(zonal_csv)) write_csv(d_r, zonal_csv)
debug: write_csv(d_r, zonal_csv)
debug: if (!keep_nc) unlink(dir_nc, recursive = T)
debug: unlink(dir_nc, recursive = T)
debug: return(d_r)
Downloading 1 requests, up to 248 time slices each
Called from: extractr::ed_extract(ed, var = v, sf_zones = ply, bbox = bb, 
    mask_tif = F, rast_tif = glue("{dir_out}/{nms}/{yr}.tif"), 
    zonal_fun = "mean", zonal_csv = glue("{dir_out}/{nms}/{yr}.csv"), 
    dir_nc = glue("{dir_out}/{nms}/{yr}_nc"), keep_nc = F, n_max_vals_per_req = 1e+05, 
    time_min = time_min, time_max = time_max, verbose = T)
debug: while (i_req <= n_reqs) {
    i_t_beg <- (i_req - 1) * n_t_per_req + 1
    i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
    t_req <- times_todo[c(i_t_beg, i_t_end)]
    t_req_str <- format_ISO8601(t_req, usetz = "Z")
    if (verbose) 
        message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
    ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
        ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
        0), nc)
    unlink(ncs0)
    nc_retry <- T
    nc_n_try <- 1
    n_max_retries
    while (nc_retry) {
        res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
            url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
                bbox[["xmax"]]), latitude = c(bbox[["ymin"]], 
                bbox[["ymax"]]), time = t_req_str, fmt = "nc", 
            store = rerddap::disk(path = dir_nc)))
        if (inherits(res, "try-error")) {
            err <- attr(res, "condition")
            msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
            nc_n_try <- nc_n_try + 1
            if (nc_n_try > n_max_retries) {
                stop(msg)
            }
            else {
                message(msg, "\nRETRYing...")
                Sys.sleep(1)
            }
        }
        else {
            nc_retry <- F
        }
    }
    i_req <- i_req + 1
}
debug: i_t_beg <- (i_req - 1) * n_t_per_req + 1
debug: i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
debug: t_req <- times_todo[c(i_t_beg, i_t_end)]
debug: t_req_str <- format_ISO8601(t_req, usetz = "Z")
debug: if (verbose) message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
debug: message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
Fetching request 1 of 1 (2009-01-01 to 2009-12-01) ~ 19:34:46 UTC
debug: ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
    0), nc)
debug: unlink(ncs0)
debug: nc_retry <- T
debug: nc_n_try <- 1
debug: n_max_retries
debug: while (nc_retry) {
    res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
        url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
            bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
        time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
    if (inherits(res, "try-error")) {
        err <- attr(res, "condition")
        msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
        nc_n_try <- nc_n_try + 1
        if (nc_n_try > n_max_retries) {
            stop(msg)
        }
        else {
            message(msg, "\nRETRYing...")
            Sys.sleep(1)
        }
    }
    else {
        nc_retry <- F
    }
}
debug: res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
    url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
        bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
    time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
debug: if (inherits(res, "try-error")) {
    err <- attr(res, "condition")
    msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
    nc_n_try <- nc_n_try + 1
    if (nc_n_try > n_max_retries) {
        stop(msg)
    }
    else {
        message(msg, "\nRETRYing...")
        Sys.sleep(1)
    }
} else {
    nc_retry <- F
}
debug: nc_retry <- F
debug: (while) nc_retry
debug: i_req <- i_req + 1
debug: (while) i_req <= n_reqs
debug: ncs <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size > 
    0), nc)
debug: r <- terra::rast(ncs)
debug: stopifnot(all(class(terra::time(r)) %in% c("POSIXct", "POSIXt")))
debug: idx <- dplyr::pull(dplyr::filter(dplyr::arrange(dplyr::tibble(idx = 1:terra::nlyr(r), 
    time = terra::time(r)), time), !duplicated(time)), idx)
debug: r <- terra::subset(r, idx)
debug: stopifnot(terra::crs(r, proj = T) == wgs84)
debug: if (mask_tif) r <- terra::mask(r, sf_zones)
debug: lyrs <- glue("{var}|{terra::time(r)}")
debug: if (length(dims_other) > 0 && !all(length(dims[dims_other]) == 
    1)) stop(glue("Other dimensions not yet supported: {paste(dims_other, collapse = ',')}"))
debug: names(r) <- lyrs
debug: if (!is.null(rast_tif)) {
    if (fs::file_exists(rast_tif)) {
        r_tmp_tif <- tempfile(fileext = ".tif")
        r_tmp <- c(rast(rast_tif), r)
        r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
        terra::writeRaster(r_tmp, r_tmp_tif)
        fs::file_delete(rast_tif)
        fs::file_move(r_tmp_tif, rast_tif)
        rm(r)
        rm(r_tmp)
    }
    else {
        terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
    }
    r <- terra::rast(rast_tif)
}
debug: if (fs::file_exists(rast_tif)) {
    r_tmp_tif <- tempfile(fileext = ".tif")
    r_tmp <- c(rast(rast_tif), r)
    r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
    terra::writeRaster(r_tmp, r_tmp_tif)
    fs::file_delete(rast_tif)
    fs::file_move(r_tmp_tif, rast_tif)
    rm(r)
    rm(r_tmp)
} else {
    terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
}
debug: terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
debug: r <- terra::rast(rast_tif)
debug: d_r <- mutate(tidyr::pivot_longer(sf::st_drop_geometry(sf::st_as_sf(terra::zonal(x = r, 
    z = terra::vect(dplyr::select(sf_zones, dplyr::all_of(fld_zones))), 
    fun = zonal_fun, exact = T, na.rm = T, as.polygons = T))), 
    cols = -dplyr::any_of(fld_zones), names_to = "lyr", values_to = zonal_fun), 
    time = readr::parse_datetime(str_replace(lyr, glue("{var}\\|(.*)"), 
        "\\1")))
debug: if (!is.null(zonal_csv)) write_csv(d_r, zonal_csv)
debug: write_csv(d_r, zonal_csv)
debug: if (!keep_nc) unlink(dir_nc, recursive = T)
debug: unlink(dir_nc, recursive = T)
debug: return(d_r)
Downloading 1 requests, up to 248 time slices each
Called from: extractr::ed_extract(ed, var = v, sf_zones = ply, bbox = bb, 
    mask_tif = F, rast_tif = glue("{dir_out}/{nms}/{yr}.tif"), 
    zonal_fun = "mean", zonal_csv = glue("{dir_out}/{nms}/{yr}.csv"), 
    dir_nc = glue("{dir_out}/{nms}/{yr}_nc"), keep_nc = F, n_max_vals_per_req = 1e+05, 
    time_min = time_min, time_max = time_max, verbose = T)
debug: while (i_req <= n_reqs) {
    i_t_beg <- (i_req - 1) * n_t_per_req + 1
    i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
    t_req <- times_todo[c(i_t_beg, i_t_end)]
    t_req_str <- format_ISO8601(t_req, usetz = "Z")
    if (verbose) 
        message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
    ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
        ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
        0), nc)
    unlink(ncs0)
    nc_retry <- T
    nc_n_try <- 1
    n_max_retries
    while (nc_retry) {
        res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
            url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
                bbox[["xmax"]]), latitude = c(bbox[["ymin"]], 
                bbox[["ymax"]]), time = t_req_str, fmt = "nc", 
            store = rerddap::disk(path = dir_nc)))
        if (inherits(res, "try-error")) {
            err <- attr(res, "condition")
            msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
            nc_n_try <- nc_n_try + 1
            if (nc_n_try > n_max_retries) {
                stop(msg)
            }
            else {
                message(msg, "\nRETRYing...")
                Sys.sleep(1)
            }
        }
        else {
            nc_retry <- F
        }
    }
    i_req <- i_req + 1
}
debug: i_t_beg <- (i_req - 1) * n_t_per_req + 1
debug: i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
debug: t_req <- times_todo[c(i_t_beg, i_t_end)]
debug: t_req_str <- format_ISO8601(t_req, usetz = "Z")
debug: if (verbose) message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
debug: message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
Fetching request 1 of 1 (2010-01-01 to 2010-12-01) ~ 19:34:48 UTC
debug: ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
    0), nc)
debug: unlink(ncs0)
debug: nc_retry <- T
debug: nc_n_try <- 1
debug: n_max_retries
debug: while (nc_retry) {
    res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
        url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
            bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
        time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
    if (inherits(res, "try-error")) {
        err <- attr(res, "condition")
        msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
        nc_n_try <- nc_n_try + 1
        if (nc_n_try > n_max_retries) {
            stop(msg)
        }
        else {
            message(msg, "\nRETRYing...")
            Sys.sleep(1)
        }
    }
    else {
        nc_retry <- F
    }
}
debug: res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
    url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
        bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
    time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
debug: if (inherits(res, "try-error")) {
    err <- attr(res, "condition")
    msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
    nc_n_try <- nc_n_try + 1
    if (nc_n_try > n_max_retries) {
        stop(msg)
    }
    else {
        message(msg, "\nRETRYing...")
        Sys.sleep(1)
    }
} else {
    nc_retry <- F
}
debug: nc_retry <- F
debug: (while) nc_retry
debug: i_req <- i_req + 1
debug: (while) i_req <= n_reqs
debug: ncs <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size > 
    0), nc)
debug: r <- terra::rast(ncs)
debug: stopifnot(all(class(terra::time(r)) %in% c("POSIXct", "POSIXt")))
debug: idx <- dplyr::pull(dplyr::filter(dplyr::arrange(dplyr::tibble(idx = 1:terra::nlyr(r), 
    time = terra::time(r)), time), !duplicated(time)), idx)
debug: r <- terra::subset(r, idx)
debug: stopifnot(terra::crs(r, proj = T) == wgs84)
debug: if (mask_tif) r <- terra::mask(r, sf_zones)
debug: lyrs <- glue("{var}|{terra::time(r)}")
debug: if (length(dims_other) > 0 && !all(length(dims[dims_other]) == 
    1)) stop(glue("Other dimensions not yet supported: {paste(dims_other, collapse = ',')}"))
debug: names(r) <- lyrs
debug: if (!is.null(rast_tif)) {
    if (fs::file_exists(rast_tif)) {
        r_tmp_tif <- tempfile(fileext = ".tif")
        r_tmp <- c(rast(rast_tif), r)
        r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
        terra::writeRaster(r_tmp, r_tmp_tif)
        fs::file_delete(rast_tif)
        fs::file_move(r_tmp_tif, rast_tif)
        rm(r)
        rm(r_tmp)
    }
    else {
        terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
    }
    r <- terra::rast(rast_tif)
}
debug: if (fs::file_exists(rast_tif)) {
    r_tmp_tif <- tempfile(fileext = ".tif")
    r_tmp <- c(rast(rast_tif), r)
    r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
    terra::writeRaster(r_tmp, r_tmp_tif)
    fs::file_delete(rast_tif)
    fs::file_move(r_tmp_tif, rast_tif)
    rm(r)
    rm(r_tmp)
} else {
    terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
}
debug: terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
debug: r <- terra::rast(rast_tif)
debug: d_r <- mutate(tidyr::pivot_longer(sf::st_drop_geometry(sf::st_as_sf(terra::zonal(x = r, 
    z = terra::vect(dplyr::select(sf_zones, dplyr::all_of(fld_zones))), 
    fun = zonal_fun, exact = T, na.rm = T, as.polygons = T))), 
    cols = -dplyr::any_of(fld_zones), names_to = "lyr", values_to = zonal_fun), 
    time = readr::parse_datetime(str_replace(lyr, glue("{var}\\|(.*)"), 
        "\\1")))
debug: if (!is.null(zonal_csv)) write_csv(d_r, zonal_csv)
debug: write_csv(d_r, zonal_csv)
debug: if (!keep_nc) unlink(dir_nc, recursive = T)
debug: unlink(dir_nc, recursive = T)
debug: return(d_r)
Downloading 1 requests, up to 248 time slices each
Called from: extractr::ed_extract(ed, var = v, sf_zones = ply, bbox = bb, 
    mask_tif = F, rast_tif = glue("{dir_out}/{nms}/{yr}.tif"), 
    zonal_fun = "mean", zonal_csv = glue("{dir_out}/{nms}/{yr}.csv"), 
    dir_nc = glue("{dir_out}/{nms}/{yr}_nc"), keep_nc = F, n_max_vals_per_req = 1e+05, 
    time_min = time_min, time_max = time_max, verbose = T)
debug: while (i_req <= n_reqs) {
    i_t_beg <- (i_req - 1) * n_t_per_req + 1
    i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
    t_req <- times_todo[c(i_t_beg, i_t_end)]
    t_req_str <- format_ISO8601(t_req, usetz = "Z")
    if (verbose) 
        message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
    ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
        ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
        0), nc)
    unlink(ncs0)
    nc_retry <- T
    nc_n_try <- 1
    n_max_retries
    while (nc_retry) {
        res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
            url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
                bbox[["xmax"]]), latitude = c(bbox[["ymin"]], 
                bbox[["ymax"]]), time = t_req_str, fmt = "nc", 
            store = rerddap::disk(path = dir_nc)))
        if (inherits(res, "try-error")) {
            err <- attr(res, "condition")
            msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
            nc_n_try <- nc_n_try + 1
            if (nc_n_try > n_max_retries) {
                stop(msg)
            }
            else {
                message(msg, "\nRETRYing...")
                Sys.sleep(1)
            }
        }
        else {
            nc_retry <- F
        }
    }
    i_req <- i_req + 1
}
debug: i_t_beg <- (i_req - 1) * n_t_per_req + 1
debug: i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
debug: t_req <- times_todo[c(i_t_beg, i_t_end)]
debug: t_req_str <- format_ISO8601(t_req, usetz = "Z")
debug: if (verbose) message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
debug: message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
Fetching request 1 of 1 (2011-01-01 to 2011-12-01) ~ 19:34:49 UTC
debug: ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
    0), nc)
debug: unlink(ncs0)
debug: nc_retry <- T
debug: nc_n_try <- 1
debug: n_max_retries
debug: while (nc_retry) {
    res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
        url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
            bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
        time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
    if (inherits(res, "try-error")) {
        err <- attr(res, "condition")
        msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
        nc_n_try <- nc_n_try + 1
        if (nc_n_try > n_max_retries) {
            stop(msg)
        }
        else {
            message(msg, "\nRETRYing...")
            Sys.sleep(1)
        }
    }
    else {
        nc_retry <- F
    }
}
debug: res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
    url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
        bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
    time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
debug: if (inherits(res, "try-error")) {
    err <- attr(res, "condition")
    msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
    nc_n_try <- nc_n_try + 1
    if (nc_n_try > n_max_retries) {
        stop(msg)
    }
    else {
        message(msg, "\nRETRYing...")
        Sys.sleep(1)
    }
} else {
    nc_retry <- F
}
debug: nc_retry <- F
debug: (while) nc_retry
debug: i_req <- i_req + 1
debug: (while) i_req <= n_reqs
debug: ncs <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size > 
    0), nc)
debug: r <- terra::rast(ncs)
debug: stopifnot(all(class(terra::time(r)) %in% c("POSIXct", "POSIXt")))
debug: idx <- dplyr::pull(dplyr::filter(dplyr::arrange(dplyr::tibble(idx = 1:terra::nlyr(r), 
    time = terra::time(r)), time), !duplicated(time)), idx)
debug: r <- terra::subset(r, idx)
debug: stopifnot(terra::crs(r, proj = T) == wgs84)
debug: if (mask_tif) r <- terra::mask(r, sf_zones)
debug: lyrs <- glue("{var}|{terra::time(r)}")
debug: if (length(dims_other) > 0 && !all(length(dims[dims_other]) == 
    1)) stop(glue("Other dimensions not yet supported: {paste(dims_other, collapse = ',')}"))
debug: names(r) <- lyrs
debug: if (!is.null(rast_tif)) {
    if (fs::file_exists(rast_tif)) {
        r_tmp_tif <- tempfile(fileext = ".tif")
        r_tmp <- c(rast(rast_tif), r)
        r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
        terra::writeRaster(r_tmp, r_tmp_tif)
        fs::file_delete(rast_tif)
        fs::file_move(r_tmp_tif, rast_tif)
        rm(r)
        rm(r_tmp)
    }
    else {
        terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
    }
    r <- terra::rast(rast_tif)
}
debug: if (fs::file_exists(rast_tif)) {
    r_tmp_tif <- tempfile(fileext = ".tif")
    r_tmp <- c(rast(rast_tif), r)
    r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
    terra::writeRaster(r_tmp, r_tmp_tif)
    fs::file_delete(rast_tif)
    fs::file_move(r_tmp_tif, rast_tif)
    rm(r)
    rm(r_tmp)
} else {
    terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
}
debug: terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
debug: r <- terra::rast(rast_tif)
debug: d_r <- mutate(tidyr::pivot_longer(sf::st_drop_geometry(sf::st_as_sf(terra::zonal(x = r, 
    z = terra::vect(dplyr::select(sf_zones, dplyr::all_of(fld_zones))), 
    fun = zonal_fun, exact = T, na.rm = T, as.polygons = T))), 
    cols = -dplyr::any_of(fld_zones), names_to = "lyr", values_to = zonal_fun), 
    time = readr::parse_datetime(str_replace(lyr, glue("{var}\\|(.*)"), 
        "\\1")))
debug: if (!is.null(zonal_csv)) write_csv(d_r, zonal_csv)
debug: write_csv(d_r, zonal_csv)
debug: if (!keep_nc) unlink(dir_nc, recursive = T)
debug: unlink(dir_nc, recursive = T)
debug: return(d_r)
Downloading 1 requests, up to 248 time slices each
Called from: extractr::ed_extract(ed, var = v, sf_zones = ply, bbox = bb, 
    mask_tif = F, rast_tif = glue("{dir_out}/{nms}/{yr}.tif"), 
    zonal_fun = "mean", zonal_csv = glue("{dir_out}/{nms}/{yr}.csv"), 
    dir_nc = glue("{dir_out}/{nms}/{yr}_nc"), keep_nc = F, n_max_vals_per_req = 1e+05, 
    time_min = time_min, time_max = time_max, verbose = T)
debug: while (i_req <= n_reqs) {
    i_t_beg <- (i_req - 1) * n_t_per_req + 1
    i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
    t_req <- times_todo[c(i_t_beg, i_t_end)]
    t_req_str <- format_ISO8601(t_req, usetz = "Z")
    if (verbose) 
        message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
    ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
        ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
        0), nc)
    unlink(ncs0)
    nc_retry <- T
    nc_n_try <- 1
    n_max_retries
    while (nc_retry) {
        res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
            url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
                bbox[["xmax"]]), latitude = c(bbox[["ymin"]], 
                bbox[["ymax"]]), time = t_req_str, fmt = "nc", 
            store = rerddap::disk(path = dir_nc)))
        if (inherits(res, "try-error")) {
            err <- attr(res, "condition")
            msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
            nc_n_try <- nc_n_try + 1
            if (nc_n_try > n_max_retries) {
                stop(msg)
            }
            else {
                message(msg, "\nRETRYing...")
                Sys.sleep(1)
            }
        }
        else {
            nc_retry <- F
        }
    }
    i_req <- i_req + 1
}
debug: i_t_beg <- (i_req - 1) * n_t_per_req + 1
debug: i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
debug: t_req <- times_todo[c(i_t_beg, i_t_end)]
debug: t_req_str <- format_ISO8601(t_req, usetz = "Z")
debug: if (verbose) message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
debug: message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
Fetching request 1 of 1 (2012-01-01 to 2012-12-01) ~ 19:34:51 UTC
debug: ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
    0), nc)
debug: unlink(ncs0)
debug: nc_retry <- T
debug: nc_n_try <- 1
debug: n_max_retries
debug: while (nc_retry) {
    res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
        url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
            bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
        time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
    if (inherits(res, "try-error")) {
        err <- attr(res, "condition")
        msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
        nc_n_try <- nc_n_try + 1
        if (nc_n_try > n_max_retries) {
            stop(msg)
        }
        else {
            message(msg, "\nRETRYing...")
            Sys.sleep(1)
        }
    }
    else {
        nc_retry <- F
    }
}
debug: res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
    url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
        bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
    time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
debug: if (inherits(res, "try-error")) {
    err <- attr(res, "condition")
    msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
    nc_n_try <- nc_n_try + 1
    if (nc_n_try > n_max_retries) {
        stop(msg)
    }
    else {
        message(msg, "\nRETRYing...")
        Sys.sleep(1)
    }
} else {
    nc_retry <- F
}
debug: nc_retry <- F
debug: (while) nc_retry
debug: i_req <- i_req + 1
debug: (while) i_req <= n_reqs
debug: ncs <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size > 
    0), nc)
debug: r <- terra::rast(ncs)
debug: stopifnot(all(class(terra::time(r)) %in% c("POSIXct", "POSIXt")))
debug: idx <- dplyr::pull(dplyr::filter(dplyr::arrange(dplyr::tibble(idx = 1:terra::nlyr(r), 
    time = terra::time(r)), time), !duplicated(time)), idx)
debug: r <- terra::subset(r, idx)
debug: stopifnot(terra::crs(r, proj = T) == wgs84)
debug: if (mask_tif) r <- terra::mask(r, sf_zones)
debug: lyrs <- glue("{var}|{terra::time(r)}")
debug: if (length(dims_other) > 0 && !all(length(dims[dims_other]) == 
    1)) stop(glue("Other dimensions not yet supported: {paste(dims_other, collapse = ',')}"))
debug: names(r) <- lyrs
debug: if (!is.null(rast_tif)) {
    if (fs::file_exists(rast_tif)) {
        r_tmp_tif <- tempfile(fileext = ".tif")
        r_tmp <- c(rast(rast_tif), r)
        r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
        terra::writeRaster(r_tmp, r_tmp_tif)
        fs::file_delete(rast_tif)
        fs::file_move(r_tmp_tif, rast_tif)
        rm(r)
        rm(r_tmp)
    }
    else {
        terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
    }
    r <- terra::rast(rast_tif)
}
debug: if (fs::file_exists(rast_tif)) {
    r_tmp_tif <- tempfile(fileext = ".tif")
    r_tmp <- c(rast(rast_tif), r)
    r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
    terra::writeRaster(r_tmp, r_tmp_tif)
    fs::file_delete(rast_tif)
    fs::file_move(r_tmp_tif, rast_tif)
    rm(r)
    rm(r_tmp)
} else {
    terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
}
debug: terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
debug: r <- terra::rast(rast_tif)
debug: d_r <- mutate(tidyr::pivot_longer(sf::st_drop_geometry(sf::st_as_sf(terra::zonal(x = r, 
    z = terra::vect(dplyr::select(sf_zones, dplyr::all_of(fld_zones))), 
    fun = zonal_fun, exact = T, na.rm = T, as.polygons = T))), 
    cols = -dplyr::any_of(fld_zones), names_to = "lyr", values_to = zonal_fun), 
    time = readr::parse_datetime(str_replace(lyr, glue("{var}\\|(.*)"), 
        "\\1")))
debug: if (!is.null(zonal_csv)) write_csv(d_r, zonal_csv)
debug: write_csv(d_r, zonal_csv)
debug: if (!keep_nc) unlink(dir_nc, recursive = T)
debug: unlink(dir_nc, recursive = T)
debug: return(d_r)
Downloading 1 requests, up to 248 time slices each
Called from: extractr::ed_extract(ed, var = v, sf_zones = ply, bbox = bb, 
    mask_tif = F, rast_tif = glue("{dir_out}/{nms}/{yr}.tif"), 
    zonal_fun = "mean", zonal_csv = glue("{dir_out}/{nms}/{yr}.csv"), 
    dir_nc = glue("{dir_out}/{nms}/{yr}_nc"), keep_nc = F, n_max_vals_per_req = 1e+05, 
    time_min = time_min, time_max = time_max, verbose = T)
debug: while (i_req <= n_reqs) {
    i_t_beg <- (i_req - 1) * n_t_per_req + 1
    i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
    t_req <- times_todo[c(i_t_beg, i_t_end)]
    t_req_str <- format_ISO8601(t_req, usetz = "Z")
    if (verbose) 
        message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
    ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
        ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
        0), nc)
    unlink(ncs0)
    nc_retry <- T
    nc_n_try <- 1
    n_max_retries
    while (nc_retry) {
        res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
            url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
                bbox[["xmax"]]), latitude = c(bbox[["ymin"]], 
                bbox[["ymax"]]), time = t_req_str, fmt = "nc", 
            store = rerddap::disk(path = dir_nc)))
        if (inherits(res, "try-error")) {
            err <- attr(res, "condition")
            msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
            nc_n_try <- nc_n_try + 1
            if (nc_n_try > n_max_retries) {
                stop(msg)
            }
            else {
                message(msg, "\nRETRYing...")
                Sys.sleep(1)
            }
        }
        else {
            nc_retry <- F
        }
    }
    i_req <- i_req + 1
}
debug: i_t_beg <- (i_req - 1) * n_t_per_req + 1
debug: i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
debug: t_req <- times_todo[c(i_t_beg, i_t_end)]
debug: t_req_str <- format_ISO8601(t_req, usetz = "Z")
debug: if (verbose) message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
debug: message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
Fetching request 1 of 1 (2013-01-01 to 2013-12-01) ~ 19:34:53 UTC
debug: ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
    0), nc)
debug: unlink(ncs0)
debug: nc_retry <- T
debug: nc_n_try <- 1
debug: n_max_retries
debug: while (nc_retry) {
    res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
        url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
            bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
        time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
    if (inherits(res, "try-error")) {
        err <- attr(res, "condition")
        msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
        nc_n_try <- nc_n_try + 1
        if (nc_n_try > n_max_retries) {
            stop(msg)
        }
        else {
            message(msg, "\nRETRYing...")
            Sys.sleep(1)
        }
    }
    else {
        nc_retry <- F
    }
}
debug: res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
    url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
        bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
    time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
debug: if (inherits(res, "try-error")) {
    err <- attr(res, "condition")
    msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
    nc_n_try <- nc_n_try + 1
    if (nc_n_try > n_max_retries) {
        stop(msg)
    }
    else {
        message(msg, "\nRETRYing...")
        Sys.sleep(1)
    }
} else {
    nc_retry <- F
}
debug: nc_retry <- F
debug: (while) nc_retry
debug: i_req <- i_req + 1
debug: (while) i_req <= n_reqs
debug: ncs <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size > 
    0), nc)
debug: r <- terra::rast(ncs)
debug: stopifnot(all(class(terra::time(r)) %in% c("POSIXct", "POSIXt")))
debug: idx <- dplyr::pull(dplyr::filter(dplyr::arrange(dplyr::tibble(idx = 1:terra::nlyr(r), 
    time = terra::time(r)), time), !duplicated(time)), idx)
debug: r <- terra::subset(r, idx)
debug: stopifnot(terra::crs(r, proj = T) == wgs84)
debug: if (mask_tif) r <- terra::mask(r, sf_zones)
debug: lyrs <- glue("{var}|{terra::time(r)}")
debug: if (length(dims_other) > 0 && !all(length(dims[dims_other]) == 
    1)) stop(glue("Other dimensions not yet supported: {paste(dims_other, collapse = ',')}"))
debug: names(r) <- lyrs
debug: if (!is.null(rast_tif)) {
    if (fs::file_exists(rast_tif)) {
        r_tmp_tif <- tempfile(fileext = ".tif")
        r_tmp <- c(rast(rast_tif), r)
        r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
        terra::writeRaster(r_tmp, r_tmp_tif)
        fs::file_delete(rast_tif)
        fs::file_move(r_tmp_tif, rast_tif)
        rm(r)
        rm(r_tmp)
    }
    else {
        terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
    }
    r <- terra::rast(rast_tif)
}
debug: if (fs::file_exists(rast_tif)) {
    r_tmp_tif <- tempfile(fileext = ".tif")
    r_tmp <- c(rast(rast_tif), r)
    r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
    terra::writeRaster(r_tmp, r_tmp_tif)
    fs::file_delete(rast_tif)
    fs::file_move(r_tmp_tif, rast_tif)
    rm(r)
    rm(r_tmp)
} else {
    terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
}
debug: terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
debug: r <- terra::rast(rast_tif)
debug: d_r <- mutate(tidyr::pivot_longer(sf::st_drop_geometry(sf::st_as_sf(terra::zonal(x = r, 
    z = terra::vect(dplyr::select(sf_zones, dplyr::all_of(fld_zones))), 
    fun = zonal_fun, exact = T, na.rm = T, as.polygons = T))), 
    cols = -dplyr::any_of(fld_zones), names_to = "lyr", values_to = zonal_fun), 
    time = readr::parse_datetime(str_replace(lyr, glue("{var}\\|(.*)"), 
        "\\1")))
debug: if (!is.null(zonal_csv)) write_csv(d_r, zonal_csv)
debug: write_csv(d_r, zonal_csv)
debug: if (!keep_nc) unlink(dir_nc, recursive = T)
debug: unlink(dir_nc, recursive = T)
debug: return(d_r)
Downloading 1 requests, up to 248 time slices each
Called from: extractr::ed_extract(ed, var = v, sf_zones = ply, bbox = bb, 
    mask_tif = F, rast_tif = glue("{dir_out}/{nms}/{yr}.tif"), 
    zonal_fun = "mean", zonal_csv = glue("{dir_out}/{nms}/{yr}.csv"), 
    dir_nc = glue("{dir_out}/{nms}/{yr}_nc"), keep_nc = F, n_max_vals_per_req = 1e+05, 
    time_min = time_min, time_max = time_max, verbose = T)
debug: while (i_req <= n_reqs) {
    i_t_beg <- (i_req - 1) * n_t_per_req + 1
    i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
    t_req <- times_todo[c(i_t_beg, i_t_end)]
    t_req_str <- format_ISO8601(t_req, usetz = "Z")
    if (verbose) 
        message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
    ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
        ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
        0), nc)
    unlink(ncs0)
    nc_retry <- T
    nc_n_try <- 1
    n_max_retries
    while (nc_retry) {
        res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
            url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
                bbox[["xmax"]]), latitude = c(bbox[["ymin"]], 
                bbox[["ymax"]]), time = t_req_str, fmt = "nc", 
            store = rerddap::disk(path = dir_nc)))
        if (inherits(res, "try-error")) {
            err <- attr(res, "condition")
            msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
            nc_n_try <- nc_n_try + 1
            if (nc_n_try > n_max_retries) {
                stop(msg)
            }
            else {
                message(msg, "\nRETRYing...")
                Sys.sleep(1)
            }
        }
        else {
            nc_retry <- F
        }
    }
    i_req <- i_req + 1
}
debug: i_t_beg <- (i_req - 1) * n_t_per_req + 1
debug: i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
debug: t_req <- times_todo[c(i_t_beg, i_t_end)]
debug: t_req_str <- format_ISO8601(t_req, usetz = "Z")
debug: if (verbose) message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
debug: message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
Fetching request 1 of 1 (2014-01-01 to 2014-12-01) ~ 19:34:55 UTC
debug: ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
    0), nc)
debug: unlink(ncs0)
debug: nc_retry <- T
debug: nc_n_try <- 1
debug: n_max_retries
debug: while (nc_retry) {
    res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
        url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
            bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
        time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
    if (inherits(res, "try-error")) {
        err <- attr(res, "condition")
        msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
        nc_n_try <- nc_n_try + 1
        if (nc_n_try > n_max_retries) {
            stop(msg)
        }
        else {
            message(msg, "\nRETRYing...")
            Sys.sleep(1)
        }
    }
    else {
        nc_retry <- F
    }
}
debug: res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
    url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
        bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
    time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
debug: if (inherits(res, "try-error")) {
    err <- attr(res, "condition")
    msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
    nc_n_try <- nc_n_try + 1
    if (nc_n_try > n_max_retries) {
        stop(msg)
    }
    else {
        message(msg, "\nRETRYing...")
        Sys.sleep(1)
    }
} else {
    nc_retry <- F
}
debug: nc_retry <- F
debug: (while) nc_retry
debug: i_req <- i_req + 1
debug: (while) i_req <= n_reqs
debug: ncs <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size > 
    0), nc)
debug: r <- terra::rast(ncs)
debug: stopifnot(all(class(terra::time(r)) %in% c("POSIXct", "POSIXt")))
debug: idx <- dplyr::pull(dplyr::filter(dplyr::arrange(dplyr::tibble(idx = 1:terra::nlyr(r), 
    time = terra::time(r)), time), !duplicated(time)), idx)
debug: r <- terra::subset(r, idx)
debug: stopifnot(terra::crs(r, proj = T) == wgs84)
debug: if (mask_tif) r <- terra::mask(r, sf_zones)
debug: lyrs <- glue("{var}|{terra::time(r)}")
debug: if (length(dims_other) > 0 && !all(length(dims[dims_other]) == 
    1)) stop(glue("Other dimensions not yet supported: {paste(dims_other, collapse = ',')}"))
debug: names(r) <- lyrs
debug: if (!is.null(rast_tif)) {
    if (fs::file_exists(rast_tif)) {
        r_tmp_tif <- tempfile(fileext = ".tif")
        r_tmp <- c(rast(rast_tif), r)
        r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
        terra::writeRaster(r_tmp, r_tmp_tif)
        fs::file_delete(rast_tif)
        fs::file_move(r_tmp_tif, rast_tif)
        rm(r)
        rm(r_tmp)
    }
    else {
        terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
    }
    r <- terra::rast(rast_tif)
}
debug: if (fs::file_exists(rast_tif)) {
    r_tmp_tif <- tempfile(fileext = ".tif")
    r_tmp <- c(rast(rast_tif), r)
    r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
    terra::writeRaster(r_tmp, r_tmp_tif)
    fs::file_delete(rast_tif)
    fs::file_move(r_tmp_tif, rast_tif)
    rm(r)
    rm(r_tmp)
} else {
    terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
}
debug: terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
debug: r <- terra::rast(rast_tif)
debug: d_r <- mutate(tidyr::pivot_longer(sf::st_drop_geometry(sf::st_as_sf(terra::zonal(x = r, 
    z = terra::vect(dplyr::select(sf_zones, dplyr::all_of(fld_zones))), 
    fun = zonal_fun, exact = T, na.rm = T, as.polygons = T))), 
    cols = -dplyr::any_of(fld_zones), names_to = "lyr", values_to = zonal_fun), 
    time = readr::parse_datetime(str_replace(lyr, glue("{var}\\|(.*)"), 
        "\\1")))
debug: if (!is.null(zonal_csv)) write_csv(d_r, zonal_csv)
debug: write_csv(d_r, zonal_csv)
debug: if (!keep_nc) unlink(dir_nc, recursive = T)
debug: unlink(dir_nc, recursive = T)
debug: return(d_r)
Downloading 1 requests, up to 248 time slices each
Called from: extractr::ed_extract(ed, var = v, sf_zones = ply, bbox = bb, 
    mask_tif = F, rast_tif = glue("{dir_out}/{nms}/{yr}.tif"), 
    zonal_fun = "mean", zonal_csv = glue("{dir_out}/{nms}/{yr}.csv"), 
    dir_nc = glue("{dir_out}/{nms}/{yr}_nc"), keep_nc = F, n_max_vals_per_req = 1e+05, 
    time_min = time_min, time_max = time_max, verbose = T)
debug: while (i_req <= n_reqs) {
    i_t_beg <- (i_req - 1) * n_t_per_req + 1
    i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
    t_req <- times_todo[c(i_t_beg, i_t_end)]
    t_req_str <- format_ISO8601(t_req, usetz = "Z")
    if (verbose) 
        message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
    ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
        ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
        0), nc)
    unlink(ncs0)
    nc_retry <- T
    nc_n_try <- 1
    n_max_retries
    while (nc_retry) {
        res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
            url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
                bbox[["xmax"]]), latitude = c(bbox[["ymin"]], 
                bbox[["ymax"]]), time = t_req_str, fmt = "nc", 
            store = rerddap::disk(path = dir_nc)))
        if (inherits(res, "try-error")) {
            err <- attr(res, "condition")
            msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
            nc_n_try <- nc_n_try + 1
            if (nc_n_try > n_max_retries) {
                stop(msg)
            }
            else {
                message(msg, "\nRETRYing...")
                Sys.sleep(1)
            }
        }
        else {
            nc_retry <- F
        }
    }
    i_req <- i_req + 1
}
debug: i_t_beg <- (i_req - 1) * n_t_per_req + 1
debug: i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
debug: t_req <- times_todo[c(i_t_beg, i_t_end)]
debug: t_req_str <- format_ISO8601(t_req, usetz = "Z")
debug: if (verbose) message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
debug: message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
Fetching request 1 of 1 (2015-01-01 to 2015-12-01) ~ 19:34:57 UTC
debug: ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
    0), nc)
debug: unlink(ncs0)
debug: nc_retry <- T
debug: nc_n_try <- 1
debug: n_max_retries
debug: while (nc_retry) {
    res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
        url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
            bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
        time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
    if (inherits(res, "try-error")) {
        err <- attr(res, "condition")
        msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
        nc_n_try <- nc_n_try + 1
        if (nc_n_try > n_max_retries) {
            stop(msg)
        }
        else {
            message(msg, "\nRETRYing...")
            Sys.sleep(1)
        }
    }
    else {
        nc_retry <- F
    }
}
debug: res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
    url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
        bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
    time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
debug: if (inherits(res, "try-error")) {
    err <- attr(res, "condition")
    msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
    nc_n_try <- nc_n_try + 1
    if (nc_n_try > n_max_retries) {
        stop(msg)
    }
    else {
        message(msg, "\nRETRYing...")
        Sys.sleep(1)
    }
} else {
    nc_retry <- F
}
debug: nc_retry <- F
debug: (while) nc_retry
debug: i_req <- i_req + 1
debug: (while) i_req <= n_reqs
debug: ncs <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size > 
    0), nc)
debug: r <- terra::rast(ncs)
debug: stopifnot(all(class(terra::time(r)) %in% c("POSIXct", "POSIXt")))
debug: idx <- dplyr::pull(dplyr::filter(dplyr::arrange(dplyr::tibble(idx = 1:terra::nlyr(r), 
    time = terra::time(r)), time), !duplicated(time)), idx)
debug: r <- terra::subset(r, idx)
debug: stopifnot(terra::crs(r, proj = T) == wgs84)
debug: if (mask_tif) r <- terra::mask(r, sf_zones)
debug: lyrs <- glue("{var}|{terra::time(r)}")
debug: if (length(dims_other) > 0 && !all(length(dims[dims_other]) == 
    1)) stop(glue("Other dimensions not yet supported: {paste(dims_other, collapse = ',')}"))
debug: names(r) <- lyrs
debug: if (!is.null(rast_tif)) {
    if (fs::file_exists(rast_tif)) {
        r_tmp_tif <- tempfile(fileext = ".tif")
        r_tmp <- c(rast(rast_tif), r)
        r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
        terra::writeRaster(r_tmp, r_tmp_tif)
        fs::file_delete(rast_tif)
        fs::file_move(r_tmp_tif, rast_tif)
        rm(r)
        rm(r_tmp)
    }
    else {
        terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
    }
    r <- terra::rast(rast_tif)
}
debug: if (fs::file_exists(rast_tif)) {
    r_tmp_tif <- tempfile(fileext = ".tif")
    r_tmp <- c(rast(rast_tif), r)
    r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
    terra::writeRaster(r_tmp, r_tmp_tif)
    fs::file_delete(rast_tif)
    fs::file_move(r_tmp_tif, rast_tif)
    rm(r)
    rm(r_tmp)
} else {
    terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
}
debug: terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
debug: r <- terra::rast(rast_tif)
debug: d_r <- mutate(tidyr::pivot_longer(sf::st_drop_geometry(sf::st_as_sf(terra::zonal(x = r, 
    z = terra::vect(dplyr::select(sf_zones, dplyr::all_of(fld_zones))), 
    fun = zonal_fun, exact = T, na.rm = T, as.polygons = T))), 
    cols = -dplyr::any_of(fld_zones), names_to = "lyr", values_to = zonal_fun), 
    time = readr::parse_datetime(str_replace(lyr, glue("{var}\\|(.*)"), 
        "\\1")))
debug: if (!is.null(zonal_csv)) write_csv(d_r, zonal_csv)
debug: write_csv(d_r, zonal_csv)
debug: if (!keep_nc) unlink(dir_nc, recursive = T)
debug: unlink(dir_nc, recursive = T)
debug: return(d_r)
Downloading 1 requests, up to 248 time slices each
Called from: extractr::ed_extract(ed, var = v, sf_zones = ply, bbox = bb, 
    mask_tif = F, rast_tif = glue("{dir_out}/{nms}/{yr}.tif"), 
    zonal_fun = "mean", zonal_csv = glue("{dir_out}/{nms}/{yr}.csv"), 
    dir_nc = glue("{dir_out}/{nms}/{yr}_nc"), keep_nc = F, n_max_vals_per_req = 1e+05, 
    time_min = time_min, time_max = time_max, verbose = T)
debug: while (i_req <= n_reqs) {
    i_t_beg <- (i_req - 1) * n_t_per_req + 1
    i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
    t_req <- times_todo[c(i_t_beg, i_t_end)]
    t_req_str <- format_ISO8601(t_req, usetz = "Z")
    if (verbose) 
        message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
    ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
        ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
        0), nc)
    unlink(ncs0)
    nc_retry <- T
    nc_n_try <- 1
    n_max_retries
    while (nc_retry) {
        res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
            url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
                bbox[["xmax"]]), latitude = c(bbox[["ymin"]], 
                bbox[["ymax"]]), time = t_req_str, fmt = "nc", 
            store = rerddap::disk(path = dir_nc)))
        if (inherits(res, "try-error")) {
            err <- attr(res, "condition")
            msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
            nc_n_try <- nc_n_try + 1
            if (nc_n_try > n_max_retries) {
                stop(msg)
            }
            else {
                message(msg, "\nRETRYing...")
                Sys.sleep(1)
            }
        }
        else {
            nc_retry <- F
        }
    }
    i_req <- i_req + 1
}
debug: i_t_beg <- (i_req - 1) * n_t_per_req + 1
debug: i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
debug: t_req <- times_todo[c(i_t_beg, i_t_end)]
debug: t_req_str <- format_ISO8601(t_req, usetz = "Z")
debug: if (verbose) message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
debug: message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
Fetching request 1 of 1 (2016-01-01 to 2016-12-01) ~ 19:34:58 UTC
debug: ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
    0), nc)
debug: unlink(ncs0)
debug: nc_retry <- T
debug: nc_n_try <- 1
debug: n_max_retries
debug: while (nc_retry) {
    res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
        url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
            bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
        time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
    if (inherits(res, "try-error")) {
        err <- attr(res, "condition")
        msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
        nc_n_try <- nc_n_try + 1
        if (nc_n_try > n_max_retries) {
            stop(msg)
        }
        else {
            message(msg, "\nRETRYing...")
            Sys.sleep(1)
        }
    }
    else {
        nc_retry <- F
    }
}
debug: res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
    url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
        bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
    time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
debug: if (inherits(res, "try-error")) {
    err <- attr(res, "condition")
    msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
    nc_n_try <- nc_n_try + 1
    if (nc_n_try > n_max_retries) {
        stop(msg)
    }
    else {
        message(msg, "\nRETRYing...")
        Sys.sleep(1)
    }
} else {
    nc_retry <- F
}
debug: nc_retry <- F
debug: (while) nc_retry
debug: i_req <- i_req + 1
debug: (while) i_req <= n_reqs
debug: ncs <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size > 
    0), nc)
debug: r <- terra::rast(ncs)
debug: stopifnot(all(class(terra::time(r)) %in% c("POSIXct", "POSIXt")))
debug: idx <- dplyr::pull(dplyr::filter(dplyr::arrange(dplyr::tibble(idx = 1:terra::nlyr(r), 
    time = terra::time(r)), time), !duplicated(time)), idx)
debug: r <- terra::subset(r, idx)
debug: stopifnot(terra::crs(r, proj = T) == wgs84)
debug: if (mask_tif) r <- terra::mask(r, sf_zones)
debug: lyrs <- glue("{var}|{terra::time(r)}")
debug: if (length(dims_other) > 0 && !all(length(dims[dims_other]) == 
    1)) stop(glue("Other dimensions not yet supported: {paste(dims_other, collapse = ',')}"))
debug: names(r) <- lyrs
debug: if (!is.null(rast_tif)) {
    if (fs::file_exists(rast_tif)) {
        r_tmp_tif <- tempfile(fileext = ".tif")
        r_tmp <- c(rast(rast_tif), r)
        r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
        terra::writeRaster(r_tmp, r_tmp_tif)
        fs::file_delete(rast_tif)
        fs::file_move(r_tmp_tif, rast_tif)
        rm(r)
        rm(r_tmp)
    }
    else {
        terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
    }
    r <- terra::rast(rast_tif)
}
debug: if (fs::file_exists(rast_tif)) {
    r_tmp_tif <- tempfile(fileext = ".tif")
    r_tmp <- c(rast(rast_tif), r)
    r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
    terra::writeRaster(r_tmp, r_tmp_tif)
    fs::file_delete(rast_tif)
    fs::file_move(r_tmp_tif, rast_tif)
    rm(r)
    rm(r_tmp)
} else {
    terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
}
debug: terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
debug: r <- terra::rast(rast_tif)
debug: d_r <- mutate(tidyr::pivot_longer(sf::st_drop_geometry(sf::st_as_sf(terra::zonal(x = r, 
    z = terra::vect(dplyr::select(sf_zones, dplyr::all_of(fld_zones))), 
    fun = zonal_fun, exact = T, na.rm = T, as.polygons = T))), 
    cols = -dplyr::any_of(fld_zones), names_to = "lyr", values_to = zonal_fun), 
    time = readr::parse_datetime(str_replace(lyr, glue("{var}\\|(.*)"), 
        "\\1")))
debug: if (!is.null(zonal_csv)) write_csv(d_r, zonal_csv)
debug: write_csv(d_r, zonal_csv)
debug: if (!keep_nc) unlink(dir_nc, recursive = T)
debug: unlink(dir_nc, recursive = T)
debug: return(d_r)
Downloading 1 requests, up to 248 time slices each
Called from: extractr::ed_extract(ed, var = v, sf_zones = ply, bbox = bb, 
    mask_tif = F, rast_tif = glue("{dir_out}/{nms}/{yr}.tif"), 
    zonal_fun = "mean", zonal_csv = glue("{dir_out}/{nms}/{yr}.csv"), 
    dir_nc = glue("{dir_out}/{nms}/{yr}_nc"), keep_nc = F, n_max_vals_per_req = 1e+05, 
    time_min = time_min, time_max = time_max, verbose = T)
debug: while (i_req <= n_reqs) {
    i_t_beg <- (i_req - 1) * n_t_per_req + 1
    i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
    t_req <- times_todo[c(i_t_beg, i_t_end)]
    t_req_str <- format_ISO8601(t_req, usetz = "Z")
    if (verbose) 
        message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
    ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
        ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
        0), nc)
    unlink(ncs0)
    nc_retry <- T
    nc_n_try <- 1
    n_max_retries
    while (nc_retry) {
        res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
            url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
                bbox[["xmax"]]), latitude = c(bbox[["ymin"]], 
                bbox[["ymax"]]), time = t_req_str, fmt = "nc", 
            store = rerddap::disk(path = dir_nc)))
        if (inherits(res, "try-error")) {
            err <- attr(res, "condition")
            msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
            nc_n_try <- nc_n_try + 1
            if (nc_n_try > n_max_retries) {
                stop(msg)
            }
            else {
                message(msg, "\nRETRYing...")
                Sys.sleep(1)
            }
        }
        else {
            nc_retry <- F
        }
    }
    i_req <- i_req + 1
}
debug: i_t_beg <- (i_req - 1) * n_t_per_req + 1
debug: i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
debug: t_req <- times_todo[c(i_t_beg, i_t_end)]
debug: t_req_str <- format_ISO8601(t_req, usetz = "Z")
debug: if (verbose) message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
debug: message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
Fetching request 1 of 1 (2017-01-01 to 2017-12-01) ~ 19:35:00 UTC
debug: ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
    0), nc)
debug: unlink(ncs0)
debug: nc_retry <- T
debug: nc_n_try <- 1
debug: n_max_retries
debug: while (nc_retry) {
    res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
        url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
            bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
        time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
    if (inherits(res, "try-error")) {
        err <- attr(res, "condition")
        msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
        nc_n_try <- nc_n_try + 1
        if (nc_n_try > n_max_retries) {
            stop(msg)
        }
        else {
            message(msg, "\nRETRYing...")
            Sys.sleep(1)
        }
    }
    else {
        nc_retry <- F
    }
}
debug: res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
    url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
        bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
    time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
debug: if (inherits(res, "try-error")) {
    err <- attr(res, "condition")
    msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
    nc_n_try <- nc_n_try + 1
    if (nc_n_try > n_max_retries) {
        stop(msg)
    }
    else {
        message(msg, "\nRETRYing...")
        Sys.sleep(1)
    }
} else {
    nc_retry <- F
}
debug: nc_retry <- F
debug: (while) nc_retry
debug: i_req <- i_req + 1
debug: (while) i_req <= n_reqs
debug: ncs <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size > 
    0), nc)
debug: r <- terra::rast(ncs)
debug: stopifnot(all(class(terra::time(r)) %in% c("POSIXct", "POSIXt")))
debug: idx <- dplyr::pull(dplyr::filter(dplyr::arrange(dplyr::tibble(idx = 1:terra::nlyr(r), 
    time = terra::time(r)), time), !duplicated(time)), idx)
debug: r <- terra::subset(r, idx)
debug: stopifnot(terra::crs(r, proj = T) == wgs84)
debug: if (mask_tif) r <- terra::mask(r, sf_zones)
debug: lyrs <- glue("{var}|{terra::time(r)}")
debug: if (length(dims_other) > 0 && !all(length(dims[dims_other]) == 
    1)) stop(glue("Other dimensions not yet supported: {paste(dims_other, collapse = ',')}"))
debug: names(r) <- lyrs
debug: if (!is.null(rast_tif)) {
    if (fs::file_exists(rast_tif)) {
        r_tmp_tif <- tempfile(fileext = ".tif")
        r_tmp <- c(rast(rast_tif), r)
        r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
        terra::writeRaster(r_tmp, r_tmp_tif)
        fs::file_delete(rast_tif)
        fs::file_move(r_tmp_tif, rast_tif)
        rm(r)
        rm(r_tmp)
    }
    else {
        terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
    }
    r <- terra::rast(rast_tif)
}
debug: if (fs::file_exists(rast_tif)) {
    r_tmp_tif <- tempfile(fileext = ".tif")
    r_tmp <- c(rast(rast_tif), r)
    r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
    terra::writeRaster(r_tmp, r_tmp_tif)
    fs::file_delete(rast_tif)
    fs::file_move(r_tmp_tif, rast_tif)
    rm(r)
    rm(r_tmp)
} else {
    terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
}
debug: terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
debug: r <- terra::rast(rast_tif)
debug: d_r <- mutate(tidyr::pivot_longer(sf::st_drop_geometry(sf::st_as_sf(terra::zonal(x = r, 
    z = terra::vect(dplyr::select(sf_zones, dplyr::all_of(fld_zones))), 
    fun = zonal_fun, exact = T, na.rm = T, as.polygons = T))), 
    cols = -dplyr::any_of(fld_zones), names_to = "lyr", values_to = zonal_fun), 
    time = readr::parse_datetime(str_replace(lyr, glue("{var}\\|(.*)"), 
        "\\1")))
debug: if (!is.null(zonal_csv)) write_csv(d_r, zonal_csv)
debug: write_csv(d_r, zonal_csv)
debug: if (!keep_nc) unlink(dir_nc, recursive = T)
debug: unlink(dir_nc, recursive = T)
debug: return(d_r)
Downloading 1 requests, up to 248 time slices each
Called from: extractr::ed_extract(ed, var = v, sf_zones = ply, bbox = bb, 
    mask_tif = F, rast_tif = glue("{dir_out}/{nms}/{yr}.tif"), 
    zonal_fun = "mean", zonal_csv = glue("{dir_out}/{nms}/{yr}.csv"), 
    dir_nc = glue("{dir_out}/{nms}/{yr}_nc"), keep_nc = F, n_max_vals_per_req = 1e+05, 
    time_min = time_min, time_max = time_max, verbose = T)
debug: while (i_req <= n_reqs) {
    i_t_beg <- (i_req - 1) * n_t_per_req + 1
    i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
    t_req <- times_todo[c(i_t_beg, i_t_end)]
    t_req_str <- format_ISO8601(t_req, usetz = "Z")
    if (verbose) 
        message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
    ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
        ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
        0), nc)
    unlink(ncs0)
    nc_retry <- T
    nc_n_try <- 1
    n_max_retries
    while (nc_retry) {
        res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
            url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
                bbox[["xmax"]]), latitude = c(bbox[["ymin"]], 
                bbox[["ymax"]]), time = t_req_str, fmt = "nc", 
            store = rerddap::disk(path = dir_nc)))
        if (inherits(res, "try-error")) {
            err <- attr(res, "condition")
            msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
            nc_n_try <- nc_n_try + 1
            if (nc_n_try > n_max_retries) {
                stop(msg)
            }
            else {
                message(msg, "\nRETRYing...")
                Sys.sleep(1)
            }
        }
        else {
            nc_retry <- F
        }
    }
    i_req <- i_req + 1
}
debug: i_t_beg <- (i_req - 1) * n_t_per_req + 1
debug: i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
debug: t_req <- times_todo[c(i_t_beg, i_t_end)]
debug: t_req_str <- format_ISO8601(t_req, usetz = "Z")
debug: if (verbose) message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
debug: message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
Fetching request 1 of 1 (2018-01-01 to 2018-12-01) ~ 19:35:03 UTC
debug: ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
    0), nc)
debug: unlink(ncs0)
debug: nc_retry <- T
debug: nc_n_try <- 1
debug: n_max_retries
debug: while (nc_retry) {
    res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
        url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
            bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
        time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
    if (inherits(res, "try-error")) {
        err <- attr(res, "condition")
        msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
        nc_n_try <- nc_n_try + 1
        if (nc_n_try > n_max_retries) {
            stop(msg)
        }
        else {
            message(msg, "\nRETRYing...")
            Sys.sleep(1)
        }
    }
    else {
        nc_retry <- F
    }
}
debug: res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
    url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
        bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
    time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
debug: if (inherits(res, "try-error")) {
    err <- attr(res, "condition")
    msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
    nc_n_try <- nc_n_try + 1
    if (nc_n_try > n_max_retries) {
        stop(msg)
    }
    else {
        message(msg, "\nRETRYing...")
        Sys.sleep(1)
    }
} else {
    nc_retry <- F
}
debug: nc_retry <- F
debug: (while) nc_retry
debug: i_req <- i_req + 1
debug: (while) i_req <= n_reqs
debug: ncs <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size > 
    0), nc)
debug: r <- terra::rast(ncs)
debug: stopifnot(all(class(terra::time(r)) %in% c("POSIXct", "POSIXt")))
debug: idx <- dplyr::pull(dplyr::filter(dplyr::arrange(dplyr::tibble(idx = 1:terra::nlyr(r), 
    time = terra::time(r)), time), !duplicated(time)), idx)
debug: r <- terra::subset(r, idx)
debug: stopifnot(terra::crs(r, proj = T) == wgs84)
debug: if (mask_tif) r <- terra::mask(r, sf_zones)
debug: lyrs <- glue("{var}|{terra::time(r)}")
debug: if (length(dims_other) > 0 && !all(length(dims[dims_other]) == 
    1)) stop(glue("Other dimensions not yet supported: {paste(dims_other, collapse = ',')}"))
debug: names(r) <- lyrs
debug: if (!is.null(rast_tif)) {
    if (fs::file_exists(rast_tif)) {
        r_tmp_tif <- tempfile(fileext = ".tif")
        r_tmp <- c(rast(rast_tif), r)
        r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
        terra::writeRaster(r_tmp, r_tmp_tif)
        fs::file_delete(rast_tif)
        fs::file_move(r_tmp_tif, rast_tif)
        rm(r)
        rm(r_tmp)
    }
    else {
        terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
    }
    r <- terra::rast(rast_tif)
}
debug: if (fs::file_exists(rast_tif)) {
    r_tmp_tif <- tempfile(fileext = ".tif")
    r_tmp <- c(rast(rast_tif), r)
    r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
    terra::writeRaster(r_tmp, r_tmp_tif)
    fs::file_delete(rast_tif)
    fs::file_move(r_tmp_tif, rast_tif)
    rm(r)
    rm(r_tmp)
} else {
    terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
}
debug: terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
debug: r <- terra::rast(rast_tif)
debug: d_r <- mutate(tidyr::pivot_longer(sf::st_drop_geometry(sf::st_as_sf(terra::zonal(x = r, 
    z = terra::vect(dplyr::select(sf_zones, dplyr::all_of(fld_zones))), 
    fun = zonal_fun, exact = T, na.rm = T, as.polygons = T))), 
    cols = -dplyr::any_of(fld_zones), names_to = "lyr", values_to = zonal_fun), 
    time = readr::parse_datetime(str_replace(lyr, glue("{var}\\|(.*)"), 
        "\\1")))
debug: if (!is.null(zonal_csv)) write_csv(d_r, zonal_csv)
debug: write_csv(d_r, zonal_csv)
debug: if (!keep_nc) unlink(dir_nc, recursive = T)
debug: unlink(dir_nc, recursive = T)
debug: return(d_r)
Downloading 1 requests, up to 248 time slices each
Called from: extractr::ed_extract(ed, var = v, sf_zones = ply, bbox = bb, 
    mask_tif = F, rast_tif = glue("{dir_out}/{nms}/{yr}.tif"), 
    zonal_fun = "mean", zonal_csv = glue("{dir_out}/{nms}/{yr}.csv"), 
    dir_nc = glue("{dir_out}/{nms}/{yr}_nc"), keep_nc = F, n_max_vals_per_req = 1e+05, 
    time_min = time_min, time_max = time_max, verbose = T)
debug: while (i_req <= n_reqs) {
    i_t_beg <- (i_req - 1) * n_t_per_req + 1
    i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
    t_req <- times_todo[c(i_t_beg, i_t_end)]
    t_req_str <- format_ISO8601(t_req, usetz = "Z")
    if (verbose) 
        message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
    ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
        ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
        0), nc)
    unlink(ncs0)
    nc_retry <- T
    nc_n_try <- 1
    n_max_retries
    while (nc_retry) {
        res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
            url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
                bbox[["xmax"]]), latitude = c(bbox[["ymin"]], 
                bbox[["ymax"]]), time = t_req_str, fmt = "nc", 
            store = rerddap::disk(path = dir_nc)))
        if (inherits(res, "try-error")) {
            err <- attr(res, "condition")
            msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
            nc_n_try <- nc_n_try + 1
            if (nc_n_try > n_max_retries) {
                stop(msg)
            }
            else {
                message(msg, "\nRETRYing...")
                Sys.sleep(1)
            }
        }
        else {
            nc_retry <- F
        }
    }
    i_req <- i_req + 1
}
debug: i_t_beg <- (i_req - 1) * n_t_per_req + 1
debug: i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
debug: t_req <- times_todo[c(i_t_beg, i_t_end)]
debug: t_req_str <- format_ISO8601(t_req, usetz = "Z")
debug: if (verbose) message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
debug: message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
Fetching request 1 of 1 (2019-01-01 to 2019-12-01) ~ 19:35:06 UTC
debug: ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
    0), nc)
debug: unlink(ncs0)
debug: nc_retry <- T
debug: nc_n_try <- 1
debug: n_max_retries
debug: while (nc_retry) {
    res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
        url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
            bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
        time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
    if (inherits(res, "try-error")) {
        err <- attr(res, "condition")
        msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
        nc_n_try <- nc_n_try + 1
        if (nc_n_try > n_max_retries) {
            stop(msg)
        }
        else {
            message(msg, "\nRETRYing...")
            Sys.sleep(1)
        }
    }
    else {
        nc_retry <- F
    }
}
debug: res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
    url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
        bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
    time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
debug: if (inherits(res, "try-error")) {
    err <- attr(res, "condition")
    msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
    nc_n_try <- nc_n_try + 1
    if (nc_n_try > n_max_retries) {
        stop(msg)
    }
    else {
        message(msg, "\nRETRYing...")
        Sys.sleep(1)
    }
} else {
    nc_retry <- F
}
debug: nc_retry <- F
debug: (while) nc_retry
debug: i_req <- i_req + 1
debug: (while) i_req <= n_reqs
debug: ncs <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size > 
    0), nc)
debug: r <- terra::rast(ncs)
debug: stopifnot(all(class(terra::time(r)) %in% c("POSIXct", "POSIXt")))
debug: idx <- dplyr::pull(dplyr::filter(dplyr::arrange(dplyr::tibble(idx = 1:terra::nlyr(r), 
    time = terra::time(r)), time), !duplicated(time)), idx)
debug: r <- terra::subset(r, idx)
debug: stopifnot(terra::crs(r, proj = T) == wgs84)
debug: if (mask_tif) r <- terra::mask(r, sf_zones)
debug: lyrs <- glue("{var}|{terra::time(r)}")
debug: if (length(dims_other) > 0 && !all(length(dims[dims_other]) == 
    1)) stop(glue("Other dimensions not yet supported: {paste(dims_other, collapse = ',')}"))
debug: names(r) <- lyrs
debug: if (!is.null(rast_tif)) {
    if (fs::file_exists(rast_tif)) {
        r_tmp_tif <- tempfile(fileext = ".tif")
        r_tmp <- c(rast(rast_tif), r)
        r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
        terra::writeRaster(r_tmp, r_tmp_tif)
        fs::file_delete(rast_tif)
        fs::file_move(r_tmp_tif, rast_tif)
        rm(r)
        rm(r_tmp)
    }
    else {
        terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
    }
    r <- terra::rast(rast_tif)
}
debug: if (fs::file_exists(rast_tif)) {
    r_tmp_tif <- tempfile(fileext = ".tif")
    r_tmp <- c(rast(rast_tif), r)
    r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
    terra::writeRaster(r_tmp, r_tmp_tif)
    fs::file_delete(rast_tif)
    fs::file_move(r_tmp_tif, rast_tif)
    rm(r)
    rm(r_tmp)
} else {
    terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
}
debug: terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
debug: r <- terra::rast(rast_tif)
debug: d_r <- mutate(tidyr::pivot_longer(sf::st_drop_geometry(sf::st_as_sf(terra::zonal(x = r, 
    z = terra::vect(dplyr::select(sf_zones, dplyr::all_of(fld_zones))), 
    fun = zonal_fun, exact = T, na.rm = T, as.polygons = T))), 
    cols = -dplyr::any_of(fld_zones), names_to = "lyr", values_to = zonal_fun), 
    time = readr::parse_datetime(str_replace(lyr, glue("{var}\\|(.*)"), 
        "\\1")))
debug: if (!is.null(zonal_csv)) write_csv(d_r, zonal_csv)
debug: write_csv(d_r, zonal_csv)
debug: if (!keep_nc) unlink(dir_nc, recursive = T)
debug: unlink(dir_nc, recursive = T)
debug: return(d_r)
Downloading 1 requests, up to 248 time slices each
Called from: extractr::ed_extract(ed, var = v, sf_zones = ply, bbox = bb, 
    mask_tif = F, rast_tif = glue("{dir_out}/{nms}/{yr}.tif"), 
    zonal_fun = "mean", zonal_csv = glue("{dir_out}/{nms}/{yr}.csv"), 
    dir_nc = glue("{dir_out}/{nms}/{yr}_nc"), keep_nc = F, n_max_vals_per_req = 1e+05, 
    time_min = time_min, time_max = time_max, verbose = T)
debug: while (i_req <= n_reqs) {
    i_t_beg <- (i_req - 1) * n_t_per_req + 1
    i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
    t_req <- times_todo[c(i_t_beg, i_t_end)]
    t_req_str <- format_ISO8601(t_req, usetz = "Z")
    if (verbose) 
        message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
    ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
        ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
        0), nc)
    unlink(ncs0)
    nc_retry <- T
    nc_n_try <- 1
    n_max_retries
    while (nc_retry) {
        res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
            url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
                bbox[["xmax"]]), latitude = c(bbox[["ymin"]], 
                bbox[["ymax"]]), time = t_req_str, fmt = "nc", 
            store = rerddap::disk(path = dir_nc)))
        if (inherits(res, "try-error")) {
            err <- attr(res, "condition")
            msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
            nc_n_try <- nc_n_try + 1
            if (nc_n_try > n_max_retries) {
                stop(msg)
            }
            else {
                message(msg, "\nRETRYing...")
                Sys.sleep(1)
            }
        }
        else {
            nc_retry <- F
        }
    }
    i_req <- i_req + 1
}
debug: i_t_beg <- (i_req - 1) * n_t_per_req + 1
debug: i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
debug: t_req <- times_todo[c(i_t_beg, i_t_end)]
debug: t_req_str <- format_ISO8601(t_req, usetz = "Z")
debug: if (verbose) message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
debug: message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
Fetching request 1 of 1 (2020-01-01 to 2020-12-01) ~ 19:35:08 UTC
debug: ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
    0), nc)
debug: unlink(ncs0)
debug: nc_retry <- T
debug: nc_n_try <- 1
debug: n_max_retries
debug: while (nc_retry) {
    res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
        url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
            bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
        time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
    if (inherits(res, "try-error")) {
        err <- attr(res, "condition")
        msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
        nc_n_try <- nc_n_try + 1
        if (nc_n_try > n_max_retries) {
            stop(msg)
        }
        else {
            message(msg, "\nRETRYing...")
            Sys.sleep(1)
        }
    }
    else {
        nc_retry <- F
    }
}
debug: res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
    url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
        bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
    time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
debug: if (inherits(res, "try-error")) {
    err <- attr(res, "condition")
    msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
    nc_n_try <- nc_n_try + 1
    if (nc_n_try > n_max_retries) {
        stop(msg)
    }
    else {
        message(msg, "\nRETRYing...")
        Sys.sleep(1)
    }
} else {
    nc_retry <- F
}
debug: nc_retry <- F
debug: (while) nc_retry
debug: i_req <- i_req + 1
debug: (while) i_req <= n_reqs
debug: ncs <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size > 
    0), nc)
debug: r <- terra::rast(ncs)
debug: stopifnot(all(class(terra::time(r)) %in% c("POSIXct", "POSIXt")))
debug: idx <- dplyr::pull(dplyr::filter(dplyr::arrange(dplyr::tibble(idx = 1:terra::nlyr(r), 
    time = terra::time(r)), time), !duplicated(time)), idx)
debug: r <- terra::subset(r, idx)
debug: stopifnot(terra::crs(r, proj = T) == wgs84)
debug: if (mask_tif) r <- terra::mask(r, sf_zones)
debug: lyrs <- glue("{var}|{terra::time(r)}")
debug: if (length(dims_other) > 0 && !all(length(dims[dims_other]) == 
    1)) stop(glue("Other dimensions not yet supported: {paste(dims_other, collapse = ',')}"))
debug: names(r) <- lyrs
debug: if (!is.null(rast_tif)) {
    if (fs::file_exists(rast_tif)) {
        r_tmp_tif <- tempfile(fileext = ".tif")
        r_tmp <- c(rast(rast_tif), r)
        r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
        terra::writeRaster(r_tmp, r_tmp_tif)
        fs::file_delete(rast_tif)
        fs::file_move(r_tmp_tif, rast_tif)
        rm(r)
        rm(r_tmp)
    }
    else {
        terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
    }
    r <- terra::rast(rast_tif)
}
debug: if (fs::file_exists(rast_tif)) {
    r_tmp_tif <- tempfile(fileext = ".tif")
    r_tmp <- c(rast(rast_tif), r)
    r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
    terra::writeRaster(r_tmp, r_tmp_tif)
    fs::file_delete(rast_tif)
    fs::file_move(r_tmp_tif, rast_tif)
    rm(r)
    rm(r_tmp)
} else {
    terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
}
debug: terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
debug: r <- terra::rast(rast_tif)
debug: d_r <- mutate(tidyr::pivot_longer(sf::st_drop_geometry(sf::st_as_sf(terra::zonal(x = r, 
    z = terra::vect(dplyr::select(sf_zones, dplyr::all_of(fld_zones))), 
    fun = zonal_fun, exact = T, na.rm = T, as.polygons = T))), 
    cols = -dplyr::any_of(fld_zones), names_to = "lyr", values_to = zonal_fun), 
    time = readr::parse_datetime(str_replace(lyr, glue("{var}\\|(.*)"), 
        "\\1")))
debug: if (!is.null(zonal_csv)) write_csv(d_r, zonal_csv)
debug: write_csv(d_r, zonal_csv)
debug: if (!keep_nc) unlink(dir_nc, recursive = T)
debug: unlink(dir_nc, recursive = T)
debug: return(d_r)
Downloading 1 requests, up to 248 time slices each
Called from: extractr::ed_extract(ed, var = v, sf_zones = ply, bbox = bb, 
    mask_tif = F, rast_tif = glue("{dir_out}/{nms}/{yr}.tif"), 
    zonal_fun = "mean", zonal_csv = glue("{dir_out}/{nms}/{yr}.csv"), 
    dir_nc = glue("{dir_out}/{nms}/{yr}_nc"), keep_nc = F, n_max_vals_per_req = 1e+05, 
    time_min = time_min, time_max = time_max, verbose = T)
debug: while (i_req <= n_reqs) {
    i_t_beg <- (i_req - 1) * n_t_per_req + 1
    i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
    t_req <- times_todo[c(i_t_beg, i_t_end)]
    t_req_str <- format_ISO8601(t_req, usetz = "Z")
    if (verbose) 
        message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
    ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
        ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
        0), nc)
    unlink(ncs0)
    nc_retry <- T
    nc_n_try <- 1
    n_max_retries
    while (nc_retry) {
        res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
            url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
                bbox[["xmax"]]), latitude = c(bbox[["ymin"]], 
                bbox[["ymax"]]), time = t_req_str, fmt = "nc", 
            store = rerddap::disk(path = dir_nc)))
        if (inherits(res, "try-error")) {
            err <- attr(res, "condition")
            msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
            nc_n_try <- nc_n_try + 1
            if (nc_n_try > n_max_retries) {
                stop(msg)
            }
            else {
                message(msg, "\nRETRYing...")
                Sys.sleep(1)
            }
        }
        else {
            nc_retry <- F
        }
    }
    i_req <- i_req + 1
}
debug: i_t_beg <- (i_req - 1) * n_t_per_req + 1
debug: i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
debug: t_req <- times_todo[c(i_t_beg, i_t_end)]
debug: t_req_str <- format_ISO8601(t_req, usetz = "Z")
debug: if (verbose) message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
debug: message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
Fetching request 1 of 1 (2021-01-01 to 2021-12-01) ~ 19:35:10 UTC
debug: ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
    0), nc)
debug: unlink(ncs0)
debug: nc_retry <- T
debug: nc_n_try <- 1
debug: n_max_retries
debug: while (nc_retry) {
    res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
        url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
            bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
        time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
    if (inherits(res, "try-error")) {
        err <- attr(res, "condition")
        msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
        nc_n_try <- nc_n_try + 1
        if (nc_n_try > n_max_retries) {
            stop(msg)
        }
        else {
            message(msg, "\nRETRYing...")
            Sys.sleep(1)
        }
    }
    else {
        nc_retry <- F
    }
}
debug: res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
    url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
        bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
    time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
debug: if (inherits(res, "try-error")) {
    err <- attr(res, "condition")
    msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
    nc_n_try <- nc_n_try + 1
    if (nc_n_try > n_max_retries) {
        stop(msg)
    }
    else {
        message(msg, "\nRETRYing...")
        Sys.sleep(1)
    }
} else {
    nc_retry <- F
}
debug: nc_retry <- F
debug: (while) nc_retry
debug: i_req <- i_req + 1
debug: (while) i_req <= n_reqs
debug: ncs <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size > 
    0), nc)
debug: r <- terra::rast(ncs)
debug: stopifnot(all(class(terra::time(r)) %in% c("POSIXct", "POSIXt")))
debug: idx <- dplyr::pull(dplyr::filter(dplyr::arrange(dplyr::tibble(idx = 1:terra::nlyr(r), 
    time = terra::time(r)), time), !duplicated(time)), idx)
debug: r <- terra::subset(r, idx)
debug: stopifnot(terra::crs(r, proj = T) == wgs84)
debug: if (mask_tif) r <- terra::mask(r, sf_zones)
debug: lyrs <- glue("{var}|{terra::time(r)}")
debug: if (length(dims_other) > 0 && !all(length(dims[dims_other]) == 
    1)) stop(glue("Other dimensions not yet supported: {paste(dims_other, collapse = ',')}"))
debug: names(r) <- lyrs
debug: if (!is.null(rast_tif)) {
    if (fs::file_exists(rast_tif)) {
        r_tmp_tif <- tempfile(fileext = ".tif")
        r_tmp <- c(rast(rast_tif), r)
        r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
        terra::writeRaster(r_tmp, r_tmp_tif)
        fs::file_delete(rast_tif)
        fs::file_move(r_tmp_tif, rast_tif)
        rm(r)
        rm(r_tmp)
    }
    else {
        terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
    }
    r <- terra::rast(rast_tif)
}
debug: if (fs::file_exists(rast_tif)) {
    r_tmp_tif <- tempfile(fileext = ".tif")
    r_tmp <- c(rast(rast_tif), r)
    r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
    terra::writeRaster(r_tmp, r_tmp_tif)
    fs::file_delete(rast_tif)
    fs::file_move(r_tmp_tif, rast_tif)
    rm(r)
    rm(r_tmp)
} else {
    terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
}
debug: terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
debug: r <- terra::rast(rast_tif)
debug: d_r <- mutate(tidyr::pivot_longer(sf::st_drop_geometry(sf::st_as_sf(terra::zonal(x = r, 
    z = terra::vect(dplyr::select(sf_zones, dplyr::all_of(fld_zones))), 
    fun = zonal_fun, exact = T, na.rm = T, as.polygons = T))), 
    cols = -dplyr::any_of(fld_zones), names_to = "lyr", values_to = zonal_fun), 
    time = readr::parse_datetime(str_replace(lyr, glue("{var}\\|(.*)"), 
        "\\1")))
debug: if (!is.null(zonal_csv)) write_csv(d_r, zonal_csv)
debug: write_csv(d_r, zonal_csv)
debug: if (!keep_nc) unlink(dir_nc, recursive = T)
debug: unlink(dir_nc, recursive = T)
debug: return(d_r)
Downloading 1 requests, up to 248 time slices each
Called from: extractr::ed_extract(ed, var = v, sf_zones = ply, bbox = bb, 
    mask_tif = F, rast_tif = glue("{dir_out}/{nms}/{yr}.tif"), 
    zonal_fun = "mean", zonal_csv = glue("{dir_out}/{nms}/{yr}.csv"), 
    dir_nc = glue("{dir_out}/{nms}/{yr}_nc"), keep_nc = F, n_max_vals_per_req = 1e+05, 
    time_min = time_min, time_max = time_max, verbose = T)
debug: while (i_req <= n_reqs) {
    i_t_beg <- (i_req - 1) * n_t_per_req + 1
    i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
    t_req <- times_todo[c(i_t_beg, i_t_end)]
    t_req_str <- format_ISO8601(t_req, usetz = "Z")
    if (verbose) 
        message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
    ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
        ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
        0), nc)
    unlink(ncs0)
    nc_retry <- T
    nc_n_try <- 1
    n_max_retries
    while (nc_retry) {
        res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
            url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
                bbox[["xmax"]]), latitude = c(bbox[["ymin"]], 
                bbox[["ymax"]]), time = t_req_str, fmt = "nc", 
            store = rerddap::disk(path = dir_nc)))
        if (inherits(res, "try-error")) {
            err <- attr(res, "condition")
            msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
            nc_n_try <- nc_n_try + 1
            if (nc_n_try > n_max_retries) {
                stop(msg)
            }
            else {
                message(msg, "\nRETRYing...")
                Sys.sleep(1)
            }
        }
        else {
            nc_retry <- F
        }
    }
    i_req <- i_req + 1
}
debug: i_t_beg <- (i_req - 1) * n_t_per_req + 1
debug: i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
debug: t_req <- times_todo[c(i_t_beg, i_t_end)]
debug: t_req_str <- format_ISO8601(t_req, usetz = "Z")
debug: if (verbose) message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
debug: message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
Fetching request 1 of 1 (2022-01-01 to 2022-12-01) ~ 19:35:12 UTC
debug: ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
    0), nc)
debug: unlink(ncs0)
debug: nc_retry <- T
debug: nc_n_try <- 1
debug: n_max_retries
debug: while (nc_retry) {
    res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
        url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
            bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
        time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
    if (inherits(res, "try-error")) {
        err <- attr(res, "condition")
        msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
        nc_n_try <- nc_n_try + 1
        if (nc_n_try > n_max_retries) {
            stop(msg)
        }
        else {
            message(msg, "\nRETRYing...")
            Sys.sleep(1)
        }
    }
    else {
        nc_retry <- F
    }
}
debug: res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
    url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
        bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
    time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
debug: if (inherits(res, "try-error")) {
    err <- attr(res, "condition")
    msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
    nc_n_try <- nc_n_try + 1
    if (nc_n_try > n_max_retries) {
        stop(msg)
    }
    else {
        message(msg, "\nRETRYing...")
        Sys.sleep(1)
    }
} else {
    nc_retry <- F
}
debug: nc_retry <- F
debug: (while) nc_retry
debug: i_req <- i_req + 1
debug: (while) i_req <= n_reqs
debug: ncs <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size > 
    0), nc)
debug: r <- terra::rast(ncs)
debug: stopifnot(all(class(terra::time(r)) %in% c("POSIXct", "POSIXt")))
debug: idx <- dplyr::pull(dplyr::filter(dplyr::arrange(dplyr::tibble(idx = 1:terra::nlyr(r), 
    time = terra::time(r)), time), !duplicated(time)), idx)
debug: r <- terra::subset(r, idx)
debug: stopifnot(terra::crs(r, proj = T) == wgs84)
debug: if (mask_tif) r <- terra::mask(r, sf_zones)
debug: lyrs <- glue("{var}|{terra::time(r)}")
debug: if (length(dims_other) > 0 && !all(length(dims[dims_other]) == 
    1)) stop(glue("Other dimensions not yet supported: {paste(dims_other, collapse = ',')}"))
debug: names(r) <- lyrs
debug: if (!is.null(rast_tif)) {
    if (fs::file_exists(rast_tif)) {
        r_tmp_tif <- tempfile(fileext = ".tif")
        r_tmp <- c(rast(rast_tif), r)
        r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
        terra::writeRaster(r_tmp, r_tmp_tif)
        fs::file_delete(rast_tif)
        fs::file_move(r_tmp_tif, rast_tif)
        rm(r)
        rm(r_tmp)
    }
    else {
        terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
    }
    r <- terra::rast(rast_tif)
}
debug: if (fs::file_exists(rast_tif)) {
    r_tmp_tif <- tempfile(fileext = ".tif")
    r_tmp <- c(rast(rast_tif), r)
    r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
    terra::writeRaster(r_tmp, r_tmp_tif)
    fs::file_delete(rast_tif)
    fs::file_move(r_tmp_tif, rast_tif)
    rm(r)
    rm(r_tmp)
} else {
    terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
}
debug: terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
debug: r <- terra::rast(rast_tif)
debug: d_r <- mutate(tidyr::pivot_longer(sf::st_drop_geometry(sf::st_as_sf(terra::zonal(x = r, 
    z = terra::vect(dplyr::select(sf_zones, dplyr::all_of(fld_zones))), 
    fun = zonal_fun, exact = T, na.rm = T, as.polygons = T))), 
    cols = -dplyr::any_of(fld_zones), names_to = "lyr", values_to = zonal_fun), 
    time = readr::parse_datetime(str_replace(lyr, glue("{var}\\|(.*)"), 
        "\\1")))
debug: if (!is.null(zonal_csv)) write_csv(d_r, zonal_csv)
debug: write_csv(d_r, zonal_csv)
debug: if (!keep_nc) unlink(dir_nc, recursive = T)
debug: unlink(dir_nc, recursive = T)
debug: return(d_r)
Downloading 1 requests, up to 248 time slices each
Called from: extractr::ed_extract(ed, var = v, sf_zones = ply, bbox = bb, 
    mask_tif = F, rast_tif = glue("{dir_out}/{nms}/{yr}.tif"), 
    zonal_fun = "mean", zonal_csv = glue("{dir_out}/{nms}/{yr}.csv"), 
    dir_nc = glue("{dir_out}/{nms}/{yr}_nc"), keep_nc = F, n_max_vals_per_req = 1e+05, 
    time_min = time_min, time_max = time_max, verbose = T)
debug: while (i_req <= n_reqs) {
    i_t_beg <- (i_req - 1) * n_t_per_req + 1
    i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
    t_req <- times_todo[c(i_t_beg, i_t_end)]
    t_req_str <- format_ISO8601(t_req, usetz = "Z")
    if (verbose) 
        message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
    ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
        ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
        0), nc)
    unlink(ncs0)
    nc_retry <- T
    nc_n_try <- 1
    n_max_retries
    while (nc_retry) {
        res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
            url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
                bbox[["xmax"]]), latitude = c(bbox[["ymin"]], 
                bbox[["ymax"]]), time = t_req_str, fmt = "nc", 
            store = rerddap::disk(path = dir_nc)))
        if (inherits(res, "try-error")) {
            err <- attr(res, "condition")
            msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
            nc_n_try <- nc_n_try + 1
            if (nc_n_try > n_max_retries) {
                stop(msg)
            }
            else {
                message(msg, "\nRETRYing...")
                Sys.sleep(1)
            }
        }
        else {
            nc_retry <- F
        }
    }
    i_req <- i_req + 1
}
debug: i_t_beg <- (i_req - 1) * n_t_per_req + 1
debug: i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
debug: t_req <- times_todo[c(i_t_beg, i_t_end)]
debug: t_req_str <- format_ISO8601(t_req, usetz = "Z")
debug: if (verbose) message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
debug: message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
Fetching request 1 of 1 (2023-01-01 to 2023-12-01) ~ 19:35:14 UTC
debug: ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
    0), nc)
debug: unlink(ncs0)
debug: nc_retry <- T
debug: nc_n_try <- 1
debug: n_max_retries
debug: while (nc_retry) {
    res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
        url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
            bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
        time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
    if (inherits(res, "try-error")) {
        err <- attr(res, "condition")
        msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
        nc_n_try <- nc_n_try + 1
        if (nc_n_try > n_max_retries) {
            stop(msg)
        }
        else {
            message(msg, "\nRETRYing...")
            Sys.sleep(1)
        }
    }
    else {
        nc_retry <- F
    }
}
debug: res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
    url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
        bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
    time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
debug: if (inherits(res, "try-error")) {
    err <- attr(res, "condition")
    msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
    nc_n_try <- nc_n_try + 1
    if (nc_n_try > n_max_retries) {
        stop(msg)
    }
    else {
        message(msg, "\nRETRYing...")
        Sys.sleep(1)
    }
} else {
    nc_retry <- F
}
debug: nc_retry <- F
debug: (while) nc_retry
debug: i_req <- i_req + 1
debug: (while) i_req <= n_reqs
debug: ncs <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size > 
    0), nc)
debug: r <- terra::rast(ncs)
debug: stopifnot(all(class(terra::time(r)) %in% c("POSIXct", "POSIXt")))
debug: idx <- dplyr::pull(dplyr::filter(dplyr::arrange(dplyr::tibble(idx = 1:terra::nlyr(r), 
    time = terra::time(r)), time), !duplicated(time)), idx)
debug: r <- terra::subset(r, idx)
debug: stopifnot(terra::crs(r, proj = T) == wgs84)
debug: if (mask_tif) r <- terra::mask(r, sf_zones)
debug: lyrs <- glue("{var}|{terra::time(r)}")
debug: if (length(dims_other) > 0 && !all(length(dims[dims_other]) == 
    1)) stop(glue("Other dimensions not yet supported: {paste(dims_other, collapse = ',')}"))
debug: names(r) <- lyrs
debug: if (!is.null(rast_tif)) {
    if (fs::file_exists(rast_tif)) {
        r_tmp_tif <- tempfile(fileext = ".tif")
        r_tmp <- c(rast(rast_tif), r)
        r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
        terra::writeRaster(r_tmp, r_tmp_tif)
        fs::file_delete(rast_tif)
        fs::file_move(r_tmp_tif, rast_tif)
        rm(r)
        rm(r_tmp)
    }
    else {
        terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
    }
    r <- terra::rast(rast_tif)
}
debug: if (fs::file_exists(rast_tif)) {
    r_tmp_tif <- tempfile(fileext = ".tif")
    r_tmp <- c(rast(rast_tif), r)
    r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
    terra::writeRaster(r_tmp, r_tmp_tif)
    fs::file_delete(rast_tif)
    fs::file_move(r_tmp_tif, rast_tif)
    rm(r)
    rm(r_tmp)
} else {
    terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
}
debug: terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
debug: r <- terra::rast(rast_tif)
debug: d_r <- mutate(tidyr::pivot_longer(sf::st_drop_geometry(sf::st_as_sf(terra::zonal(x = r, 
    z = terra::vect(dplyr::select(sf_zones, dplyr::all_of(fld_zones))), 
    fun = zonal_fun, exact = T, na.rm = T, as.polygons = T))), 
    cols = -dplyr::any_of(fld_zones), names_to = "lyr", values_to = zonal_fun), 
    time = readr::parse_datetime(str_replace(lyr, glue("{var}\\|(.*)"), 
        "\\1")))
debug: if (!is.null(zonal_csv)) write_csv(d_r, zonal_csv)
debug: write_csv(d_r, zonal_csv)
debug: if (!keep_nc) unlink(dir_nc, recursive = T)
debug: unlink(dir_nc, recursive = T)
debug: return(d_r)
Downloading 1 requests, up to 248 time slices each
Called from: extractr::ed_extract(ed, var = v, sf_zones = ply, bbox = bb, 
    mask_tif = F, rast_tif = glue("{dir_out}/{nms}/{yr}.tif"), 
    zonal_fun = "mean", zonal_csv = glue("{dir_out}/{nms}/{yr}.csv"), 
    dir_nc = glue("{dir_out}/{nms}/{yr}_nc"), keep_nc = F, n_max_vals_per_req = 1e+05, 
    time_min = time_min, time_max = time_max, verbose = T)
debug: while (i_req <= n_reqs) {
    i_t_beg <- (i_req - 1) * n_t_per_req + 1
    i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
    t_req <- times_todo[c(i_t_beg, i_t_end)]
    t_req_str <- format_ISO8601(t_req, usetz = "Z")
    if (verbose) 
        message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
    ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
        ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
        0), nc)
    unlink(ncs0)
    nc_retry <- T
    nc_n_try <- 1
    n_max_retries
    while (nc_retry) {
        res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
            url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
                bbox[["xmax"]]), latitude = c(bbox[["ymin"]], 
                bbox[["ymax"]]), time = t_req_str, fmt = "nc", 
            store = rerddap::disk(path = dir_nc)))
        if (inherits(res, "try-error")) {
            err <- attr(res, "condition")
            msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
            nc_n_try <- nc_n_try + 1
            if (nc_n_try > n_max_retries) {
                stop(msg)
            }
            else {
                message(msg, "\nRETRYing...")
                Sys.sleep(1)
            }
        }
        else {
            nc_retry <- F
        }
    }
    i_req <- i_req + 1
}
debug: i_t_beg <- (i_req - 1) * n_t_per_req + 1
debug: i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
debug: t_req <- times_todo[c(i_t_beg, i_t_end)]
debug: t_req_str <- format_ISO8601(t_req, usetz = "Z")
debug: if (verbose) message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
debug: message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
Fetching request 1 of 1 (2024-01-01 to 2024-12-01) ~ 19:35:15 UTC
debug: ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
    0), nc)
debug: unlink(ncs0)
debug: nc_retry <- T
debug: nc_n_try <- 1
debug: n_max_retries
debug: while (nc_retry) {
    res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
        url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
            bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
        time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
    if (inherits(res, "try-error")) {
        err <- attr(res, "condition")
        msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
        nc_n_try <- nc_n_try + 1
        if (nc_n_try > n_max_retries) {
            stop(msg)
        }
        else {
            message(msg, "\nRETRYing...")
            Sys.sleep(1)
        }
    }
    else {
        nc_retry <- F
    }
}
debug: res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
    url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
        bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
    time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
debug: if (inherits(res, "try-error")) {
    err <- attr(res, "condition")
    msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
    nc_n_try <- nc_n_try + 1
    if (nc_n_try > n_max_retries) {
        stop(msg)
    }
    else {
        message(msg, "\nRETRYing...")
        Sys.sleep(1)
    }
} else {
    nc_retry <- F
}
debug: nc_retry <- F
debug: (while) nc_retry
debug: i_req <- i_req + 1
debug: (while) i_req <= n_reqs
debug: ncs <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size > 
    0), nc)
debug: r <- terra::rast(ncs)
debug: stopifnot(all(class(terra::time(r)) %in% c("POSIXct", "POSIXt")))
debug: idx <- dplyr::pull(dplyr::filter(dplyr::arrange(dplyr::tibble(idx = 1:terra::nlyr(r), 
    time = terra::time(r)), time), !duplicated(time)), idx)
debug: r <- terra::subset(r, idx)
debug: stopifnot(terra::crs(r, proj = T) == wgs84)
debug: if (mask_tif) r <- terra::mask(r, sf_zones)
debug: lyrs <- glue("{var}|{terra::time(r)}")
debug: if (length(dims_other) > 0 && !all(length(dims[dims_other]) == 
    1)) stop(glue("Other dimensions not yet supported: {paste(dims_other, collapse = ',')}"))
debug: names(r) <- lyrs
debug: if (!is.null(rast_tif)) {
    if (fs::file_exists(rast_tif)) {
        r_tmp_tif <- tempfile(fileext = ".tif")
        r_tmp <- c(rast(rast_tif), r)
        r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
        terra::writeRaster(r_tmp, r_tmp_tif)
        fs::file_delete(rast_tif)
        fs::file_move(r_tmp_tif, rast_tif)
        rm(r)
        rm(r_tmp)
    }
    else {
        terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
    }
    r <- terra::rast(rast_tif)
}
debug: if (fs::file_exists(rast_tif)) {
    r_tmp_tif <- tempfile(fileext = ".tif")
    r_tmp <- c(rast(rast_tif), r)
    r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
    terra::writeRaster(r_tmp, r_tmp_tif)
    fs::file_delete(rast_tif)
    fs::file_move(r_tmp_tif, rast_tif)
    rm(r)
    rm(r_tmp)
} else {
    terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
}
debug: terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
debug: r <- terra::rast(rast_tif)
debug: d_r <- mutate(tidyr::pivot_longer(sf::st_drop_geometry(sf::st_as_sf(terra::zonal(x = r, 
    z = terra::vect(dplyr::select(sf_zones, dplyr::all_of(fld_zones))), 
    fun = zonal_fun, exact = T, na.rm = T, as.polygons = T))), 
    cols = -dplyr::any_of(fld_zones), names_to = "lyr", values_to = zonal_fun), 
    time = readr::parse_datetime(str_replace(lyr, glue("{var}\\|(.*)"), 
        "\\1")))
debug: if (!is.null(zonal_csv)) write_csv(d_r, zonal_csv)
debug: write_csv(d_r, zonal_csv)
debug: if (!keep_nc) unlink(dir_nc, recursive = T)
debug: unlink(dir_nc, recursive = T)
debug: return(d_r)
Downloading 1 requests, up to 248 time slices each
Called from: extractr::ed_extract(ed, var = v, sf_zones = ply, bbox = bb, 
    mask_tif = F, rast_tif = glue("{dir_out}/{nms}/{yr}.tif"), 
    zonal_fun = "mean", zonal_csv = glue("{dir_out}/{nms}/{yr}.csv"), 
    dir_nc = glue("{dir_out}/{nms}/{yr}_nc"), keep_nc = F, n_max_vals_per_req = 1e+05, 
    time_min = time_min, time_max = time_max, verbose = T)
debug: while (i_req <= n_reqs) {
    i_t_beg <- (i_req - 1) * n_t_per_req + 1
    i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
    t_req <- times_todo[c(i_t_beg, i_t_end)]
    t_req_str <- format_ISO8601(t_req, usetz = "Z")
    if (verbose) 
        message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
    ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
        ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
        0), nc)
    unlink(ncs0)
    nc_retry <- T
    nc_n_try <- 1
    n_max_retries
    while (nc_retry) {
        res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
            url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
                bbox[["xmax"]]), latitude = c(bbox[["ymin"]], 
                bbox[["ymax"]]), time = t_req_str, fmt = "nc", 
            store = rerddap::disk(path = dir_nc)))
        if (inherits(res, "try-error")) {
            err <- attr(res, "condition")
            msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
            nc_n_try <- nc_n_try + 1
            if (nc_n_try > n_max_retries) {
                stop(msg)
            }
            else {
                message(msg, "\nRETRYing...")
                Sys.sleep(1)
            }
        }
        else {
            nc_retry <- F
        }
    }
    i_req <- i_req + 1
}
debug: i_t_beg <- (i_req - 1) * n_t_per_req + 1
debug: i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
debug: t_req <- times_todo[c(i_t_beg, i_t_end)]
debug: t_req_str <- format_ISO8601(t_req, usetz = "Z")
debug: if (verbose) message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
debug: message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
Fetching request 1 of 1 (2025-01-01 to 2025-07-01) ~ 19:35:17 UTC
debug: ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
    0), nc)
debug: unlink(ncs0)
debug: nc_retry <- T
debug: nc_n_try <- 1
debug: n_max_retries
debug: while (nc_retry) {
    res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
        url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
            bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
        time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
    if (inherits(res, "try-error")) {
        err <- attr(res, "condition")
        msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
        nc_n_try <- nc_n_try + 1
        if (nc_n_try > n_max_retries) {
            stop(msg)
        }
        else {
            message(msg, "\nRETRYing...")
            Sys.sleep(1)
        }
    }
    else {
        nc_retry <- F
    }
}
debug: res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
    url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
        bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
    time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
debug: if (inherits(res, "try-error")) {
    err <- attr(res, "condition")
    msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
    nc_n_try <- nc_n_try + 1
    if (nc_n_try > n_max_retries) {
        stop(msg)
    }
    else {
        message(msg, "\nRETRYing...")
        Sys.sleep(1)
    }
} else {
    nc_retry <- F
}
debug: nc_retry <- F
debug: (while) nc_retry
debug: i_req <- i_req + 1
debug: (while) i_req <= n_reqs
debug: ncs <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size > 
    0), nc)
debug: r <- terra::rast(ncs)
debug: stopifnot(all(class(terra::time(r)) %in% c("POSIXct", "POSIXt")))
debug: idx <- dplyr::pull(dplyr::filter(dplyr::arrange(dplyr::tibble(idx = 1:terra::nlyr(r), 
    time = terra::time(r)), time), !duplicated(time)), idx)
debug: r <- terra::subset(r, idx)
debug: stopifnot(terra::crs(r, proj = T) == wgs84)
debug: if (mask_tif) r <- terra::mask(r, sf_zones)
debug: lyrs <- glue("{var}|{terra::time(r)}")
debug: if (length(dims_other) > 0 && !all(length(dims[dims_other]) == 
    1)) stop(glue("Other dimensions not yet supported: {paste(dims_other, collapse = ',')}"))
debug: names(r) <- lyrs
debug: if (!is.null(rast_tif)) {
    if (fs::file_exists(rast_tif)) {
        r_tmp_tif <- tempfile(fileext = ".tif")
        r_tmp <- c(rast(rast_tif), r)
        r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
        terra::writeRaster(r_tmp, r_tmp_tif)
        fs::file_delete(rast_tif)
        fs::file_move(r_tmp_tif, rast_tif)
        rm(r)
        rm(r_tmp)
    }
    else {
        terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
    }
    r <- terra::rast(rast_tif)
}
debug: if (fs::file_exists(rast_tif)) {
    r_tmp_tif <- tempfile(fileext = ".tif")
    r_tmp <- c(rast(rast_tif), r)
    r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
    terra::writeRaster(r_tmp, r_tmp_tif)
    fs::file_delete(rast_tif)
    fs::file_move(r_tmp_tif, rast_tif)
    rm(r)
    rm(r_tmp)
} else {
    terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
}
debug: terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
debug: r <- terra::rast(rast_tif)
debug: d_r <- mutate(tidyr::pivot_longer(sf::st_drop_geometry(sf::st_as_sf(terra::zonal(x = r, 
    z = terra::vect(dplyr::select(sf_zones, dplyr::all_of(fld_zones))), 
    fun = zonal_fun, exact = T, na.rm = T, as.polygons = T))), 
    cols = -dplyr::any_of(fld_zones), names_to = "lyr", values_to = zonal_fun), 
    time = readr::parse_datetime(str_replace(lyr, glue("{var}\\|(.*)"), 
        "\\1")))
debug: if (!is.null(zonal_csv)) write_csv(d_r, zonal_csv)
debug: write_csv(d_r, zonal_csv)
debug: if (!keep_nc) unlink(dir_nc, recursive = T)
debug: unlink(dir_nc, recursive = T)
debug: return(d_r)
Downloading 1 requests, up to 125 time slices each
Called from: extractr::ed_extract(ed, var = v, sf_zones = ply, bbox = bb, 
    mask_tif = F, rast_tif = glue("{dir_out}/{nms}/{yr}.tif"), 
    zonal_fun = "mean", zonal_csv = glue("{dir_out}/{nms}/{yr}.csv"), 
    dir_nc = glue("{dir_out}/{nms}/{yr}_nc"), keep_nc = F, n_max_vals_per_req = 1e+05, 
    time_min = time_min, time_max = time_max, verbose = T)
debug: while (i_req <= n_reqs) {
    i_t_beg <- (i_req - 1) * n_t_per_req + 1
    i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
    t_req <- times_todo[c(i_t_beg, i_t_end)]
    t_req_str <- format_ISO8601(t_req, usetz = "Z")
    if (verbose) 
        message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
    ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
        ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
        0), nc)
    unlink(ncs0)
    nc_retry <- T
    nc_n_try <- 1
    n_max_retries
    while (nc_retry) {
        res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
            url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
                bbox[["xmax"]]), latitude = c(bbox[["ymin"]], 
                bbox[["ymax"]]), time = t_req_str, fmt = "nc", 
            store = rerddap::disk(path = dir_nc)))
        if (inherits(res, "try-error")) {
            err <- attr(res, "condition")
            msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
            nc_n_try <- nc_n_try + 1
            if (nc_n_try > n_max_retries) {
                stop(msg)
            }
            else {
                message(msg, "\nRETRYing...")
                Sys.sleep(1)
            }
        }
        else {
            nc_retry <- F
        }
    }
    i_req <- i_req + 1
}
debug: i_t_beg <- (i_req - 1) * n_t_per_req + 1
debug: i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
debug: t_req <- times_todo[c(i_t_beg, i_t_end)]
debug: t_req_str <- format_ISO8601(t_req, usetz = "Z")
debug: if (verbose) message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
debug: message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
Fetching request 1 of 1 (1998-01-01 to 1998-12-01) ~ 19:35:19 UTC
debug: ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
    0), nc)
debug: unlink(ncs0)
debug: nc_retry <- T
debug: nc_n_try <- 1
debug: n_max_retries
debug: while (nc_retry) {
    res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
        url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
            bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
        time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
    if (inherits(res, "try-error")) {
        err <- attr(res, "condition")
        msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
        nc_n_try <- nc_n_try + 1
        if (nc_n_try > n_max_retries) {
            stop(msg)
        }
        else {
            message(msg, "\nRETRYing...")
            Sys.sleep(1)
        }
    }
    else {
        nc_retry <- F
    }
}
debug: res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
    url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
        bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
    time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
debug: if (inherits(res, "try-error")) {
    err <- attr(res, "condition")
    msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
    nc_n_try <- nc_n_try + 1
    if (nc_n_try > n_max_retries) {
        stop(msg)
    }
    else {
        message(msg, "\nRETRYing...")
        Sys.sleep(1)
    }
} else {
    nc_retry <- F
}
debug: nc_retry <- F
debug: (while) nc_retry
debug: i_req <- i_req + 1
debug: (while) i_req <= n_reqs
debug: ncs <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size > 
    0), nc)
debug: r <- terra::rast(ncs)
debug: stopifnot(all(class(terra::time(r)) %in% c("POSIXct", "POSIXt")))
debug: idx <- dplyr::pull(dplyr::filter(dplyr::arrange(dplyr::tibble(idx = 1:terra::nlyr(r), 
    time = terra::time(r)), time), !duplicated(time)), idx)
debug: r <- terra::subset(r, idx)
debug: stopifnot(terra::crs(r, proj = T) == wgs84)
debug: if (mask_tif) r <- terra::mask(r, sf_zones)
debug: lyrs <- glue("{var}|{terra::time(r)}")
debug: if (length(dims_other) > 0 && !all(length(dims[dims_other]) == 
    1)) stop(glue("Other dimensions not yet supported: {paste(dims_other, collapse = ',')}"))
debug: names(r) <- lyrs
debug: if (!is.null(rast_tif)) {
    if (fs::file_exists(rast_tif)) {
        r_tmp_tif <- tempfile(fileext = ".tif")
        r_tmp <- c(rast(rast_tif), r)
        r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
        terra::writeRaster(r_tmp, r_tmp_tif)
        fs::file_delete(rast_tif)
        fs::file_move(r_tmp_tif, rast_tif)
        rm(r)
        rm(r_tmp)
    }
    else {
        terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
    }
    r <- terra::rast(rast_tif)
}
debug: if (fs::file_exists(rast_tif)) {
    r_tmp_tif <- tempfile(fileext = ".tif")
    r_tmp <- c(rast(rast_tif), r)
    r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
    terra::writeRaster(r_tmp, r_tmp_tif)
    fs::file_delete(rast_tif)
    fs::file_move(r_tmp_tif, rast_tif)
    rm(r)
    rm(r_tmp)
} else {
    terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
}
debug: terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
debug: r <- terra::rast(rast_tif)
debug: d_r <- mutate(tidyr::pivot_longer(sf::st_drop_geometry(sf::st_as_sf(terra::zonal(x = r, 
    z = terra::vect(dplyr::select(sf_zones, dplyr::all_of(fld_zones))), 
    fun = zonal_fun, exact = T, na.rm = T, as.polygons = T))), 
    cols = -dplyr::any_of(fld_zones), names_to = "lyr", values_to = zonal_fun), 
    time = readr::parse_datetime(str_replace(lyr, glue("{var}\\|(.*)"), 
        "\\1")))
debug: if (!is.null(zonal_csv)) write_csv(d_r, zonal_csv)
debug: write_csv(d_r, zonal_csv)
debug: if (!keep_nc) unlink(dir_nc, recursive = T)
debug: unlink(dir_nc, recursive = T)
debug: return(d_r)
Downloading 1 requests, up to 125 time slices each
Called from: extractr::ed_extract(ed, var = v, sf_zones = ply, bbox = bb, 
    mask_tif = F, rast_tif = glue("{dir_out}/{nms}/{yr}.tif"), 
    zonal_fun = "mean", zonal_csv = glue("{dir_out}/{nms}/{yr}.csv"), 
    dir_nc = glue("{dir_out}/{nms}/{yr}_nc"), keep_nc = F, n_max_vals_per_req = 1e+05, 
    time_min = time_min, time_max = time_max, verbose = T)
debug: while (i_req <= n_reqs) {
    i_t_beg <- (i_req - 1) * n_t_per_req + 1
    i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
    t_req <- times_todo[c(i_t_beg, i_t_end)]
    t_req_str <- format_ISO8601(t_req, usetz = "Z")
    if (verbose) 
        message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
    ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
        ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
        0), nc)
    unlink(ncs0)
    nc_retry <- T
    nc_n_try <- 1
    n_max_retries
    while (nc_retry) {
        res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
            url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
                bbox[["xmax"]]), latitude = c(bbox[["ymin"]], 
                bbox[["ymax"]]), time = t_req_str, fmt = "nc", 
            store = rerddap::disk(path = dir_nc)))
        if (inherits(res, "try-error")) {
            err <- attr(res, "condition")
            msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
            nc_n_try <- nc_n_try + 1
            if (nc_n_try > n_max_retries) {
                stop(msg)
            }
            else {
                message(msg, "\nRETRYing...")
                Sys.sleep(1)
            }
        }
        else {
            nc_retry <- F
        }
    }
    i_req <- i_req + 1
}
debug: i_t_beg <- (i_req - 1) * n_t_per_req + 1
debug: i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
debug: t_req <- times_todo[c(i_t_beg, i_t_end)]
debug: t_req_str <- format_ISO8601(t_req, usetz = "Z")
debug: if (verbose) message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
debug: message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
Fetching request 1 of 1 (1999-01-01 to 1999-12-01) ~ 19:35:22 UTC
debug: ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
    0), nc)
debug: unlink(ncs0)
debug: nc_retry <- T
debug: nc_n_try <- 1
debug: n_max_retries
debug: while (nc_retry) {
    res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
        url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
            bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
        time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
    if (inherits(res, "try-error")) {
        err <- attr(res, "condition")
        msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
        nc_n_try <- nc_n_try + 1
        if (nc_n_try > n_max_retries) {
            stop(msg)
        }
        else {
            message(msg, "\nRETRYing...")
            Sys.sleep(1)
        }
    }
    else {
        nc_retry <- F
    }
}
debug: res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
    url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
        bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
    time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
debug: if (inherits(res, "try-error")) {
    err <- attr(res, "condition")
    msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
    nc_n_try <- nc_n_try + 1
    if (nc_n_try > n_max_retries) {
        stop(msg)
    }
    else {
        message(msg, "\nRETRYing...")
        Sys.sleep(1)
    }
} else {
    nc_retry <- F
}
debug: nc_retry <- F
debug: (while) nc_retry
debug: i_req <- i_req + 1
debug: (while) i_req <= n_reqs
debug: ncs <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size > 
    0), nc)
debug: r <- terra::rast(ncs)
debug: stopifnot(all(class(terra::time(r)) %in% c("POSIXct", "POSIXt")))
debug: idx <- dplyr::pull(dplyr::filter(dplyr::arrange(dplyr::tibble(idx = 1:terra::nlyr(r), 
    time = terra::time(r)), time), !duplicated(time)), idx)
debug: r <- terra::subset(r, idx)
debug: stopifnot(terra::crs(r, proj = T) == wgs84)
debug: if (mask_tif) r <- terra::mask(r, sf_zones)
debug: lyrs <- glue("{var}|{terra::time(r)}")
debug: if (length(dims_other) > 0 && !all(length(dims[dims_other]) == 
    1)) stop(glue("Other dimensions not yet supported: {paste(dims_other, collapse = ',')}"))
debug: names(r) <- lyrs
debug: if (!is.null(rast_tif)) {
    if (fs::file_exists(rast_tif)) {
        r_tmp_tif <- tempfile(fileext = ".tif")
        r_tmp <- c(rast(rast_tif), r)
        r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
        terra::writeRaster(r_tmp, r_tmp_tif)
        fs::file_delete(rast_tif)
        fs::file_move(r_tmp_tif, rast_tif)
        rm(r)
        rm(r_tmp)
    }
    else {
        terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
    }
    r <- terra::rast(rast_tif)
}
debug: if (fs::file_exists(rast_tif)) {
    r_tmp_tif <- tempfile(fileext = ".tif")
    r_tmp <- c(rast(rast_tif), r)
    r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
    terra::writeRaster(r_tmp, r_tmp_tif)
    fs::file_delete(rast_tif)
    fs::file_move(r_tmp_tif, rast_tif)
    rm(r)
    rm(r_tmp)
} else {
    terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
}
debug: terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
debug: r <- terra::rast(rast_tif)
debug: d_r <- mutate(tidyr::pivot_longer(sf::st_drop_geometry(sf::st_as_sf(terra::zonal(x = r, 
    z = terra::vect(dplyr::select(sf_zones, dplyr::all_of(fld_zones))), 
    fun = zonal_fun, exact = T, na.rm = T, as.polygons = T))), 
    cols = -dplyr::any_of(fld_zones), names_to = "lyr", values_to = zonal_fun), 
    time = readr::parse_datetime(str_replace(lyr, glue("{var}\\|(.*)"), 
        "\\1")))
debug: if (!is.null(zonal_csv)) write_csv(d_r, zonal_csv)
debug: write_csv(d_r, zonal_csv)
debug: if (!keep_nc) unlink(dir_nc, recursive = T)
debug: unlink(dir_nc, recursive = T)
debug: return(d_r)
Downloading 1 requests, up to 125 time slices each
Called from: extractr::ed_extract(ed, var = v, sf_zones = ply, bbox = bb, 
    mask_tif = F, rast_tif = glue("{dir_out}/{nms}/{yr}.tif"), 
    zonal_fun = "mean", zonal_csv = glue("{dir_out}/{nms}/{yr}.csv"), 
    dir_nc = glue("{dir_out}/{nms}/{yr}_nc"), keep_nc = F, n_max_vals_per_req = 1e+05, 
    time_min = time_min, time_max = time_max, verbose = T)
debug: while (i_req <= n_reqs) {
    i_t_beg <- (i_req - 1) * n_t_per_req + 1
    i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
    t_req <- times_todo[c(i_t_beg, i_t_end)]
    t_req_str <- format_ISO8601(t_req, usetz = "Z")
    if (verbose) 
        message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
    ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
        ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
        0), nc)
    unlink(ncs0)
    nc_retry <- T
    nc_n_try <- 1
    n_max_retries
    while (nc_retry) {
        res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
            url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
                bbox[["xmax"]]), latitude = c(bbox[["ymin"]], 
                bbox[["ymax"]]), time = t_req_str, fmt = "nc", 
            store = rerddap::disk(path = dir_nc)))
        if (inherits(res, "try-error")) {
            err <- attr(res, "condition")
            msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
            nc_n_try <- nc_n_try + 1
            if (nc_n_try > n_max_retries) {
                stop(msg)
            }
            else {
                message(msg, "\nRETRYing...")
                Sys.sleep(1)
            }
        }
        else {
            nc_retry <- F
        }
    }
    i_req <- i_req + 1
}
debug: i_t_beg <- (i_req - 1) * n_t_per_req + 1
debug: i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
debug: t_req <- times_todo[c(i_t_beg, i_t_end)]
debug: t_req_str <- format_ISO8601(t_req, usetz = "Z")
debug: if (verbose) message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
debug: message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
Fetching request 1 of 1 (2000-01-01 to 2000-12-01) ~ 19:35:24 UTC
debug: ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
    0), nc)
debug: unlink(ncs0)
debug: nc_retry <- T
debug: nc_n_try <- 1
debug: n_max_retries
debug: while (nc_retry) {
    res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
        url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
            bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
        time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
    if (inherits(res, "try-error")) {
        err <- attr(res, "condition")
        msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
        nc_n_try <- nc_n_try + 1
        if (nc_n_try > n_max_retries) {
            stop(msg)
        }
        else {
            message(msg, "\nRETRYing...")
            Sys.sleep(1)
        }
    }
    else {
        nc_retry <- F
    }
}
debug: res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
    url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
        bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
    time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
debug: if (inherits(res, "try-error")) {
    err <- attr(res, "condition")
    msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
    nc_n_try <- nc_n_try + 1
    if (nc_n_try > n_max_retries) {
        stop(msg)
    }
    else {
        message(msg, "\nRETRYing...")
        Sys.sleep(1)
    }
} else {
    nc_retry <- F
}
debug: nc_retry <- F
debug: (while) nc_retry
debug: i_req <- i_req + 1
debug: (while) i_req <= n_reqs
debug: ncs <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size > 
    0), nc)
debug: r <- terra::rast(ncs)
debug: stopifnot(all(class(terra::time(r)) %in% c("POSIXct", "POSIXt")))
debug: idx <- dplyr::pull(dplyr::filter(dplyr::arrange(dplyr::tibble(idx = 1:terra::nlyr(r), 
    time = terra::time(r)), time), !duplicated(time)), idx)
debug: r <- terra::subset(r, idx)
debug: stopifnot(terra::crs(r, proj = T) == wgs84)
debug: if (mask_tif) r <- terra::mask(r, sf_zones)
debug: lyrs <- glue("{var}|{terra::time(r)}")
debug: if (length(dims_other) > 0 && !all(length(dims[dims_other]) == 
    1)) stop(glue("Other dimensions not yet supported: {paste(dims_other, collapse = ',')}"))
debug: names(r) <- lyrs
debug: if (!is.null(rast_tif)) {
    if (fs::file_exists(rast_tif)) {
        r_tmp_tif <- tempfile(fileext = ".tif")
        r_tmp <- c(rast(rast_tif), r)
        r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
        terra::writeRaster(r_tmp, r_tmp_tif)
        fs::file_delete(rast_tif)
        fs::file_move(r_tmp_tif, rast_tif)
        rm(r)
        rm(r_tmp)
    }
    else {
        terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
    }
    r <- terra::rast(rast_tif)
}
debug: if (fs::file_exists(rast_tif)) {
    r_tmp_tif <- tempfile(fileext = ".tif")
    r_tmp <- c(rast(rast_tif), r)
    r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
    terra::writeRaster(r_tmp, r_tmp_tif)
    fs::file_delete(rast_tif)
    fs::file_move(r_tmp_tif, rast_tif)
    rm(r)
    rm(r_tmp)
} else {
    terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
}
debug: terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
debug: r <- terra::rast(rast_tif)
debug: d_r <- mutate(tidyr::pivot_longer(sf::st_drop_geometry(sf::st_as_sf(terra::zonal(x = r, 
    z = terra::vect(dplyr::select(sf_zones, dplyr::all_of(fld_zones))), 
    fun = zonal_fun, exact = T, na.rm = T, as.polygons = T))), 
    cols = -dplyr::any_of(fld_zones), names_to = "lyr", values_to = zonal_fun), 
    time = readr::parse_datetime(str_replace(lyr, glue("{var}\\|(.*)"), 
        "\\1")))
debug: if (!is.null(zonal_csv)) write_csv(d_r, zonal_csv)
debug: write_csv(d_r, zonal_csv)
debug: if (!keep_nc) unlink(dir_nc, recursive = T)
debug: unlink(dir_nc, recursive = T)
debug: return(d_r)
Downloading 1 requests, up to 125 time slices each
Called from: extractr::ed_extract(ed, var = v, sf_zones = ply, bbox = bb, 
    mask_tif = F, rast_tif = glue("{dir_out}/{nms}/{yr}.tif"), 
    zonal_fun = "mean", zonal_csv = glue("{dir_out}/{nms}/{yr}.csv"), 
    dir_nc = glue("{dir_out}/{nms}/{yr}_nc"), keep_nc = F, n_max_vals_per_req = 1e+05, 
    time_min = time_min, time_max = time_max, verbose = T)
debug: while (i_req <= n_reqs) {
    i_t_beg <- (i_req - 1) * n_t_per_req + 1
    i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
    t_req <- times_todo[c(i_t_beg, i_t_end)]
    t_req_str <- format_ISO8601(t_req, usetz = "Z")
    if (verbose) 
        message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
    ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
        ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
        0), nc)
    unlink(ncs0)
    nc_retry <- T
    nc_n_try <- 1
    n_max_retries
    while (nc_retry) {
        res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
            url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
                bbox[["xmax"]]), latitude = c(bbox[["ymin"]], 
                bbox[["ymax"]]), time = t_req_str, fmt = "nc", 
            store = rerddap::disk(path = dir_nc)))
        if (inherits(res, "try-error")) {
            err <- attr(res, "condition")
            msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
            nc_n_try <- nc_n_try + 1
            if (nc_n_try > n_max_retries) {
                stop(msg)
            }
            else {
                message(msg, "\nRETRYing...")
                Sys.sleep(1)
            }
        }
        else {
            nc_retry <- F
        }
    }
    i_req <- i_req + 1
}
debug: i_t_beg <- (i_req - 1) * n_t_per_req + 1
debug: i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
debug: t_req <- times_todo[c(i_t_beg, i_t_end)]
debug: t_req_str <- format_ISO8601(t_req, usetz = "Z")
debug: if (verbose) message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
debug: message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
Fetching request 1 of 1 (2001-01-01 to 2001-12-01) ~ 19:35:27 UTC
debug: ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
    0), nc)
debug: unlink(ncs0)
debug: nc_retry <- T
debug: nc_n_try <- 1
debug: n_max_retries
debug: while (nc_retry) {
    res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
        url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
            bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
        time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
    if (inherits(res, "try-error")) {
        err <- attr(res, "condition")
        msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
        nc_n_try <- nc_n_try + 1
        if (nc_n_try > n_max_retries) {
            stop(msg)
        }
        else {
            message(msg, "\nRETRYing...")
            Sys.sleep(1)
        }
    }
    else {
        nc_retry <- F
    }
}
debug: res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
    url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
        bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
    time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
debug: if (inherits(res, "try-error")) {
    err <- attr(res, "condition")
    msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
    nc_n_try <- nc_n_try + 1
    if (nc_n_try > n_max_retries) {
        stop(msg)
    }
    else {
        message(msg, "\nRETRYing...")
        Sys.sleep(1)
    }
} else {
    nc_retry <- F
}
debug: nc_retry <- F
debug: (while) nc_retry
debug: i_req <- i_req + 1
debug: (while) i_req <= n_reqs
debug: ncs <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size > 
    0), nc)
debug: r <- terra::rast(ncs)
debug: stopifnot(all(class(terra::time(r)) %in% c("POSIXct", "POSIXt")))
debug: idx <- dplyr::pull(dplyr::filter(dplyr::arrange(dplyr::tibble(idx = 1:terra::nlyr(r), 
    time = terra::time(r)), time), !duplicated(time)), idx)
debug: r <- terra::subset(r, idx)
debug: stopifnot(terra::crs(r, proj = T) == wgs84)
debug: if (mask_tif) r <- terra::mask(r, sf_zones)
debug: lyrs <- glue("{var}|{terra::time(r)}")
debug: if (length(dims_other) > 0 && !all(length(dims[dims_other]) == 
    1)) stop(glue("Other dimensions not yet supported: {paste(dims_other, collapse = ',')}"))
debug: names(r) <- lyrs
debug: if (!is.null(rast_tif)) {
    if (fs::file_exists(rast_tif)) {
        r_tmp_tif <- tempfile(fileext = ".tif")
        r_tmp <- c(rast(rast_tif), r)
        r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
        terra::writeRaster(r_tmp, r_tmp_tif)
        fs::file_delete(rast_tif)
        fs::file_move(r_tmp_tif, rast_tif)
        rm(r)
        rm(r_tmp)
    }
    else {
        terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
    }
    r <- terra::rast(rast_tif)
}
debug: if (fs::file_exists(rast_tif)) {
    r_tmp_tif <- tempfile(fileext = ".tif")
    r_tmp <- c(rast(rast_tif), r)
    r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
    terra::writeRaster(r_tmp, r_tmp_tif)
    fs::file_delete(rast_tif)
    fs::file_move(r_tmp_tif, rast_tif)
    rm(r)
    rm(r_tmp)
} else {
    terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
}
debug: terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
debug: r <- terra::rast(rast_tif)
debug: d_r <- mutate(tidyr::pivot_longer(sf::st_drop_geometry(sf::st_as_sf(terra::zonal(x = r, 
    z = terra::vect(dplyr::select(sf_zones, dplyr::all_of(fld_zones))), 
    fun = zonal_fun, exact = T, na.rm = T, as.polygons = T))), 
    cols = -dplyr::any_of(fld_zones), names_to = "lyr", values_to = zonal_fun), 
    time = readr::parse_datetime(str_replace(lyr, glue("{var}\\|(.*)"), 
        "\\1")))
debug: if (!is.null(zonal_csv)) write_csv(d_r, zonal_csv)
debug: write_csv(d_r, zonal_csv)
debug: if (!keep_nc) unlink(dir_nc, recursive = T)
debug: unlink(dir_nc, recursive = T)
debug: return(d_r)
Downloading 1 requests, up to 125 time slices each
Called from: extractr::ed_extract(ed, var = v, sf_zones = ply, bbox = bb, 
    mask_tif = F, rast_tif = glue("{dir_out}/{nms}/{yr}.tif"), 
    zonal_fun = "mean", zonal_csv = glue("{dir_out}/{nms}/{yr}.csv"), 
    dir_nc = glue("{dir_out}/{nms}/{yr}_nc"), keep_nc = F, n_max_vals_per_req = 1e+05, 
    time_min = time_min, time_max = time_max, verbose = T)
debug: while (i_req <= n_reqs) {
    i_t_beg <- (i_req - 1) * n_t_per_req + 1
    i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
    t_req <- times_todo[c(i_t_beg, i_t_end)]
    t_req_str <- format_ISO8601(t_req, usetz = "Z")
    if (verbose) 
        message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
    ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
        ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
        0), nc)
    unlink(ncs0)
    nc_retry <- T
    nc_n_try <- 1
    n_max_retries
    while (nc_retry) {
        res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
            url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
                bbox[["xmax"]]), latitude = c(bbox[["ymin"]], 
                bbox[["ymax"]]), time = t_req_str, fmt = "nc", 
            store = rerddap::disk(path = dir_nc)))
        if (inherits(res, "try-error")) {
            err <- attr(res, "condition")
            msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
            nc_n_try <- nc_n_try + 1
            if (nc_n_try > n_max_retries) {
                stop(msg)
            }
            else {
                message(msg, "\nRETRYing...")
                Sys.sleep(1)
            }
        }
        else {
            nc_retry <- F
        }
    }
    i_req <- i_req + 1
}
debug: i_t_beg <- (i_req - 1) * n_t_per_req + 1
debug: i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
debug: t_req <- times_todo[c(i_t_beg, i_t_end)]
debug: t_req_str <- format_ISO8601(t_req, usetz = "Z")
debug: if (verbose) message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
debug: message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
Fetching request 1 of 1 (2002-01-01 to 2002-12-01) ~ 19:35:30 UTC
debug: ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
    0), nc)
debug: unlink(ncs0)
debug: nc_retry <- T
debug: nc_n_try <- 1
debug: n_max_retries
debug: while (nc_retry) {
    res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
        url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
            bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
        time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
    if (inherits(res, "try-error")) {
        err <- attr(res, "condition")
        msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
        nc_n_try <- nc_n_try + 1
        if (nc_n_try > n_max_retries) {
            stop(msg)
        }
        else {
            message(msg, "\nRETRYing...")
            Sys.sleep(1)
        }
    }
    else {
        nc_retry <- F
    }
}
debug: res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
    url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
        bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
    time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
debug: if (inherits(res, "try-error")) {
    err <- attr(res, "condition")
    msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
    nc_n_try <- nc_n_try + 1
    if (nc_n_try > n_max_retries) {
        stop(msg)
    }
    else {
        message(msg, "\nRETRYing...")
        Sys.sleep(1)
    }
} else {
    nc_retry <- F
}
debug: nc_retry <- F
debug: (while) nc_retry
debug: i_req <- i_req + 1
debug: (while) i_req <= n_reqs
debug: ncs <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size > 
    0), nc)
debug: r <- terra::rast(ncs)
debug: stopifnot(all(class(terra::time(r)) %in% c("POSIXct", "POSIXt")))
debug: idx <- dplyr::pull(dplyr::filter(dplyr::arrange(dplyr::tibble(idx = 1:terra::nlyr(r), 
    time = terra::time(r)), time), !duplicated(time)), idx)
debug: r <- terra::subset(r, idx)
debug: stopifnot(terra::crs(r, proj = T) == wgs84)
debug: if (mask_tif) r <- terra::mask(r, sf_zones)
debug: lyrs <- glue("{var}|{terra::time(r)}")
debug: if (length(dims_other) > 0 && !all(length(dims[dims_other]) == 
    1)) stop(glue("Other dimensions not yet supported: {paste(dims_other, collapse = ',')}"))
debug: names(r) <- lyrs
debug: if (!is.null(rast_tif)) {
    if (fs::file_exists(rast_tif)) {
        r_tmp_tif <- tempfile(fileext = ".tif")
        r_tmp <- c(rast(rast_tif), r)
        r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
        terra::writeRaster(r_tmp, r_tmp_tif)
        fs::file_delete(rast_tif)
        fs::file_move(r_tmp_tif, rast_tif)
        rm(r)
        rm(r_tmp)
    }
    else {
        terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
    }
    r <- terra::rast(rast_tif)
}
debug: if (fs::file_exists(rast_tif)) {
    r_tmp_tif <- tempfile(fileext = ".tif")
    r_tmp <- c(rast(rast_tif), r)
    r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
    terra::writeRaster(r_tmp, r_tmp_tif)
    fs::file_delete(rast_tif)
    fs::file_move(r_tmp_tif, rast_tif)
    rm(r)
    rm(r_tmp)
} else {
    terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
}
debug: terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
debug: r <- terra::rast(rast_tif)
debug: d_r <- mutate(tidyr::pivot_longer(sf::st_drop_geometry(sf::st_as_sf(terra::zonal(x = r, 
    z = terra::vect(dplyr::select(sf_zones, dplyr::all_of(fld_zones))), 
    fun = zonal_fun, exact = T, na.rm = T, as.polygons = T))), 
    cols = -dplyr::any_of(fld_zones), names_to = "lyr", values_to = zonal_fun), 
    time = readr::parse_datetime(str_replace(lyr, glue("{var}\\|(.*)"), 
        "\\1")))
debug: if (!is.null(zonal_csv)) write_csv(d_r, zonal_csv)
debug: write_csv(d_r, zonal_csv)
debug: if (!keep_nc) unlink(dir_nc, recursive = T)
debug: unlink(dir_nc, recursive = T)
debug: return(d_r)
Downloading 1 requests, up to 125 time slices each
Called from: extractr::ed_extract(ed, var = v, sf_zones = ply, bbox = bb, 
    mask_tif = F, rast_tif = glue("{dir_out}/{nms}/{yr}.tif"), 
    zonal_fun = "mean", zonal_csv = glue("{dir_out}/{nms}/{yr}.csv"), 
    dir_nc = glue("{dir_out}/{nms}/{yr}_nc"), keep_nc = F, n_max_vals_per_req = 1e+05, 
    time_min = time_min, time_max = time_max, verbose = T)
debug: while (i_req <= n_reqs) {
    i_t_beg <- (i_req - 1) * n_t_per_req + 1
    i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
    t_req <- times_todo[c(i_t_beg, i_t_end)]
    t_req_str <- format_ISO8601(t_req, usetz = "Z")
    if (verbose) 
        message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
    ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
        ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
        0), nc)
    unlink(ncs0)
    nc_retry <- T
    nc_n_try <- 1
    n_max_retries
    while (nc_retry) {
        res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
            url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
                bbox[["xmax"]]), latitude = c(bbox[["ymin"]], 
                bbox[["ymax"]]), time = t_req_str, fmt = "nc", 
            store = rerddap::disk(path = dir_nc)))
        if (inherits(res, "try-error")) {
            err <- attr(res, "condition")
            msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
            nc_n_try <- nc_n_try + 1
            if (nc_n_try > n_max_retries) {
                stop(msg)
            }
            else {
                message(msg, "\nRETRYing...")
                Sys.sleep(1)
            }
        }
        else {
            nc_retry <- F
        }
    }
    i_req <- i_req + 1
}
debug: i_t_beg <- (i_req - 1) * n_t_per_req + 1
debug: i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
debug: t_req <- times_todo[c(i_t_beg, i_t_end)]
debug: t_req_str <- format_ISO8601(t_req, usetz = "Z")
debug: if (verbose) message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
debug: message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
Fetching request 1 of 1 (2003-01-01 to 2003-12-01) ~ 19:35:33 UTC
debug: ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
    0), nc)
debug: unlink(ncs0)
debug: nc_retry <- T
debug: nc_n_try <- 1
debug: n_max_retries
debug: while (nc_retry) {
    res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
        url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
            bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
        time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
    if (inherits(res, "try-error")) {
        err <- attr(res, "condition")
        msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
        nc_n_try <- nc_n_try + 1
        if (nc_n_try > n_max_retries) {
            stop(msg)
        }
        else {
            message(msg, "\nRETRYing...")
            Sys.sleep(1)
        }
    }
    else {
        nc_retry <- F
    }
}
debug: res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
    url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
        bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
    time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
debug: if (inherits(res, "try-error")) {
    err <- attr(res, "condition")
    msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
    nc_n_try <- nc_n_try + 1
    if (nc_n_try > n_max_retries) {
        stop(msg)
    }
    else {
        message(msg, "\nRETRYing...")
        Sys.sleep(1)
    }
} else {
    nc_retry <- F
}
debug: nc_retry <- F
debug: (while) nc_retry
debug: i_req <- i_req + 1
debug: (while) i_req <= n_reqs
debug: ncs <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size > 
    0), nc)
debug: r <- terra::rast(ncs)
debug: stopifnot(all(class(terra::time(r)) %in% c("POSIXct", "POSIXt")))
debug: idx <- dplyr::pull(dplyr::filter(dplyr::arrange(dplyr::tibble(idx = 1:terra::nlyr(r), 
    time = terra::time(r)), time), !duplicated(time)), idx)
debug: r <- terra::subset(r, idx)
debug: stopifnot(terra::crs(r, proj = T) == wgs84)
debug: if (mask_tif) r <- terra::mask(r, sf_zones)
debug: lyrs <- glue("{var}|{terra::time(r)}")
debug: if (length(dims_other) > 0 && !all(length(dims[dims_other]) == 
    1)) stop(glue("Other dimensions not yet supported: {paste(dims_other, collapse = ',')}"))
debug: names(r) <- lyrs
debug: if (!is.null(rast_tif)) {
    if (fs::file_exists(rast_tif)) {
        r_tmp_tif <- tempfile(fileext = ".tif")
        r_tmp <- c(rast(rast_tif), r)
        r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
        terra::writeRaster(r_tmp, r_tmp_tif)
        fs::file_delete(rast_tif)
        fs::file_move(r_tmp_tif, rast_tif)
        rm(r)
        rm(r_tmp)
    }
    else {
        terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
    }
    r <- terra::rast(rast_tif)
}
debug: if (fs::file_exists(rast_tif)) {
    r_tmp_tif <- tempfile(fileext = ".tif")
    r_tmp <- c(rast(rast_tif), r)
    r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
    terra::writeRaster(r_tmp, r_tmp_tif)
    fs::file_delete(rast_tif)
    fs::file_move(r_tmp_tif, rast_tif)
    rm(r)
    rm(r_tmp)
} else {
    terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
}
debug: terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
debug: r <- terra::rast(rast_tif)
debug: d_r <- mutate(tidyr::pivot_longer(sf::st_drop_geometry(sf::st_as_sf(terra::zonal(x = r, 
    z = terra::vect(dplyr::select(sf_zones, dplyr::all_of(fld_zones))), 
    fun = zonal_fun, exact = T, na.rm = T, as.polygons = T))), 
    cols = -dplyr::any_of(fld_zones), names_to = "lyr", values_to = zonal_fun), 
    time = readr::parse_datetime(str_replace(lyr, glue("{var}\\|(.*)"), 
        "\\1")))
debug: if (!is.null(zonal_csv)) write_csv(d_r, zonal_csv)
debug: write_csv(d_r, zonal_csv)
debug: if (!keep_nc) unlink(dir_nc, recursive = T)
debug: unlink(dir_nc, recursive = T)
debug: return(d_r)
Downloading 1 requests, up to 125 time slices each
Called from: extractr::ed_extract(ed, var = v, sf_zones = ply, bbox = bb, 
    mask_tif = F, rast_tif = glue("{dir_out}/{nms}/{yr}.tif"), 
    zonal_fun = "mean", zonal_csv = glue("{dir_out}/{nms}/{yr}.csv"), 
    dir_nc = glue("{dir_out}/{nms}/{yr}_nc"), keep_nc = F, n_max_vals_per_req = 1e+05, 
    time_min = time_min, time_max = time_max, verbose = T)
debug: while (i_req <= n_reqs) {
    i_t_beg <- (i_req - 1) * n_t_per_req + 1
    i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
    t_req <- times_todo[c(i_t_beg, i_t_end)]
    t_req_str <- format_ISO8601(t_req, usetz = "Z")
    if (verbose) 
        message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
    ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
        ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
        0), nc)
    unlink(ncs0)
    nc_retry <- T
    nc_n_try <- 1
    n_max_retries
    while (nc_retry) {
        res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
            url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
                bbox[["xmax"]]), latitude = c(bbox[["ymin"]], 
                bbox[["ymax"]]), time = t_req_str, fmt = "nc", 
            store = rerddap::disk(path = dir_nc)))
        if (inherits(res, "try-error")) {
            err <- attr(res, "condition")
            msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
            nc_n_try <- nc_n_try + 1
            if (nc_n_try > n_max_retries) {
                stop(msg)
            }
            else {
                message(msg, "\nRETRYing...")
                Sys.sleep(1)
            }
        }
        else {
            nc_retry <- F
        }
    }
    i_req <- i_req + 1
}
debug: i_t_beg <- (i_req - 1) * n_t_per_req + 1
debug: i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
debug: t_req <- times_todo[c(i_t_beg, i_t_end)]
debug: t_req_str <- format_ISO8601(t_req, usetz = "Z")
debug: if (verbose) message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
debug: message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
Fetching request 1 of 1 (2004-01-01 to 2004-12-01) ~ 19:35:36 UTC
debug: ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
    0), nc)
debug: unlink(ncs0)
debug: nc_retry <- T
debug: nc_n_try <- 1
debug: n_max_retries
debug: while (nc_retry) {
    res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
        url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
            bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
        time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
    if (inherits(res, "try-error")) {
        err <- attr(res, "condition")
        msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
        nc_n_try <- nc_n_try + 1
        if (nc_n_try > n_max_retries) {
            stop(msg)
        }
        else {
            message(msg, "\nRETRYing...")
            Sys.sleep(1)
        }
    }
    else {
        nc_retry <- F
    }
}
debug: res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
    url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
        bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
    time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
debug: if (inherits(res, "try-error")) {
    err <- attr(res, "condition")
    msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
    nc_n_try <- nc_n_try + 1
    if (nc_n_try > n_max_retries) {
        stop(msg)
    }
    else {
        message(msg, "\nRETRYing...")
        Sys.sleep(1)
    }
} else {
    nc_retry <- F
}
debug: nc_retry <- F
debug: (while) nc_retry
debug: i_req <- i_req + 1
debug: (while) i_req <= n_reqs
debug: ncs <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size > 
    0), nc)
debug: r <- terra::rast(ncs)
debug: stopifnot(all(class(terra::time(r)) %in% c("POSIXct", "POSIXt")))
debug: idx <- dplyr::pull(dplyr::filter(dplyr::arrange(dplyr::tibble(idx = 1:terra::nlyr(r), 
    time = terra::time(r)), time), !duplicated(time)), idx)
debug: r <- terra::subset(r, idx)
debug: stopifnot(terra::crs(r, proj = T) == wgs84)
debug: if (mask_tif) r <- terra::mask(r, sf_zones)
debug: lyrs <- glue("{var}|{terra::time(r)}")
debug: if (length(dims_other) > 0 && !all(length(dims[dims_other]) == 
    1)) stop(glue("Other dimensions not yet supported: {paste(dims_other, collapse = ',')}"))
debug: names(r) <- lyrs
debug: if (!is.null(rast_tif)) {
    if (fs::file_exists(rast_tif)) {
        r_tmp_tif <- tempfile(fileext = ".tif")
        r_tmp <- c(rast(rast_tif), r)
        r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
        terra::writeRaster(r_tmp, r_tmp_tif)
        fs::file_delete(rast_tif)
        fs::file_move(r_tmp_tif, rast_tif)
        rm(r)
        rm(r_tmp)
    }
    else {
        terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
    }
    r <- terra::rast(rast_tif)
}
debug: if (fs::file_exists(rast_tif)) {
    r_tmp_tif <- tempfile(fileext = ".tif")
    r_tmp <- c(rast(rast_tif), r)
    r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
    terra::writeRaster(r_tmp, r_tmp_tif)
    fs::file_delete(rast_tif)
    fs::file_move(r_tmp_tif, rast_tif)
    rm(r)
    rm(r_tmp)
} else {
    terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
}
debug: terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
debug: r <- terra::rast(rast_tif)
debug: d_r <- mutate(tidyr::pivot_longer(sf::st_drop_geometry(sf::st_as_sf(terra::zonal(x = r, 
    z = terra::vect(dplyr::select(sf_zones, dplyr::all_of(fld_zones))), 
    fun = zonal_fun, exact = T, na.rm = T, as.polygons = T))), 
    cols = -dplyr::any_of(fld_zones), names_to = "lyr", values_to = zonal_fun), 
    time = readr::parse_datetime(str_replace(lyr, glue("{var}\\|(.*)"), 
        "\\1")))
debug: if (!is.null(zonal_csv)) write_csv(d_r, zonal_csv)
debug: write_csv(d_r, zonal_csv)
debug: if (!keep_nc) unlink(dir_nc, recursive = T)
debug: unlink(dir_nc, recursive = T)
debug: return(d_r)
Downloading 1 requests, up to 125 time slices each
Called from: extractr::ed_extract(ed, var = v, sf_zones = ply, bbox = bb, 
    mask_tif = F, rast_tif = glue("{dir_out}/{nms}/{yr}.tif"), 
    zonal_fun = "mean", zonal_csv = glue("{dir_out}/{nms}/{yr}.csv"), 
    dir_nc = glue("{dir_out}/{nms}/{yr}_nc"), keep_nc = F, n_max_vals_per_req = 1e+05, 
    time_min = time_min, time_max = time_max, verbose = T)
debug: while (i_req <= n_reqs) {
    i_t_beg <- (i_req - 1) * n_t_per_req + 1
    i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
    t_req <- times_todo[c(i_t_beg, i_t_end)]
    t_req_str <- format_ISO8601(t_req, usetz = "Z")
    if (verbose) 
        message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
    ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
        ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
        0), nc)
    unlink(ncs0)
    nc_retry <- T
    nc_n_try <- 1
    n_max_retries
    while (nc_retry) {
        res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
            url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
                bbox[["xmax"]]), latitude = c(bbox[["ymin"]], 
                bbox[["ymax"]]), time = t_req_str, fmt = "nc", 
            store = rerddap::disk(path = dir_nc)))
        if (inherits(res, "try-error")) {
            err <- attr(res, "condition")
            msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
            nc_n_try <- nc_n_try + 1
            if (nc_n_try > n_max_retries) {
                stop(msg)
            }
            else {
                message(msg, "\nRETRYing...")
                Sys.sleep(1)
            }
        }
        else {
            nc_retry <- F
        }
    }
    i_req <- i_req + 1
}
debug: i_t_beg <- (i_req - 1) * n_t_per_req + 1
debug: i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
debug: t_req <- times_todo[c(i_t_beg, i_t_end)]
debug: t_req_str <- format_ISO8601(t_req, usetz = "Z")
debug: if (verbose) message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
debug: message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
Fetching request 1 of 1 (2005-01-01 to 2005-12-01) ~ 19:35:38 UTC
debug: ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
    0), nc)
debug: unlink(ncs0)
debug: nc_retry <- T
debug: nc_n_try <- 1
debug: n_max_retries
debug: while (nc_retry) {
    res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
        url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
            bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
        time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
    if (inherits(res, "try-error")) {
        err <- attr(res, "condition")
        msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
        nc_n_try <- nc_n_try + 1
        if (nc_n_try > n_max_retries) {
            stop(msg)
        }
        else {
            message(msg, "\nRETRYing...")
            Sys.sleep(1)
        }
    }
    else {
        nc_retry <- F
    }
}
debug: res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
    url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
        bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
    time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
debug: if (inherits(res, "try-error")) {
    err <- attr(res, "condition")
    msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
    nc_n_try <- nc_n_try + 1
    if (nc_n_try > n_max_retries) {
        stop(msg)
    }
    else {
        message(msg, "\nRETRYing...")
        Sys.sleep(1)
    }
} else {
    nc_retry <- F
}
debug: nc_retry <- F
debug: (while) nc_retry
debug: i_req <- i_req + 1
debug: (while) i_req <= n_reqs
debug: ncs <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size > 
    0), nc)
debug: r <- terra::rast(ncs)
debug: stopifnot(all(class(terra::time(r)) %in% c("POSIXct", "POSIXt")))
debug: idx <- dplyr::pull(dplyr::filter(dplyr::arrange(dplyr::tibble(idx = 1:terra::nlyr(r), 
    time = terra::time(r)), time), !duplicated(time)), idx)
debug: r <- terra::subset(r, idx)
debug: stopifnot(terra::crs(r, proj = T) == wgs84)
debug: if (mask_tif) r <- terra::mask(r, sf_zones)
debug: lyrs <- glue("{var}|{terra::time(r)}")
debug: if (length(dims_other) > 0 && !all(length(dims[dims_other]) == 
    1)) stop(glue("Other dimensions not yet supported: {paste(dims_other, collapse = ',')}"))
debug: names(r) <- lyrs
debug: if (!is.null(rast_tif)) {
    if (fs::file_exists(rast_tif)) {
        r_tmp_tif <- tempfile(fileext = ".tif")
        r_tmp <- c(rast(rast_tif), r)
        r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
        terra::writeRaster(r_tmp, r_tmp_tif)
        fs::file_delete(rast_tif)
        fs::file_move(r_tmp_tif, rast_tif)
        rm(r)
        rm(r_tmp)
    }
    else {
        terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
    }
    r <- terra::rast(rast_tif)
}
debug: if (fs::file_exists(rast_tif)) {
    r_tmp_tif <- tempfile(fileext = ".tif")
    r_tmp <- c(rast(rast_tif), r)
    r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
    terra::writeRaster(r_tmp, r_tmp_tif)
    fs::file_delete(rast_tif)
    fs::file_move(r_tmp_tif, rast_tif)
    rm(r)
    rm(r_tmp)
} else {
    terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
}
debug: terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
debug: r <- terra::rast(rast_tif)
debug: d_r <- mutate(tidyr::pivot_longer(sf::st_drop_geometry(sf::st_as_sf(terra::zonal(x = r, 
    z = terra::vect(dplyr::select(sf_zones, dplyr::all_of(fld_zones))), 
    fun = zonal_fun, exact = T, na.rm = T, as.polygons = T))), 
    cols = -dplyr::any_of(fld_zones), names_to = "lyr", values_to = zonal_fun), 
    time = readr::parse_datetime(str_replace(lyr, glue("{var}\\|(.*)"), 
        "\\1")))
debug: if (!is.null(zonal_csv)) write_csv(d_r, zonal_csv)
debug: write_csv(d_r, zonal_csv)
debug: if (!keep_nc) unlink(dir_nc, recursive = T)
debug: unlink(dir_nc, recursive = T)
debug: return(d_r)
Downloading 1 requests, up to 125 time slices each
Called from: extractr::ed_extract(ed, var = v, sf_zones = ply, bbox = bb, 
    mask_tif = F, rast_tif = glue("{dir_out}/{nms}/{yr}.tif"), 
    zonal_fun = "mean", zonal_csv = glue("{dir_out}/{nms}/{yr}.csv"), 
    dir_nc = glue("{dir_out}/{nms}/{yr}_nc"), keep_nc = F, n_max_vals_per_req = 1e+05, 
    time_min = time_min, time_max = time_max, verbose = T)
debug: while (i_req <= n_reqs) {
    i_t_beg <- (i_req - 1) * n_t_per_req + 1
    i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
    t_req <- times_todo[c(i_t_beg, i_t_end)]
    t_req_str <- format_ISO8601(t_req, usetz = "Z")
    if (verbose) 
        message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
    ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
        ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
        0), nc)
    unlink(ncs0)
    nc_retry <- T
    nc_n_try <- 1
    n_max_retries
    while (nc_retry) {
        res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
            url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
                bbox[["xmax"]]), latitude = c(bbox[["ymin"]], 
                bbox[["ymax"]]), time = t_req_str, fmt = "nc", 
            store = rerddap::disk(path = dir_nc)))
        if (inherits(res, "try-error")) {
            err <- attr(res, "condition")
            msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
            nc_n_try <- nc_n_try + 1
            if (nc_n_try > n_max_retries) {
                stop(msg)
            }
            else {
                message(msg, "\nRETRYing...")
                Sys.sleep(1)
            }
        }
        else {
            nc_retry <- F
        }
    }
    i_req <- i_req + 1
}
debug: i_t_beg <- (i_req - 1) * n_t_per_req + 1
debug: i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
debug: t_req <- times_todo[c(i_t_beg, i_t_end)]
debug: t_req_str <- format_ISO8601(t_req, usetz = "Z")
debug: if (verbose) message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
debug: message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
Fetching request 1 of 1 (2006-01-01 to 2006-12-01) ~ 19:35:41 UTC
debug: ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
    0), nc)
debug: unlink(ncs0)
debug: nc_retry <- T
debug: nc_n_try <- 1
debug: n_max_retries
debug: while (nc_retry) {
    res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
        url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
            bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
        time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
    if (inherits(res, "try-error")) {
        err <- attr(res, "condition")
        msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
        nc_n_try <- nc_n_try + 1
        if (nc_n_try > n_max_retries) {
            stop(msg)
        }
        else {
            message(msg, "\nRETRYing...")
            Sys.sleep(1)
        }
    }
    else {
        nc_retry <- F
    }
}
debug: res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
    url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
        bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
    time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
debug: if (inherits(res, "try-error")) {
    err <- attr(res, "condition")
    msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
    nc_n_try <- nc_n_try + 1
    if (nc_n_try > n_max_retries) {
        stop(msg)
    }
    else {
        message(msg, "\nRETRYing...")
        Sys.sleep(1)
    }
} else {
    nc_retry <- F
}
debug: nc_retry <- F
debug: (while) nc_retry
debug: i_req <- i_req + 1
debug: (while) i_req <= n_reqs
debug: ncs <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size > 
    0), nc)
debug: r <- terra::rast(ncs)
debug: stopifnot(all(class(terra::time(r)) %in% c("POSIXct", "POSIXt")))
debug: idx <- dplyr::pull(dplyr::filter(dplyr::arrange(dplyr::tibble(idx = 1:terra::nlyr(r), 
    time = terra::time(r)), time), !duplicated(time)), idx)
debug: r <- terra::subset(r, idx)
debug: stopifnot(terra::crs(r, proj = T) == wgs84)
debug: if (mask_tif) r <- terra::mask(r, sf_zones)
debug: lyrs <- glue("{var}|{terra::time(r)}")
debug: if (length(dims_other) > 0 && !all(length(dims[dims_other]) == 
    1)) stop(glue("Other dimensions not yet supported: {paste(dims_other, collapse = ',')}"))
debug: names(r) <- lyrs
debug: if (!is.null(rast_tif)) {
    if (fs::file_exists(rast_tif)) {
        r_tmp_tif <- tempfile(fileext = ".tif")
        r_tmp <- c(rast(rast_tif), r)
        r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
        terra::writeRaster(r_tmp, r_tmp_tif)
        fs::file_delete(rast_tif)
        fs::file_move(r_tmp_tif, rast_tif)
        rm(r)
        rm(r_tmp)
    }
    else {
        terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
    }
    r <- terra::rast(rast_tif)
}
debug: if (fs::file_exists(rast_tif)) {
    r_tmp_tif <- tempfile(fileext = ".tif")
    r_tmp <- c(rast(rast_tif), r)
    r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
    terra::writeRaster(r_tmp, r_tmp_tif)
    fs::file_delete(rast_tif)
    fs::file_move(r_tmp_tif, rast_tif)
    rm(r)
    rm(r_tmp)
} else {
    terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
}
debug: terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
debug: r <- terra::rast(rast_tif)
debug: d_r <- mutate(tidyr::pivot_longer(sf::st_drop_geometry(sf::st_as_sf(terra::zonal(x = r, 
    z = terra::vect(dplyr::select(sf_zones, dplyr::all_of(fld_zones))), 
    fun = zonal_fun, exact = T, na.rm = T, as.polygons = T))), 
    cols = -dplyr::any_of(fld_zones), names_to = "lyr", values_to = zonal_fun), 
    time = readr::parse_datetime(str_replace(lyr, glue("{var}\\|(.*)"), 
        "\\1")))
debug: if (!is.null(zonal_csv)) write_csv(d_r, zonal_csv)
debug: write_csv(d_r, zonal_csv)
debug: if (!keep_nc) unlink(dir_nc, recursive = T)
debug: unlink(dir_nc, recursive = T)
debug: return(d_r)
Downloading 1 requests, up to 125 time slices each
Called from: extractr::ed_extract(ed, var = v, sf_zones = ply, bbox = bb, 
    mask_tif = F, rast_tif = glue("{dir_out}/{nms}/{yr}.tif"), 
    zonal_fun = "mean", zonal_csv = glue("{dir_out}/{nms}/{yr}.csv"), 
    dir_nc = glue("{dir_out}/{nms}/{yr}_nc"), keep_nc = F, n_max_vals_per_req = 1e+05, 
    time_min = time_min, time_max = time_max, verbose = T)
debug: while (i_req <= n_reqs) {
    i_t_beg <- (i_req - 1) * n_t_per_req + 1
    i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
    t_req <- times_todo[c(i_t_beg, i_t_end)]
    t_req_str <- format_ISO8601(t_req, usetz = "Z")
    if (verbose) 
        message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
    ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
        ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
        0), nc)
    unlink(ncs0)
    nc_retry <- T
    nc_n_try <- 1
    n_max_retries
    while (nc_retry) {
        res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
            url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
                bbox[["xmax"]]), latitude = c(bbox[["ymin"]], 
                bbox[["ymax"]]), time = t_req_str, fmt = "nc", 
            store = rerddap::disk(path = dir_nc)))
        if (inherits(res, "try-error")) {
            err <- attr(res, "condition")
            msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
            nc_n_try <- nc_n_try + 1
            if (nc_n_try > n_max_retries) {
                stop(msg)
            }
            else {
                message(msg, "\nRETRYing...")
                Sys.sleep(1)
            }
        }
        else {
            nc_retry <- F
        }
    }
    i_req <- i_req + 1
}
debug: i_t_beg <- (i_req - 1) * n_t_per_req + 1
debug: i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
debug: t_req <- times_todo[c(i_t_beg, i_t_end)]
debug: t_req_str <- format_ISO8601(t_req, usetz = "Z")
debug: if (verbose) message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
debug: message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
Fetching request 1 of 1 (2007-01-01 to 2007-12-01) ~ 19:35:44 UTC
debug: ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
    0), nc)
debug: unlink(ncs0)
debug: nc_retry <- T
debug: nc_n_try <- 1
debug: n_max_retries
debug: while (nc_retry) {
    res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
        url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
            bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
        time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
    if (inherits(res, "try-error")) {
        err <- attr(res, "condition")
        msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
        nc_n_try <- nc_n_try + 1
        if (nc_n_try > n_max_retries) {
            stop(msg)
        }
        else {
            message(msg, "\nRETRYing...")
            Sys.sleep(1)
        }
    }
    else {
        nc_retry <- F
    }
}
debug: res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
    url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
        bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
    time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
debug: if (inherits(res, "try-error")) {
    err <- attr(res, "condition")
    msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
    nc_n_try <- nc_n_try + 1
    if (nc_n_try > n_max_retries) {
        stop(msg)
    }
    else {
        message(msg, "\nRETRYing...")
        Sys.sleep(1)
    }
} else {
    nc_retry <- F
}
debug: nc_retry <- F
debug: (while) nc_retry
debug: i_req <- i_req + 1
debug: (while) i_req <= n_reqs
debug: ncs <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size > 
    0), nc)
debug: r <- terra::rast(ncs)
debug: stopifnot(all(class(terra::time(r)) %in% c("POSIXct", "POSIXt")))
debug: idx <- dplyr::pull(dplyr::filter(dplyr::arrange(dplyr::tibble(idx = 1:terra::nlyr(r), 
    time = terra::time(r)), time), !duplicated(time)), idx)
debug: r <- terra::subset(r, idx)
debug: stopifnot(terra::crs(r, proj = T) == wgs84)
debug: if (mask_tif) r <- terra::mask(r, sf_zones)
debug: lyrs <- glue("{var}|{terra::time(r)}")
debug: if (length(dims_other) > 0 && !all(length(dims[dims_other]) == 
    1)) stop(glue("Other dimensions not yet supported: {paste(dims_other, collapse = ',')}"))
debug: names(r) <- lyrs
debug: if (!is.null(rast_tif)) {
    if (fs::file_exists(rast_tif)) {
        r_tmp_tif <- tempfile(fileext = ".tif")
        r_tmp <- c(rast(rast_tif), r)
        r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
        terra::writeRaster(r_tmp, r_tmp_tif)
        fs::file_delete(rast_tif)
        fs::file_move(r_tmp_tif, rast_tif)
        rm(r)
        rm(r_tmp)
    }
    else {
        terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
    }
    r <- terra::rast(rast_tif)
}
debug: if (fs::file_exists(rast_tif)) {
    r_tmp_tif <- tempfile(fileext = ".tif")
    r_tmp <- c(rast(rast_tif), r)
    r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
    terra::writeRaster(r_tmp, r_tmp_tif)
    fs::file_delete(rast_tif)
    fs::file_move(r_tmp_tif, rast_tif)
    rm(r)
    rm(r_tmp)
} else {
    terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
}
debug: terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
debug: r <- terra::rast(rast_tif)
debug: d_r <- mutate(tidyr::pivot_longer(sf::st_drop_geometry(sf::st_as_sf(terra::zonal(x = r, 
    z = terra::vect(dplyr::select(sf_zones, dplyr::all_of(fld_zones))), 
    fun = zonal_fun, exact = T, na.rm = T, as.polygons = T))), 
    cols = -dplyr::any_of(fld_zones), names_to = "lyr", values_to = zonal_fun), 
    time = readr::parse_datetime(str_replace(lyr, glue("{var}\\|(.*)"), 
        "\\1")))
debug: if (!is.null(zonal_csv)) write_csv(d_r, zonal_csv)
debug: write_csv(d_r, zonal_csv)
debug: if (!keep_nc) unlink(dir_nc, recursive = T)
debug: unlink(dir_nc, recursive = T)
debug: return(d_r)
Downloading 1 requests, up to 125 time slices each
Called from: extractr::ed_extract(ed, var = v, sf_zones = ply, bbox = bb, 
    mask_tif = F, rast_tif = glue("{dir_out}/{nms}/{yr}.tif"), 
    zonal_fun = "mean", zonal_csv = glue("{dir_out}/{nms}/{yr}.csv"), 
    dir_nc = glue("{dir_out}/{nms}/{yr}_nc"), keep_nc = F, n_max_vals_per_req = 1e+05, 
    time_min = time_min, time_max = time_max, verbose = T)
debug: while (i_req <= n_reqs) {
    i_t_beg <- (i_req - 1) * n_t_per_req + 1
    i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
    t_req <- times_todo[c(i_t_beg, i_t_end)]
    t_req_str <- format_ISO8601(t_req, usetz = "Z")
    if (verbose) 
        message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
    ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
        ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
        0), nc)
    unlink(ncs0)
    nc_retry <- T
    nc_n_try <- 1
    n_max_retries
    while (nc_retry) {
        res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
            url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
                bbox[["xmax"]]), latitude = c(bbox[["ymin"]], 
                bbox[["ymax"]]), time = t_req_str, fmt = "nc", 
            store = rerddap::disk(path = dir_nc)))
        if (inherits(res, "try-error")) {
            err <- attr(res, "condition")
            msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
            nc_n_try <- nc_n_try + 1
            if (nc_n_try > n_max_retries) {
                stop(msg)
            }
            else {
                message(msg, "\nRETRYing...")
                Sys.sleep(1)
            }
        }
        else {
            nc_retry <- F
        }
    }
    i_req <- i_req + 1
}
debug: i_t_beg <- (i_req - 1) * n_t_per_req + 1
debug: i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
debug: t_req <- times_todo[c(i_t_beg, i_t_end)]
debug: t_req_str <- format_ISO8601(t_req, usetz = "Z")
debug: if (verbose) message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
debug: message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
Fetching request 1 of 1 (2008-01-01 to 2008-12-01) ~ 19:35:48 UTC
debug: ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
    0), nc)
debug: unlink(ncs0)
debug: nc_retry <- T
debug: nc_n_try <- 1
debug: n_max_retries
debug: while (nc_retry) {
    res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
        url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
            bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
        time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
    if (inherits(res, "try-error")) {
        err <- attr(res, "condition")
        msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
        nc_n_try <- nc_n_try + 1
        if (nc_n_try > n_max_retries) {
            stop(msg)
        }
        else {
            message(msg, "\nRETRYing...")
            Sys.sleep(1)
        }
    }
    else {
        nc_retry <- F
    }
}
debug: res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
    url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
        bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
    time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
debug: if (inherits(res, "try-error")) {
    err <- attr(res, "condition")
    msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
    nc_n_try <- nc_n_try + 1
    if (nc_n_try > n_max_retries) {
        stop(msg)
    }
    else {
        message(msg, "\nRETRYing...")
        Sys.sleep(1)
    }
} else {
    nc_retry <- F
}
debug: nc_retry <- F
debug: (while) nc_retry
debug: i_req <- i_req + 1
debug: (while) i_req <= n_reqs
debug: ncs <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size > 
    0), nc)
debug: r <- terra::rast(ncs)
debug: stopifnot(all(class(terra::time(r)) %in% c("POSIXct", "POSIXt")))
debug: idx <- dplyr::pull(dplyr::filter(dplyr::arrange(dplyr::tibble(idx = 1:terra::nlyr(r), 
    time = terra::time(r)), time), !duplicated(time)), idx)
debug: r <- terra::subset(r, idx)
debug: stopifnot(terra::crs(r, proj = T) == wgs84)
debug: if (mask_tif) r <- terra::mask(r, sf_zones)
debug: lyrs <- glue("{var}|{terra::time(r)}")
debug: if (length(dims_other) > 0 && !all(length(dims[dims_other]) == 
    1)) stop(glue("Other dimensions not yet supported: {paste(dims_other, collapse = ',')}"))
debug: names(r) <- lyrs
debug: if (!is.null(rast_tif)) {
    if (fs::file_exists(rast_tif)) {
        r_tmp_tif <- tempfile(fileext = ".tif")
        r_tmp <- c(rast(rast_tif), r)
        r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
        terra::writeRaster(r_tmp, r_tmp_tif)
        fs::file_delete(rast_tif)
        fs::file_move(r_tmp_tif, rast_tif)
        rm(r)
        rm(r_tmp)
    }
    else {
        terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
    }
    r <- terra::rast(rast_tif)
}
debug: if (fs::file_exists(rast_tif)) {
    r_tmp_tif <- tempfile(fileext = ".tif")
    r_tmp <- c(rast(rast_tif), r)
    r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
    terra::writeRaster(r_tmp, r_tmp_tif)
    fs::file_delete(rast_tif)
    fs::file_move(r_tmp_tif, rast_tif)
    rm(r)
    rm(r_tmp)
} else {
    terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
}
debug: terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
debug: r <- terra::rast(rast_tif)
debug: d_r <- mutate(tidyr::pivot_longer(sf::st_drop_geometry(sf::st_as_sf(terra::zonal(x = r, 
    z = terra::vect(dplyr::select(sf_zones, dplyr::all_of(fld_zones))), 
    fun = zonal_fun, exact = T, na.rm = T, as.polygons = T))), 
    cols = -dplyr::any_of(fld_zones), names_to = "lyr", values_to = zonal_fun), 
    time = readr::parse_datetime(str_replace(lyr, glue("{var}\\|(.*)"), 
        "\\1")))
debug: if (!is.null(zonal_csv)) write_csv(d_r, zonal_csv)
debug: write_csv(d_r, zonal_csv)
debug: if (!keep_nc) unlink(dir_nc, recursive = T)
debug: unlink(dir_nc, recursive = T)
debug: return(d_r)
Downloading 1 requests, up to 125 time slices each
Called from: extractr::ed_extract(ed, var = v, sf_zones = ply, bbox = bb, 
    mask_tif = F, rast_tif = glue("{dir_out}/{nms}/{yr}.tif"), 
    zonal_fun = "mean", zonal_csv = glue("{dir_out}/{nms}/{yr}.csv"), 
    dir_nc = glue("{dir_out}/{nms}/{yr}_nc"), keep_nc = F, n_max_vals_per_req = 1e+05, 
    time_min = time_min, time_max = time_max, verbose = T)
debug: while (i_req <= n_reqs) {
    i_t_beg <- (i_req - 1) * n_t_per_req + 1
    i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
    t_req <- times_todo[c(i_t_beg, i_t_end)]
    t_req_str <- format_ISO8601(t_req, usetz = "Z")
    if (verbose) 
        message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
    ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
        ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
        0), nc)
    unlink(ncs0)
    nc_retry <- T
    nc_n_try <- 1
    n_max_retries
    while (nc_retry) {
        res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
            url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
                bbox[["xmax"]]), latitude = c(bbox[["ymin"]], 
                bbox[["ymax"]]), time = t_req_str, fmt = "nc", 
            store = rerddap::disk(path = dir_nc)))
        if (inherits(res, "try-error")) {
            err <- attr(res, "condition")
            msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
            nc_n_try <- nc_n_try + 1
            if (nc_n_try > n_max_retries) {
                stop(msg)
            }
            else {
                message(msg, "\nRETRYing...")
                Sys.sleep(1)
            }
        }
        else {
            nc_retry <- F
        }
    }
    i_req <- i_req + 1
}
debug: i_t_beg <- (i_req - 1) * n_t_per_req + 1
debug: i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
debug: t_req <- times_todo[c(i_t_beg, i_t_end)]
debug: t_req_str <- format_ISO8601(t_req, usetz = "Z")
debug: if (verbose) message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
debug: message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
Fetching request 1 of 1 (2009-01-01 to 2009-12-01) ~ 19:35:50 UTC
debug: ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
    0), nc)
debug: unlink(ncs0)
debug: nc_retry <- T
debug: nc_n_try <- 1
debug: n_max_retries
debug: while (nc_retry) {
    res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
        url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
            bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
        time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
    if (inherits(res, "try-error")) {
        err <- attr(res, "condition")
        msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
        nc_n_try <- nc_n_try + 1
        if (nc_n_try > n_max_retries) {
            stop(msg)
        }
        else {
            message(msg, "\nRETRYing...")
            Sys.sleep(1)
        }
    }
    else {
        nc_retry <- F
    }
}
debug: res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
    url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
        bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
    time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
debug: if (inherits(res, "try-error")) {
    err <- attr(res, "condition")
    msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
    nc_n_try <- nc_n_try + 1
    if (nc_n_try > n_max_retries) {
        stop(msg)
    }
    else {
        message(msg, "\nRETRYing...")
        Sys.sleep(1)
    }
} else {
    nc_retry <- F
}
debug: nc_retry <- F
debug: (while) nc_retry
debug: i_req <- i_req + 1
debug: (while) i_req <= n_reqs
debug: ncs <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size > 
    0), nc)
debug: r <- terra::rast(ncs)
debug: stopifnot(all(class(terra::time(r)) %in% c("POSIXct", "POSIXt")))
debug: idx <- dplyr::pull(dplyr::filter(dplyr::arrange(dplyr::tibble(idx = 1:terra::nlyr(r), 
    time = terra::time(r)), time), !duplicated(time)), idx)
debug: r <- terra::subset(r, idx)
debug: stopifnot(terra::crs(r, proj = T) == wgs84)
debug: if (mask_tif) r <- terra::mask(r, sf_zones)
debug: lyrs <- glue("{var}|{terra::time(r)}")
debug: if (length(dims_other) > 0 && !all(length(dims[dims_other]) == 
    1)) stop(glue("Other dimensions not yet supported: {paste(dims_other, collapse = ',')}"))
debug: names(r) <- lyrs
debug: if (!is.null(rast_tif)) {
    if (fs::file_exists(rast_tif)) {
        r_tmp_tif <- tempfile(fileext = ".tif")
        r_tmp <- c(rast(rast_tif), r)
        r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
        terra::writeRaster(r_tmp, r_tmp_tif)
        fs::file_delete(rast_tif)
        fs::file_move(r_tmp_tif, rast_tif)
        rm(r)
        rm(r_tmp)
    }
    else {
        terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
    }
    r <- terra::rast(rast_tif)
}
debug: if (fs::file_exists(rast_tif)) {
    r_tmp_tif <- tempfile(fileext = ".tif")
    r_tmp <- c(rast(rast_tif), r)
    r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
    terra::writeRaster(r_tmp, r_tmp_tif)
    fs::file_delete(rast_tif)
    fs::file_move(r_tmp_tif, rast_tif)
    rm(r)
    rm(r_tmp)
} else {
    terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
}
debug: terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
debug: r <- terra::rast(rast_tif)
debug: d_r <- mutate(tidyr::pivot_longer(sf::st_drop_geometry(sf::st_as_sf(terra::zonal(x = r, 
    z = terra::vect(dplyr::select(sf_zones, dplyr::all_of(fld_zones))), 
    fun = zonal_fun, exact = T, na.rm = T, as.polygons = T))), 
    cols = -dplyr::any_of(fld_zones), names_to = "lyr", values_to = zonal_fun), 
    time = readr::parse_datetime(str_replace(lyr, glue("{var}\\|(.*)"), 
        "\\1")))
debug: if (!is.null(zonal_csv)) write_csv(d_r, zonal_csv)
debug: write_csv(d_r, zonal_csv)
debug: if (!keep_nc) unlink(dir_nc, recursive = T)
debug: unlink(dir_nc, recursive = T)
debug: return(d_r)
Downloading 1 requests, up to 125 time slices each
Called from: extractr::ed_extract(ed, var = v, sf_zones = ply, bbox = bb, 
    mask_tif = F, rast_tif = glue("{dir_out}/{nms}/{yr}.tif"), 
    zonal_fun = "mean", zonal_csv = glue("{dir_out}/{nms}/{yr}.csv"), 
    dir_nc = glue("{dir_out}/{nms}/{yr}_nc"), keep_nc = F, n_max_vals_per_req = 1e+05, 
    time_min = time_min, time_max = time_max, verbose = T)
debug: while (i_req <= n_reqs) {
    i_t_beg <- (i_req - 1) * n_t_per_req + 1
    i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
    t_req <- times_todo[c(i_t_beg, i_t_end)]
    t_req_str <- format_ISO8601(t_req, usetz = "Z")
    if (verbose) 
        message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
    ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
        ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
        0), nc)
    unlink(ncs0)
    nc_retry <- T
    nc_n_try <- 1
    n_max_retries
    while (nc_retry) {
        res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
            url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
                bbox[["xmax"]]), latitude = c(bbox[["ymin"]], 
                bbox[["ymax"]]), time = t_req_str, fmt = "nc", 
            store = rerddap::disk(path = dir_nc)))
        if (inherits(res, "try-error")) {
            err <- attr(res, "condition")
            msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
            nc_n_try <- nc_n_try + 1
            if (nc_n_try > n_max_retries) {
                stop(msg)
            }
            else {
                message(msg, "\nRETRYing...")
                Sys.sleep(1)
            }
        }
        else {
            nc_retry <- F
        }
    }
    i_req <- i_req + 1
}
debug: i_t_beg <- (i_req - 1) * n_t_per_req + 1
debug: i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
debug: t_req <- times_todo[c(i_t_beg, i_t_end)]
debug: t_req_str <- format_ISO8601(t_req, usetz = "Z")
debug: if (verbose) message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
debug: message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
Fetching request 1 of 1 (2010-01-01 to 2010-12-01) ~ 19:35:53 UTC
debug: ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
    0), nc)
debug: unlink(ncs0)
debug: nc_retry <- T
debug: nc_n_try <- 1
debug: n_max_retries
debug: while (nc_retry) {
    res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
        url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
            bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
        time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
    if (inherits(res, "try-error")) {
        err <- attr(res, "condition")
        msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
        nc_n_try <- nc_n_try + 1
        if (nc_n_try > n_max_retries) {
            stop(msg)
        }
        else {
            message(msg, "\nRETRYing...")
            Sys.sleep(1)
        }
    }
    else {
        nc_retry <- F
    }
}
debug: res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
    url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
        bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
    time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
debug: if (inherits(res, "try-error")) {
    err <- attr(res, "condition")
    msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
    nc_n_try <- nc_n_try + 1
    if (nc_n_try > n_max_retries) {
        stop(msg)
    }
    else {
        message(msg, "\nRETRYing...")
        Sys.sleep(1)
    }
} else {
    nc_retry <- F
}
debug: nc_retry <- F
debug: (while) nc_retry
debug: i_req <- i_req + 1
debug: (while) i_req <= n_reqs
debug: ncs <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size > 
    0), nc)
debug: r <- terra::rast(ncs)
debug: stopifnot(all(class(terra::time(r)) %in% c("POSIXct", "POSIXt")))
debug: idx <- dplyr::pull(dplyr::filter(dplyr::arrange(dplyr::tibble(idx = 1:terra::nlyr(r), 
    time = terra::time(r)), time), !duplicated(time)), idx)
debug: r <- terra::subset(r, idx)
debug: stopifnot(terra::crs(r, proj = T) == wgs84)
debug: if (mask_tif) r <- terra::mask(r, sf_zones)
debug: lyrs <- glue("{var}|{terra::time(r)}")
debug: if (length(dims_other) > 0 && !all(length(dims[dims_other]) == 
    1)) stop(glue("Other dimensions not yet supported: {paste(dims_other, collapse = ',')}"))
debug: names(r) <- lyrs
debug: if (!is.null(rast_tif)) {
    if (fs::file_exists(rast_tif)) {
        r_tmp_tif <- tempfile(fileext = ".tif")
        r_tmp <- c(rast(rast_tif), r)
        r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
        terra::writeRaster(r_tmp, r_tmp_tif)
        fs::file_delete(rast_tif)
        fs::file_move(r_tmp_tif, rast_tif)
        rm(r)
        rm(r_tmp)
    }
    else {
        terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
    }
    r <- terra::rast(rast_tif)
}
debug: if (fs::file_exists(rast_tif)) {
    r_tmp_tif <- tempfile(fileext = ".tif")
    r_tmp <- c(rast(rast_tif), r)
    r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
    terra::writeRaster(r_tmp, r_tmp_tif)
    fs::file_delete(rast_tif)
    fs::file_move(r_tmp_tif, rast_tif)
    rm(r)
    rm(r_tmp)
} else {
    terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
}
debug: terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
debug: r <- terra::rast(rast_tif)
debug: d_r <- mutate(tidyr::pivot_longer(sf::st_drop_geometry(sf::st_as_sf(terra::zonal(x = r, 
    z = terra::vect(dplyr::select(sf_zones, dplyr::all_of(fld_zones))), 
    fun = zonal_fun, exact = T, na.rm = T, as.polygons = T))), 
    cols = -dplyr::any_of(fld_zones), names_to = "lyr", values_to = zonal_fun), 
    time = readr::parse_datetime(str_replace(lyr, glue("{var}\\|(.*)"), 
        "\\1")))
debug: if (!is.null(zonal_csv)) write_csv(d_r, zonal_csv)
debug: write_csv(d_r, zonal_csv)
debug: if (!keep_nc) unlink(dir_nc, recursive = T)
debug: unlink(dir_nc, recursive = T)
debug: return(d_r)
Downloading 1 requests, up to 125 time slices each
Called from: extractr::ed_extract(ed, var = v, sf_zones = ply, bbox = bb, 
    mask_tif = F, rast_tif = glue("{dir_out}/{nms}/{yr}.tif"), 
    zonal_fun = "mean", zonal_csv = glue("{dir_out}/{nms}/{yr}.csv"), 
    dir_nc = glue("{dir_out}/{nms}/{yr}_nc"), keep_nc = F, n_max_vals_per_req = 1e+05, 
    time_min = time_min, time_max = time_max, verbose = T)
debug: while (i_req <= n_reqs) {
    i_t_beg <- (i_req - 1) * n_t_per_req + 1
    i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
    t_req <- times_todo[c(i_t_beg, i_t_end)]
    t_req_str <- format_ISO8601(t_req, usetz = "Z")
    if (verbose) 
        message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
    ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
        ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
        0), nc)
    unlink(ncs0)
    nc_retry <- T
    nc_n_try <- 1
    n_max_retries
    while (nc_retry) {
        res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
            url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
                bbox[["xmax"]]), latitude = c(bbox[["ymin"]], 
                bbox[["ymax"]]), time = t_req_str, fmt = "nc", 
            store = rerddap::disk(path = dir_nc)))
        if (inherits(res, "try-error")) {
            err <- attr(res, "condition")
            msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
            nc_n_try <- nc_n_try + 1
            if (nc_n_try > n_max_retries) {
                stop(msg)
            }
            else {
                message(msg, "\nRETRYing...")
                Sys.sleep(1)
            }
        }
        else {
            nc_retry <- F
        }
    }
    i_req <- i_req + 1
}
debug: i_t_beg <- (i_req - 1) * n_t_per_req + 1
debug: i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
debug: t_req <- times_todo[c(i_t_beg, i_t_end)]
debug: t_req_str <- format_ISO8601(t_req, usetz = "Z")
debug: if (verbose) message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
debug: message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
Fetching request 1 of 1 (2011-01-01 to 2011-12-01) ~ 19:35:56 UTC
debug: ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
    0), nc)
debug: unlink(ncs0)
debug: nc_retry <- T
debug: nc_n_try <- 1
debug: n_max_retries
debug: while (nc_retry) {
    res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
        url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
            bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
        time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
    if (inherits(res, "try-error")) {
        err <- attr(res, "condition")
        msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
        nc_n_try <- nc_n_try + 1
        if (nc_n_try > n_max_retries) {
            stop(msg)
        }
        else {
            message(msg, "\nRETRYing...")
            Sys.sleep(1)
        }
    }
    else {
        nc_retry <- F
    }
}
debug: res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
    url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
        bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
    time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
debug: if (inherits(res, "try-error")) {
    err <- attr(res, "condition")
    msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
    nc_n_try <- nc_n_try + 1
    if (nc_n_try > n_max_retries) {
        stop(msg)
    }
    else {
        message(msg, "\nRETRYing...")
        Sys.sleep(1)
    }
} else {
    nc_retry <- F
}
debug: nc_retry <- F
debug: (while) nc_retry
debug: i_req <- i_req + 1
debug: (while) i_req <= n_reqs
debug: ncs <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size > 
    0), nc)
debug: r <- terra::rast(ncs)
debug: stopifnot(all(class(terra::time(r)) %in% c("POSIXct", "POSIXt")))
debug: idx <- dplyr::pull(dplyr::filter(dplyr::arrange(dplyr::tibble(idx = 1:terra::nlyr(r), 
    time = terra::time(r)), time), !duplicated(time)), idx)
debug: r <- terra::subset(r, idx)
debug: stopifnot(terra::crs(r, proj = T) == wgs84)
debug: if (mask_tif) r <- terra::mask(r, sf_zones)
debug: lyrs <- glue("{var}|{terra::time(r)}")
debug: if (length(dims_other) > 0 && !all(length(dims[dims_other]) == 
    1)) stop(glue("Other dimensions not yet supported: {paste(dims_other, collapse = ',')}"))
debug: names(r) <- lyrs
debug: if (!is.null(rast_tif)) {
    if (fs::file_exists(rast_tif)) {
        r_tmp_tif <- tempfile(fileext = ".tif")
        r_tmp <- c(rast(rast_tif), r)
        r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
        terra::writeRaster(r_tmp, r_tmp_tif)
        fs::file_delete(rast_tif)
        fs::file_move(r_tmp_tif, rast_tif)
        rm(r)
        rm(r_tmp)
    }
    else {
        terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
    }
    r <- terra::rast(rast_tif)
}
debug: if (fs::file_exists(rast_tif)) {
    r_tmp_tif <- tempfile(fileext = ".tif")
    r_tmp <- c(rast(rast_tif), r)
    r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
    terra::writeRaster(r_tmp, r_tmp_tif)
    fs::file_delete(rast_tif)
    fs::file_move(r_tmp_tif, rast_tif)
    rm(r)
    rm(r_tmp)
} else {
    terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
}
debug: terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
debug: r <- terra::rast(rast_tif)
debug: d_r <- mutate(tidyr::pivot_longer(sf::st_drop_geometry(sf::st_as_sf(terra::zonal(x = r, 
    z = terra::vect(dplyr::select(sf_zones, dplyr::all_of(fld_zones))), 
    fun = zonal_fun, exact = T, na.rm = T, as.polygons = T))), 
    cols = -dplyr::any_of(fld_zones), names_to = "lyr", values_to = zonal_fun), 
    time = readr::parse_datetime(str_replace(lyr, glue("{var}\\|(.*)"), 
        "\\1")))
debug: if (!is.null(zonal_csv)) write_csv(d_r, zonal_csv)
debug: write_csv(d_r, zonal_csv)
debug: if (!keep_nc) unlink(dir_nc, recursive = T)
debug: unlink(dir_nc, recursive = T)
debug: return(d_r)
Downloading 1 requests, up to 125 time slices each
Called from: extractr::ed_extract(ed, var = v, sf_zones = ply, bbox = bb, 
    mask_tif = F, rast_tif = glue("{dir_out}/{nms}/{yr}.tif"), 
    zonal_fun = "mean", zonal_csv = glue("{dir_out}/{nms}/{yr}.csv"), 
    dir_nc = glue("{dir_out}/{nms}/{yr}_nc"), keep_nc = F, n_max_vals_per_req = 1e+05, 
    time_min = time_min, time_max = time_max, verbose = T)
debug: while (i_req <= n_reqs) {
    i_t_beg <- (i_req - 1) * n_t_per_req + 1
    i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
    t_req <- times_todo[c(i_t_beg, i_t_end)]
    t_req_str <- format_ISO8601(t_req, usetz = "Z")
    if (verbose) 
        message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
    ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
        ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
        0), nc)
    unlink(ncs0)
    nc_retry <- T
    nc_n_try <- 1
    n_max_retries
    while (nc_retry) {
        res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
            url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
                bbox[["xmax"]]), latitude = c(bbox[["ymin"]], 
                bbox[["ymax"]]), time = t_req_str, fmt = "nc", 
            store = rerddap::disk(path = dir_nc)))
        if (inherits(res, "try-error")) {
            err <- attr(res, "condition")
            msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
            nc_n_try <- nc_n_try + 1
            if (nc_n_try > n_max_retries) {
                stop(msg)
            }
            else {
                message(msg, "\nRETRYing...")
                Sys.sleep(1)
            }
        }
        else {
            nc_retry <- F
        }
    }
    i_req <- i_req + 1
}
debug: i_t_beg <- (i_req - 1) * n_t_per_req + 1
debug: i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
debug: t_req <- times_todo[c(i_t_beg, i_t_end)]
debug: t_req_str <- format_ISO8601(t_req, usetz = "Z")
debug: if (verbose) message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
debug: message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
Fetching request 1 of 1 (2012-01-01 to 2012-12-01) ~ 19:35:58 UTC
debug: ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
    0), nc)
debug: unlink(ncs0)
debug: nc_retry <- T
debug: nc_n_try <- 1
debug: n_max_retries
debug: while (nc_retry) {
    res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
        url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
            bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
        time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
    if (inherits(res, "try-error")) {
        err <- attr(res, "condition")
        msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
        nc_n_try <- nc_n_try + 1
        if (nc_n_try > n_max_retries) {
            stop(msg)
        }
        else {
            message(msg, "\nRETRYing...")
            Sys.sleep(1)
        }
    }
    else {
        nc_retry <- F
    }
}
debug: res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
    url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
        bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
    time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
debug: if (inherits(res, "try-error")) {
    err <- attr(res, "condition")
    msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
    nc_n_try <- nc_n_try + 1
    if (nc_n_try > n_max_retries) {
        stop(msg)
    }
    else {
        message(msg, "\nRETRYing...")
        Sys.sleep(1)
    }
} else {
    nc_retry <- F
}
debug: nc_retry <- F
debug: (while) nc_retry
debug: i_req <- i_req + 1
debug: (while) i_req <= n_reqs
debug: ncs <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size > 
    0), nc)
debug: r <- terra::rast(ncs)
debug: stopifnot(all(class(terra::time(r)) %in% c("POSIXct", "POSIXt")))
debug: idx <- dplyr::pull(dplyr::filter(dplyr::arrange(dplyr::tibble(idx = 1:terra::nlyr(r), 
    time = terra::time(r)), time), !duplicated(time)), idx)
debug: r <- terra::subset(r, idx)
debug: stopifnot(terra::crs(r, proj = T) == wgs84)
debug: if (mask_tif) r <- terra::mask(r, sf_zones)
debug: lyrs <- glue("{var}|{terra::time(r)}")
debug: if (length(dims_other) > 0 && !all(length(dims[dims_other]) == 
    1)) stop(glue("Other dimensions not yet supported: {paste(dims_other, collapse = ',')}"))
debug: names(r) <- lyrs
debug: if (!is.null(rast_tif)) {
    if (fs::file_exists(rast_tif)) {
        r_tmp_tif <- tempfile(fileext = ".tif")
        r_tmp <- c(rast(rast_tif), r)
        r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
        terra::writeRaster(r_tmp, r_tmp_tif)
        fs::file_delete(rast_tif)
        fs::file_move(r_tmp_tif, rast_tif)
        rm(r)
        rm(r_tmp)
    }
    else {
        terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
    }
    r <- terra::rast(rast_tif)
}
debug: if (fs::file_exists(rast_tif)) {
    r_tmp_tif <- tempfile(fileext = ".tif")
    r_tmp <- c(rast(rast_tif), r)
    r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
    terra::writeRaster(r_tmp, r_tmp_tif)
    fs::file_delete(rast_tif)
    fs::file_move(r_tmp_tif, rast_tif)
    rm(r)
    rm(r_tmp)
} else {
    terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
}
debug: terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
debug: r <- terra::rast(rast_tif)
debug: d_r <- mutate(tidyr::pivot_longer(sf::st_drop_geometry(sf::st_as_sf(terra::zonal(x = r, 
    z = terra::vect(dplyr::select(sf_zones, dplyr::all_of(fld_zones))), 
    fun = zonal_fun, exact = T, na.rm = T, as.polygons = T))), 
    cols = -dplyr::any_of(fld_zones), names_to = "lyr", values_to = zonal_fun), 
    time = readr::parse_datetime(str_replace(lyr, glue("{var}\\|(.*)"), 
        "\\1")))
debug: if (!is.null(zonal_csv)) write_csv(d_r, zonal_csv)
debug: write_csv(d_r, zonal_csv)
debug: if (!keep_nc) unlink(dir_nc, recursive = T)
debug: unlink(dir_nc, recursive = T)
debug: return(d_r)
Downloading 1 requests, up to 125 time slices each
Called from: extractr::ed_extract(ed, var = v, sf_zones = ply, bbox = bb, 
    mask_tif = F, rast_tif = glue("{dir_out}/{nms}/{yr}.tif"), 
    zonal_fun = "mean", zonal_csv = glue("{dir_out}/{nms}/{yr}.csv"), 
    dir_nc = glue("{dir_out}/{nms}/{yr}_nc"), keep_nc = F, n_max_vals_per_req = 1e+05, 
    time_min = time_min, time_max = time_max, verbose = T)
debug: while (i_req <= n_reqs) {
    i_t_beg <- (i_req - 1) * n_t_per_req + 1
    i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
    t_req <- times_todo[c(i_t_beg, i_t_end)]
    t_req_str <- format_ISO8601(t_req, usetz = "Z")
    if (verbose) 
        message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
    ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
        ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
        0), nc)
    unlink(ncs0)
    nc_retry <- T
    nc_n_try <- 1
    n_max_retries
    while (nc_retry) {
        res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
            url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
                bbox[["xmax"]]), latitude = c(bbox[["ymin"]], 
                bbox[["ymax"]]), time = t_req_str, fmt = "nc", 
            store = rerddap::disk(path = dir_nc)))
        if (inherits(res, "try-error")) {
            err <- attr(res, "condition")
            msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
            nc_n_try <- nc_n_try + 1
            if (nc_n_try > n_max_retries) {
                stop(msg)
            }
            else {
                message(msg, "\nRETRYing...")
                Sys.sleep(1)
            }
        }
        else {
            nc_retry <- F
        }
    }
    i_req <- i_req + 1
}
debug: i_t_beg <- (i_req - 1) * n_t_per_req + 1
debug: i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
debug: t_req <- times_todo[c(i_t_beg, i_t_end)]
debug: t_req_str <- format_ISO8601(t_req, usetz = "Z")
debug: if (verbose) message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
debug: message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
Fetching request 1 of 1 (2013-01-01 to 2013-12-01) ~ 19:36:01 UTC
debug: ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
    0), nc)
debug: unlink(ncs0)
debug: nc_retry <- T
debug: nc_n_try <- 1
debug: n_max_retries
debug: while (nc_retry) {
    res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
        url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
            bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
        time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
    if (inherits(res, "try-error")) {
        err <- attr(res, "condition")
        msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
        nc_n_try <- nc_n_try + 1
        if (nc_n_try > n_max_retries) {
            stop(msg)
        }
        else {
            message(msg, "\nRETRYing...")
            Sys.sleep(1)
        }
    }
    else {
        nc_retry <- F
    }
}
debug: res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
    url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
        bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
    time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
debug: if (inherits(res, "try-error")) {
    err <- attr(res, "condition")
    msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
    nc_n_try <- nc_n_try + 1
    if (nc_n_try > n_max_retries) {
        stop(msg)
    }
    else {
        message(msg, "\nRETRYing...")
        Sys.sleep(1)
    }
} else {
    nc_retry <- F
}
debug: nc_retry <- F
debug: (while) nc_retry
debug: i_req <- i_req + 1
debug: (while) i_req <= n_reqs
debug: ncs <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size > 
    0), nc)
debug: r <- terra::rast(ncs)
debug: stopifnot(all(class(terra::time(r)) %in% c("POSIXct", "POSIXt")))
debug: idx <- dplyr::pull(dplyr::filter(dplyr::arrange(dplyr::tibble(idx = 1:terra::nlyr(r), 
    time = terra::time(r)), time), !duplicated(time)), idx)
debug: r <- terra::subset(r, idx)
debug: stopifnot(terra::crs(r, proj = T) == wgs84)
debug: if (mask_tif) r <- terra::mask(r, sf_zones)
debug: lyrs <- glue("{var}|{terra::time(r)}")
debug: if (length(dims_other) > 0 && !all(length(dims[dims_other]) == 
    1)) stop(glue("Other dimensions not yet supported: {paste(dims_other, collapse = ',')}"))
debug: names(r) <- lyrs
debug: if (!is.null(rast_tif)) {
    if (fs::file_exists(rast_tif)) {
        r_tmp_tif <- tempfile(fileext = ".tif")
        r_tmp <- c(rast(rast_tif), r)
        r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
        terra::writeRaster(r_tmp, r_tmp_tif)
        fs::file_delete(rast_tif)
        fs::file_move(r_tmp_tif, rast_tif)
        rm(r)
        rm(r_tmp)
    }
    else {
        terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
    }
    r <- terra::rast(rast_tif)
}
debug: if (fs::file_exists(rast_tif)) {
    r_tmp_tif <- tempfile(fileext = ".tif")
    r_tmp <- c(rast(rast_tif), r)
    r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
    terra::writeRaster(r_tmp, r_tmp_tif)
    fs::file_delete(rast_tif)
    fs::file_move(r_tmp_tif, rast_tif)
    rm(r)
    rm(r_tmp)
} else {
    terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
}
debug: terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
debug: r <- terra::rast(rast_tif)
debug: d_r <- mutate(tidyr::pivot_longer(sf::st_drop_geometry(sf::st_as_sf(terra::zonal(x = r, 
    z = terra::vect(dplyr::select(sf_zones, dplyr::all_of(fld_zones))), 
    fun = zonal_fun, exact = T, na.rm = T, as.polygons = T))), 
    cols = -dplyr::any_of(fld_zones), names_to = "lyr", values_to = zonal_fun), 
    time = readr::parse_datetime(str_replace(lyr, glue("{var}\\|(.*)"), 
        "\\1")))
debug: if (!is.null(zonal_csv)) write_csv(d_r, zonal_csv)
debug: write_csv(d_r, zonal_csv)
debug: if (!keep_nc) unlink(dir_nc, recursive = T)
debug: unlink(dir_nc, recursive = T)
debug: return(d_r)
Downloading 1 requests, up to 125 time slices each
Called from: extractr::ed_extract(ed, var = v, sf_zones = ply, bbox = bb, 
    mask_tif = F, rast_tif = glue("{dir_out}/{nms}/{yr}.tif"), 
    zonal_fun = "mean", zonal_csv = glue("{dir_out}/{nms}/{yr}.csv"), 
    dir_nc = glue("{dir_out}/{nms}/{yr}_nc"), keep_nc = F, n_max_vals_per_req = 1e+05, 
    time_min = time_min, time_max = time_max, verbose = T)
debug: while (i_req <= n_reqs) {
    i_t_beg <- (i_req - 1) * n_t_per_req + 1
    i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
    t_req <- times_todo[c(i_t_beg, i_t_end)]
    t_req_str <- format_ISO8601(t_req, usetz = "Z")
    if (verbose) 
        message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
    ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
        ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
        0), nc)
    unlink(ncs0)
    nc_retry <- T
    nc_n_try <- 1
    n_max_retries
    while (nc_retry) {
        res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
            url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
                bbox[["xmax"]]), latitude = c(bbox[["ymin"]], 
                bbox[["ymax"]]), time = t_req_str, fmt = "nc", 
            store = rerddap::disk(path = dir_nc)))
        if (inherits(res, "try-error")) {
            err <- attr(res, "condition")
            msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
            nc_n_try <- nc_n_try + 1
            if (nc_n_try > n_max_retries) {
                stop(msg)
            }
            else {
                message(msg, "\nRETRYing...")
                Sys.sleep(1)
            }
        }
        else {
            nc_retry <- F
        }
    }
    i_req <- i_req + 1
}
debug: i_t_beg <- (i_req - 1) * n_t_per_req + 1
debug: i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
debug: t_req <- times_todo[c(i_t_beg, i_t_end)]
debug: t_req_str <- format_ISO8601(t_req, usetz = "Z")
debug: if (verbose) message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
debug: message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
Fetching request 1 of 1 (2014-01-01 to 2014-12-01) ~ 19:36:04 UTC
debug: ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
    0), nc)
debug: unlink(ncs0)
debug: nc_retry <- T
debug: nc_n_try <- 1
debug: n_max_retries
debug: while (nc_retry) {
    res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
        url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
            bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
        time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
    if (inherits(res, "try-error")) {
        err <- attr(res, "condition")
        msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
        nc_n_try <- nc_n_try + 1
        if (nc_n_try > n_max_retries) {
            stop(msg)
        }
        else {
            message(msg, "\nRETRYing...")
            Sys.sleep(1)
        }
    }
    else {
        nc_retry <- F
    }
}
debug: res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
    url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
        bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
    time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
debug: if (inherits(res, "try-error")) {
    err <- attr(res, "condition")
    msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
    nc_n_try <- nc_n_try + 1
    if (nc_n_try > n_max_retries) {
        stop(msg)
    }
    else {
        message(msg, "\nRETRYing...")
        Sys.sleep(1)
    }
} else {
    nc_retry <- F
}
debug: nc_retry <- F
debug: (while) nc_retry
debug: i_req <- i_req + 1
debug: (while) i_req <= n_reqs
debug: ncs <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size > 
    0), nc)
debug: r <- terra::rast(ncs)
debug: stopifnot(all(class(terra::time(r)) %in% c("POSIXct", "POSIXt")))
debug: idx <- dplyr::pull(dplyr::filter(dplyr::arrange(dplyr::tibble(idx = 1:terra::nlyr(r), 
    time = terra::time(r)), time), !duplicated(time)), idx)
debug: r <- terra::subset(r, idx)
debug: stopifnot(terra::crs(r, proj = T) == wgs84)
debug: if (mask_tif) r <- terra::mask(r, sf_zones)
debug: lyrs <- glue("{var}|{terra::time(r)}")
debug: if (length(dims_other) > 0 && !all(length(dims[dims_other]) == 
    1)) stop(glue("Other dimensions not yet supported: {paste(dims_other, collapse = ',')}"))
debug: names(r) <- lyrs
debug: if (!is.null(rast_tif)) {
    if (fs::file_exists(rast_tif)) {
        r_tmp_tif <- tempfile(fileext = ".tif")
        r_tmp <- c(rast(rast_tif), r)
        r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
        terra::writeRaster(r_tmp, r_tmp_tif)
        fs::file_delete(rast_tif)
        fs::file_move(r_tmp_tif, rast_tif)
        rm(r)
        rm(r_tmp)
    }
    else {
        terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
    }
    r <- terra::rast(rast_tif)
}
debug: if (fs::file_exists(rast_tif)) {
    r_tmp_tif <- tempfile(fileext = ".tif")
    r_tmp <- c(rast(rast_tif), r)
    r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
    terra::writeRaster(r_tmp, r_tmp_tif)
    fs::file_delete(rast_tif)
    fs::file_move(r_tmp_tif, rast_tif)
    rm(r)
    rm(r_tmp)
} else {
    terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
}
debug: terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
debug: r <- terra::rast(rast_tif)
debug: d_r <- mutate(tidyr::pivot_longer(sf::st_drop_geometry(sf::st_as_sf(terra::zonal(x = r, 
    z = terra::vect(dplyr::select(sf_zones, dplyr::all_of(fld_zones))), 
    fun = zonal_fun, exact = T, na.rm = T, as.polygons = T))), 
    cols = -dplyr::any_of(fld_zones), names_to = "lyr", values_to = zonal_fun), 
    time = readr::parse_datetime(str_replace(lyr, glue("{var}\\|(.*)"), 
        "\\1")))
debug: if (!is.null(zonal_csv)) write_csv(d_r, zonal_csv)
debug: write_csv(d_r, zonal_csv)
debug: if (!keep_nc) unlink(dir_nc, recursive = T)
debug: unlink(dir_nc, recursive = T)
debug: return(d_r)
Downloading 1 requests, up to 125 time slices each
Called from: extractr::ed_extract(ed, var = v, sf_zones = ply, bbox = bb, 
    mask_tif = F, rast_tif = glue("{dir_out}/{nms}/{yr}.tif"), 
    zonal_fun = "mean", zonal_csv = glue("{dir_out}/{nms}/{yr}.csv"), 
    dir_nc = glue("{dir_out}/{nms}/{yr}_nc"), keep_nc = F, n_max_vals_per_req = 1e+05, 
    time_min = time_min, time_max = time_max, verbose = T)
debug: while (i_req <= n_reqs) {
    i_t_beg <- (i_req - 1) * n_t_per_req + 1
    i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
    t_req <- times_todo[c(i_t_beg, i_t_end)]
    t_req_str <- format_ISO8601(t_req, usetz = "Z")
    if (verbose) 
        message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
    ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
        ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
        0), nc)
    unlink(ncs0)
    nc_retry <- T
    nc_n_try <- 1
    n_max_retries
    while (nc_retry) {
        res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
            url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
                bbox[["xmax"]]), latitude = c(bbox[["ymin"]], 
                bbox[["ymax"]]), time = t_req_str, fmt = "nc", 
            store = rerddap::disk(path = dir_nc)))
        if (inherits(res, "try-error")) {
            err <- attr(res, "condition")
            msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
            nc_n_try <- nc_n_try + 1
            if (nc_n_try > n_max_retries) {
                stop(msg)
            }
            else {
                message(msg, "\nRETRYing...")
                Sys.sleep(1)
            }
        }
        else {
            nc_retry <- F
        }
    }
    i_req <- i_req + 1
}
debug: i_t_beg <- (i_req - 1) * n_t_per_req + 1
debug: i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
debug: t_req <- times_todo[c(i_t_beg, i_t_end)]
debug: t_req_str <- format_ISO8601(t_req, usetz = "Z")
debug: if (verbose) message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
debug: message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
Fetching request 1 of 1 (2015-01-01 to 2015-12-01) ~ 19:36:07 UTC
debug: ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
    0), nc)
debug: unlink(ncs0)
debug: nc_retry <- T
debug: nc_n_try <- 1
debug: n_max_retries
debug: while (nc_retry) {
    res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
        url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
            bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
        time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
    if (inherits(res, "try-error")) {
        err <- attr(res, "condition")
        msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
        nc_n_try <- nc_n_try + 1
        if (nc_n_try > n_max_retries) {
            stop(msg)
        }
        else {
            message(msg, "\nRETRYing...")
            Sys.sleep(1)
        }
    }
    else {
        nc_retry <- F
    }
}
debug: res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
    url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
        bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
    time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
debug: if (inherits(res, "try-error")) {
    err <- attr(res, "condition")
    msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
    nc_n_try <- nc_n_try + 1
    if (nc_n_try > n_max_retries) {
        stop(msg)
    }
    else {
        message(msg, "\nRETRYing...")
        Sys.sleep(1)
    }
} else {
    nc_retry <- F
}
debug: nc_retry <- F
debug: (while) nc_retry
debug: i_req <- i_req + 1
debug: (while) i_req <= n_reqs
debug: ncs <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size > 
    0), nc)
debug: r <- terra::rast(ncs)
debug: stopifnot(all(class(terra::time(r)) %in% c("POSIXct", "POSIXt")))
debug: idx <- dplyr::pull(dplyr::filter(dplyr::arrange(dplyr::tibble(idx = 1:terra::nlyr(r), 
    time = terra::time(r)), time), !duplicated(time)), idx)
debug: r <- terra::subset(r, idx)
debug: stopifnot(terra::crs(r, proj = T) == wgs84)
debug: if (mask_tif) r <- terra::mask(r, sf_zones)
debug: lyrs <- glue("{var}|{terra::time(r)}")
debug: if (length(dims_other) > 0 && !all(length(dims[dims_other]) == 
    1)) stop(glue("Other dimensions not yet supported: {paste(dims_other, collapse = ',')}"))
debug: names(r) <- lyrs
debug: if (!is.null(rast_tif)) {
    if (fs::file_exists(rast_tif)) {
        r_tmp_tif <- tempfile(fileext = ".tif")
        r_tmp <- c(rast(rast_tif), r)
        r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
        terra::writeRaster(r_tmp, r_tmp_tif)
        fs::file_delete(rast_tif)
        fs::file_move(r_tmp_tif, rast_tif)
        rm(r)
        rm(r_tmp)
    }
    else {
        terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
    }
    r <- terra::rast(rast_tif)
}
debug: if (fs::file_exists(rast_tif)) {
    r_tmp_tif <- tempfile(fileext = ".tif")
    r_tmp <- c(rast(rast_tif), r)
    r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
    terra::writeRaster(r_tmp, r_tmp_tif)
    fs::file_delete(rast_tif)
    fs::file_move(r_tmp_tif, rast_tif)
    rm(r)
    rm(r_tmp)
} else {
    terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
}
debug: terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
debug: r <- terra::rast(rast_tif)
debug: d_r <- mutate(tidyr::pivot_longer(sf::st_drop_geometry(sf::st_as_sf(terra::zonal(x = r, 
    z = terra::vect(dplyr::select(sf_zones, dplyr::all_of(fld_zones))), 
    fun = zonal_fun, exact = T, na.rm = T, as.polygons = T))), 
    cols = -dplyr::any_of(fld_zones), names_to = "lyr", values_to = zonal_fun), 
    time = readr::parse_datetime(str_replace(lyr, glue("{var}\\|(.*)"), 
        "\\1")))
debug: if (!is.null(zonal_csv)) write_csv(d_r, zonal_csv)
debug: write_csv(d_r, zonal_csv)
debug: if (!keep_nc) unlink(dir_nc, recursive = T)
debug: unlink(dir_nc, recursive = T)
debug: return(d_r)
Downloading 1 requests, up to 125 time slices each
Called from: extractr::ed_extract(ed, var = v, sf_zones = ply, bbox = bb, 
    mask_tif = F, rast_tif = glue("{dir_out}/{nms}/{yr}.tif"), 
    zonal_fun = "mean", zonal_csv = glue("{dir_out}/{nms}/{yr}.csv"), 
    dir_nc = glue("{dir_out}/{nms}/{yr}_nc"), keep_nc = F, n_max_vals_per_req = 1e+05, 
    time_min = time_min, time_max = time_max, verbose = T)
debug: while (i_req <= n_reqs) {
    i_t_beg <- (i_req - 1) * n_t_per_req + 1
    i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
    t_req <- times_todo[c(i_t_beg, i_t_end)]
    t_req_str <- format_ISO8601(t_req, usetz = "Z")
    if (verbose) 
        message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
    ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
        ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
        0), nc)
    unlink(ncs0)
    nc_retry <- T
    nc_n_try <- 1
    n_max_retries
    while (nc_retry) {
        res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
            url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
                bbox[["xmax"]]), latitude = c(bbox[["ymin"]], 
                bbox[["ymax"]]), time = t_req_str, fmt = "nc", 
            store = rerddap::disk(path = dir_nc)))
        if (inherits(res, "try-error")) {
            err <- attr(res, "condition")
            msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
            nc_n_try <- nc_n_try + 1
            if (nc_n_try > n_max_retries) {
                stop(msg)
            }
            else {
                message(msg, "\nRETRYing...")
                Sys.sleep(1)
            }
        }
        else {
            nc_retry <- F
        }
    }
    i_req <- i_req + 1
}
debug: i_t_beg <- (i_req - 1) * n_t_per_req + 1
debug: i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
debug: t_req <- times_todo[c(i_t_beg, i_t_end)]
debug: t_req_str <- format_ISO8601(t_req, usetz = "Z")
debug: if (verbose) message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
debug: message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
Fetching request 1 of 1 (2016-01-01 to 2016-12-01) ~ 19:36:10 UTC
debug: ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
    0), nc)
debug: unlink(ncs0)
debug: nc_retry <- T
debug: nc_n_try <- 1
debug: n_max_retries
debug: while (nc_retry) {
    res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
        url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
            bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
        time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
    if (inherits(res, "try-error")) {
        err <- attr(res, "condition")
        msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
        nc_n_try <- nc_n_try + 1
        if (nc_n_try > n_max_retries) {
            stop(msg)
        }
        else {
            message(msg, "\nRETRYing...")
            Sys.sleep(1)
        }
    }
    else {
        nc_retry <- F
    }
}
debug: res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
    url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
        bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
    time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
debug: if (inherits(res, "try-error")) {
    err <- attr(res, "condition")
    msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
    nc_n_try <- nc_n_try + 1
    if (nc_n_try > n_max_retries) {
        stop(msg)
    }
    else {
        message(msg, "\nRETRYing...")
        Sys.sleep(1)
    }
} else {
    nc_retry <- F
}
debug: nc_retry <- F
debug: (while) nc_retry
debug: i_req <- i_req + 1
debug: (while) i_req <= n_reqs
debug: ncs <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size > 
    0), nc)
debug: r <- terra::rast(ncs)
debug: stopifnot(all(class(terra::time(r)) %in% c("POSIXct", "POSIXt")))
debug: idx <- dplyr::pull(dplyr::filter(dplyr::arrange(dplyr::tibble(idx = 1:terra::nlyr(r), 
    time = terra::time(r)), time), !duplicated(time)), idx)
debug: r <- terra::subset(r, idx)
debug: stopifnot(terra::crs(r, proj = T) == wgs84)
debug: if (mask_tif) r <- terra::mask(r, sf_zones)
debug: lyrs <- glue("{var}|{terra::time(r)}")
debug: if (length(dims_other) > 0 && !all(length(dims[dims_other]) == 
    1)) stop(glue("Other dimensions not yet supported: {paste(dims_other, collapse = ',')}"))
debug: names(r) <- lyrs
debug: if (!is.null(rast_tif)) {
    if (fs::file_exists(rast_tif)) {
        r_tmp_tif <- tempfile(fileext = ".tif")
        r_tmp <- c(rast(rast_tif), r)
        r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
        terra::writeRaster(r_tmp, r_tmp_tif)
        fs::file_delete(rast_tif)
        fs::file_move(r_tmp_tif, rast_tif)
        rm(r)
        rm(r_tmp)
    }
    else {
        terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
    }
    r <- terra::rast(rast_tif)
}
debug: if (fs::file_exists(rast_tif)) {
    r_tmp_tif <- tempfile(fileext = ".tif")
    r_tmp <- c(rast(rast_tif), r)
    r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
    terra::writeRaster(r_tmp, r_tmp_tif)
    fs::file_delete(rast_tif)
    fs::file_move(r_tmp_tif, rast_tif)
    rm(r)
    rm(r_tmp)
} else {
    terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
}
debug: terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
debug: r <- terra::rast(rast_tif)
debug: d_r <- mutate(tidyr::pivot_longer(sf::st_drop_geometry(sf::st_as_sf(terra::zonal(x = r, 
    z = terra::vect(dplyr::select(sf_zones, dplyr::all_of(fld_zones))), 
    fun = zonal_fun, exact = T, na.rm = T, as.polygons = T))), 
    cols = -dplyr::any_of(fld_zones), names_to = "lyr", values_to = zonal_fun), 
    time = readr::parse_datetime(str_replace(lyr, glue("{var}\\|(.*)"), 
        "\\1")))
debug: if (!is.null(zonal_csv)) write_csv(d_r, zonal_csv)
debug: write_csv(d_r, zonal_csv)
debug: if (!keep_nc) unlink(dir_nc, recursive = T)
debug: unlink(dir_nc, recursive = T)
debug: return(d_r)
Downloading 1 requests, up to 125 time slices each
Called from: extractr::ed_extract(ed, var = v, sf_zones = ply, bbox = bb, 
    mask_tif = F, rast_tif = glue("{dir_out}/{nms}/{yr}.tif"), 
    zonal_fun = "mean", zonal_csv = glue("{dir_out}/{nms}/{yr}.csv"), 
    dir_nc = glue("{dir_out}/{nms}/{yr}_nc"), keep_nc = F, n_max_vals_per_req = 1e+05, 
    time_min = time_min, time_max = time_max, verbose = T)
debug: while (i_req <= n_reqs) {
    i_t_beg <- (i_req - 1) * n_t_per_req + 1
    i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
    t_req <- times_todo[c(i_t_beg, i_t_end)]
    t_req_str <- format_ISO8601(t_req, usetz = "Z")
    if (verbose) 
        message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
    ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
        ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
        0), nc)
    unlink(ncs0)
    nc_retry <- T
    nc_n_try <- 1
    n_max_retries
    while (nc_retry) {
        res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
            url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
                bbox[["xmax"]]), latitude = c(bbox[["ymin"]], 
                bbox[["ymax"]]), time = t_req_str, fmt = "nc", 
            store = rerddap::disk(path = dir_nc)))
        if (inherits(res, "try-error")) {
            err <- attr(res, "condition")
            msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
            nc_n_try <- nc_n_try + 1
            if (nc_n_try > n_max_retries) {
                stop(msg)
            }
            else {
                message(msg, "\nRETRYing...")
                Sys.sleep(1)
            }
        }
        else {
            nc_retry <- F
        }
    }
    i_req <- i_req + 1
}
debug: i_t_beg <- (i_req - 1) * n_t_per_req + 1
debug: i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
debug: t_req <- times_todo[c(i_t_beg, i_t_end)]
debug: t_req_str <- format_ISO8601(t_req, usetz = "Z")
debug: if (verbose) message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
debug: message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
Fetching request 1 of 1 (2017-01-01 to 2017-12-01) ~ 19:36:12 UTC
debug: ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
    0), nc)
debug: unlink(ncs0)
debug: nc_retry <- T
debug: nc_n_try <- 1
debug: n_max_retries
debug: while (nc_retry) {
    res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
        url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
            bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
        time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
    if (inherits(res, "try-error")) {
        err <- attr(res, "condition")
        msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
        nc_n_try <- nc_n_try + 1
        if (nc_n_try > n_max_retries) {
            stop(msg)
        }
        else {
            message(msg, "\nRETRYing...")
            Sys.sleep(1)
        }
    }
    else {
        nc_retry <- F
    }
}
debug: res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
    url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
        bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
    time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
debug: if (inherits(res, "try-error")) {
    err <- attr(res, "condition")
    msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
    nc_n_try <- nc_n_try + 1
    if (nc_n_try > n_max_retries) {
        stop(msg)
    }
    else {
        message(msg, "\nRETRYing...")
        Sys.sleep(1)
    }
} else {
    nc_retry <- F
}
debug: nc_retry <- F
debug: (while) nc_retry
debug: i_req <- i_req + 1
debug: (while) i_req <= n_reqs
debug: ncs <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size > 
    0), nc)
debug: r <- terra::rast(ncs)
debug: stopifnot(all(class(terra::time(r)) %in% c("POSIXct", "POSIXt")))
debug: idx <- dplyr::pull(dplyr::filter(dplyr::arrange(dplyr::tibble(idx = 1:terra::nlyr(r), 
    time = terra::time(r)), time), !duplicated(time)), idx)
debug: r <- terra::subset(r, idx)
debug: stopifnot(terra::crs(r, proj = T) == wgs84)
debug: if (mask_tif) r <- terra::mask(r, sf_zones)
debug: lyrs <- glue("{var}|{terra::time(r)}")
debug: if (length(dims_other) > 0 && !all(length(dims[dims_other]) == 
    1)) stop(glue("Other dimensions not yet supported: {paste(dims_other, collapse = ',')}"))
debug: names(r) <- lyrs
debug: if (!is.null(rast_tif)) {
    if (fs::file_exists(rast_tif)) {
        r_tmp_tif <- tempfile(fileext = ".tif")
        r_tmp <- c(rast(rast_tif), r)
        r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
        terra::writeRaster(r_tmp, r_tmp_tif)
        fs::file_delete(rast_tif)
        fs::file_move(r_tmp_tif, rast_tif)
        rm(r)
        rm(r_tmp)
    }
    else {
        terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
    }
    r <- terra::rast(rast_tif)
}
debug: if (fs::file_exists(rast_tif)) {
    r_tmp_tif <- tempfile(fileext = ".tif")
    r_tmp <- c(rast(rast_tif), r)
    r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
    terra::writeRaster(r_tmp, r_tmp_tif)
    fs::file_delete(rast_tif)
    fs::file_move(r_tmp_tif, rast_tif)
    rm(r)
    rm(r_tmp)
} else {
    terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
}
debug: terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
debug: r <- terra::rast(rast_tif)
debug: d_r <- mutate(tidyr::pivot_longer(sf::st_drop_geometry(sf::st_as_sf(terra::zonal(x = r, 
    z = terra::vect(dplyr::select(sf_zones, dplyr::all_of(fld_zones))), 
    fun = zonal_fun, exact = T, na.rm = T, as.polygons = T))), 
    cols = -dplyr::any_of(fld_zones), names_to = "lyr", values_to = zonal_fun), 
    time = readr::parse_datetime(str_replace(lyr, glue("{var}\\|(.*)"), 
        "\\1")))
debug: if (!is.null(zonal_csv)) write_csv(d_r, zonal_csv)
debug: write_csv(d_r, zonal_csv)
debug: if (!keep_nc) unlink(dir_nc, recursive = T)
debug: unlink(dir_nc, recursive = T)
debug: return(d_r)
Downloading 1 requests, up to 125 time slices each
Called from: extractr::ed_extract(ed, var = v, sf_zones = ply, bbox = bb, 
    mask_tif = F, rast_tif = glue("{dir_out}/{nms}/{yr}.tif"), 
    zonal_fun = "mean", zonal_csv = glue("{dir_out}/{nms}/{yr}.csv"), 
    dir_nc = glue("{dir_out}/{nms}/{yr}_nc"), keep_nc = F, n_max_vals_per_req = 1e+05, 
    time_min = time_min, time_max = time_max, verbose = T)
debug: while (i_req <= n_reqs) {
    i_t_beg <- (i_req - 1) * n_t_per_req + 1
    i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
    t_req <- times_todo[c(i_t_beg, i_t_end)]
    t_req_str <- format_ISO8601(t_req, usetz = "Z")
    if (verbose) 
        message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
    ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
        ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
        0), nc)
    unlink(ncs0)
    nc_retry <- T
    nc_n_try <- 1
    n_max_retries
    while (nc_retry) {
        res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
            url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
                bbox[["xmax"]]), latitude = c(bbox[["ymin"]], 
                bbox[["ymax"]]), time = t_req_str, fmt = "nc", 
            store = rerddap::disk(path = dir_nc)))
        if (inherits(res, "try-error")) {
            err <- attr(res, "condition")
            msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
            nc_n_try <- nc_n_try + 1
            if (nc_n_try > n_max_retries) {
                stop(msg)
            }
            else {
                message(msg, "\nRETRYing...")
                Sys.sleep(1)
            }
        }
        else {
            nc_retry <- F
        }
    }
    i_req <- i_req + 1
}
debug: i_t_beg <- (i_req - 1) * n_t_per_req + 1
debug: i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
debug: t_req <- times_todo[c(i_t_beg, i_t_end)]
debug: t_req_str <- format_ISO8601(t_req, usetz = "Z")
debug: if (verbose) message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
debug: message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
Fetching request 1 of 1 (2018-01-01 to 2018-12-01) ~ 19:36:15 UTC
debug: ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
    0), nc)
debug: unlink(ncs0)
debug: nc_retry <- T
debug: nc_n_try <- 1
debug: n_max_retries
debug: while (nc_retry) {
    res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
        url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
            bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
        time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
    if (inherits(res, "try-error")) {
        err <- attr(res, "condition")
        msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
        nc_n_try <- nc_n_try + 1
        if (nc_n_try > n_max_retries) {
            stop(msg)
        }
        else {
            message(msg, "\nRETRYing...")
            Sys.sleep(1)
        }
    }
    else {
        nc_retry <- F
    }
}
debug: res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
    url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
        bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
    time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
debug: if (inherits(res, "try-error")) {
    err <- attr(res, "condition")
    msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
    nc_n_try <- nc_n_try + 1
    if (nc_n_try > n_max_retries) {
        stop(msg)
    }
    else {
        message(msg, "\nRETRYing...")
        Sys.sleep(1)
    }
} else {
    nc_retry <- F
}
debug: nc_retry <- F
debug: (while) nc_retry
debug: i_req <- i_req + 1
debug: (while) i_req <= n_reqs
debug: ncs <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size > 
    0), nc)
debug: r <- terra::rast(ncs)
debug: stopifnot(all(class(terra::time(r)) %in% c("POSIXct", "POSIXt")))
debug: idx <- dplyr::pull(dplyr::filter(dplyr::arrange(dplyr::tibble(idx = 1:terra::nlyr(r), 
    time = terra::time(r)), time), !duplicated(time)), idx)
debug: r <- terra::subset(r, idx)
debug: stopifnot(terra::crs(r, proj = T) == wgs84)
debug: if (mask_tif) r <- terra::mask(r, sf_zones)
debug: lyrs <- glue("{var}|{terra::time(r)}")
debug: if (length(dims_other) > 0 && !all(length(dims[dims_other]) == 
    1)) stop(glue("Other dimensions not yet supported: {paste(dims_other, collapse = ',')}"))
debug: names(r) <- lyrs
debug: if (!is.null(rast_tif)) {
    if (fs::file_exists(rast_tif)) {
        r_tmp_tif <- tempfile(fileext = ".tif")
        r_tmp <- c(rast(rast_tif), r)
        r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
        terra::writeRaster(r_tmp, r_tmp_tif)
        fs::file_delete(rast_tif)
        fs::file_move(r_tmp_tif, rast_tif)
        rm(r)
        rm(r_tmp)
    }
    else {
        terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
    }
    r <- terra::rast(rast_tif)
}
debug: if (fs::file_exists(rast_tif)) {
    r_tmp_tif <- tempfile(fileext = ".tif")
    r_tmp <- c(rast(rast_tif), r)
    r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
    terra::writeRaster(r_tmp, r_tmp_tif)
    fs::file_delete(rast_tif)
    fs::file_move(r_tmp_tif, rast_tif)
    rm(r)
    rm(r_tmp)
} else {
    terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
}
debug: terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
debug: r <- terra::rast(rast_tif)
debug: d_r <- mutate(tidyr::pivot_longer(sf::st_drop_geometry(sf::st_as_sf(terra::zonal(x = r, 
    z = terra::vect(dplyr::select(sf_zones, dplyr::all_of(fld_zones))), 
    fun = zonal_fun, exact = T, na.rm = T, as.polygons = T))), 
    cols = -dplyr::any_of(fld_zones), names_to = "lyr", values_to = zonal_fun), 
    time = readr::parse_datetime(str_replace(lyr, glue("{var}\\|(.*)"), 
        "\\1")))
debug: if (!is.null(zonal_csv)) write_csv(d_r, zonal_csv)
debug: write_csv(d_r, zonal_csv)
debug: if (!keep_nc) unlink(dir_nc, recursive = T)
debug: unlink(dir_nc, recursive = T)
debug: return(d_r)
Downloading 1 requests, up to 125 time slices each
Called from: extractr::ed_extract(ed, var = v, sf_zones = ply, bbox = bb, 
    mask_tif = F, rast_tif = glue("{dir_out}/{nms}/{yr}.tif"), 
    zonal_fun = "mean", zonal_csv = glue("{dir_out}/{nms}/{yr}.csv"), 
    dir_nc = glue("{dir_out}/{nms}/{yr}_nc"), keep_nc = F, n_max_vals_per_req = 1e+05, 
    time_min = time_min, time_max = time_max, verbose = T)
debug: while (i_req <= n_reqs) {
    i_t_beg <- (i_req - 1) * n_t_per_req + 1
    i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
    t_req <- times_todo[c(i_t_beg, i_t_end)]
    t_req_str <- format_ISO8601(t_req, usetz = "Z")
    if (verbose) 
        message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
    ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
        ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
        0), nc)
    unlink(ncs0)
    nc_retry <- T
    nc_n_try <- 1
    n_max_retries
    while (nc_retry) {
        res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
            url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
                bbox[["xmax"]]), latitude = c(bbox[["ymin"]], 
                bbox[["ymax"]]), time = t_req_str, fmt = "nc", 
            store = rerddap::disk(path = dir_nc)))
        if (inherits(res, "try-error")) {
            err <- attr(res, "condition")
            msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
            nc_n_try <- nc_n_try + 1
            if (nc_n_try > n_max_retries) {
                stop(msg)
            }
            else {
                message(msg, "\nRETRYing...")
                Sys.sleep(1)
            }
        }
        else {
            nc_retry <- F
        }
    }
    i_req <- i_req + 1
}
debug: i_t_beg <- (i_req - 1) * n_t_per_req + 1
debug: i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
debug: t_req <- times_todo[c(i_t_beg, i_t_end)]
debug: t_req_str <- format_ISO8601(t_req, usetz = "Z")
debug: if (verbose) message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
debug: message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
Fetching request 1 of 1 (2019-01-01 to 2019-12-01) ~ 19:36:18 UTC
debug: ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
    0), nc)
debug: unlink(ncs0)
debug: nc_retry <- T
debug: nc_n_try <- 1
debug: n_max_retries
debug: while (nc_retry) {
    res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
        url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
            bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
        time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
    if (inherits(res, "try-error")) {
        err <- attr(res, "condition")
        msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
        nc_n_try <- nc_n_try + 1
        if (nc_n_try > n_max_retries) {
            stop(msg)
        }
        else {
            message(msg, "\nRETRYing...")
            Sys.sleep(1)
        }
    }
    else {
        nc_retry <- F
    }
}
debug: res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
    url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
        bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
    time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
debug: if (inherits(res, "try-error")) {
    err <- attr(res, "condition")
    msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
    nc_n_try <- nc_n_try + 1
    if (nc_n_try > n_max_retries) {
        stop(msg)
    }
    else {
        message(msg, "\nRETRYing...")
        Sys.sleep(1)
    }
} else {
    nc_retry <- F
}
debug: nc_retry <- F
debug: (while) nc_retry
debug: i_req <- i_req + 1
debug: (while) i_req <= n_reqs
debug: ncs <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size > 
    0), nc)
debug: r <- terra::rast(ncs)
debug: stopifnot(all(class(terra::time(r)) %in% c("POSIXct", "POSIXt")))
debug: idx <- dplyr::pull(dplyr::filter(dplyr::arrange(dplyr::tibble(idx = 1:terra::nlyr(r), 
    time = terra::time(r)), time), !duplicated(time)), idx)
debug: r <- terra::subset(r, idx)
debug: stopifnot(terra::crs(r, proj = T) == wgs84)
debug: if (mask_tif) r <- terra::mask(r, sf_zones)
debug: lyrs <- glue("{var}|{terra::time(r)}")
debug: if (length(dims_other) > 0 && !all(length(dims[dims_other]) == 
    1)) stop(glue("Other dimensions not yet supported: {paste(dims_other, collapse = ',')}"))
debug: names(r) <- lyrs
debug: if (!is.null(rast_tif)) {
    if (fs::file_exists(rast_tif)) {
        r_tmp_tif <- tempfile(fileext = ".tif")
        r_tmp <- c(rast(rast_tif), r)
        r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
        terra::writeRaster(r_tmp, r_tmp_tif)
        fs::file_delete(rast_tif)
        fs::file_move(r_tmp_tif, rast_tif)
        rm(r)
        rm(r_tmp)
    }
    else {
        terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
    }
    r <- terra::rast(rast_tif)
}
debug: if (fs::file_exists(rast_tif)) {
    r_tmp_tif <- tempfile(fileext = ".tif")
    r_tmp <- c(rast(rast_tif), r)
    r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
    terra::writeRaster(r_tmp, r_tmp_tif)
    fs::file_delete(rast_tif)
    fs::file_move(r_tmp_tif, rast_tif)
    rm(r)
    rm(r_tmp)
} else {
    terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
}
debug: terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
debug: r <- terra::rast(rast_tif)
debug: d_r <- mutate(tidyr::pivot_longer(sf::st_drop_geometry(sf::st_as_sf(terra::zonal(x = r, 
    z = terra::vect(dplyr::select(sf_zones, dplyr::all_of(fld_zones))), 
    fun = zonal_fun, exact = T, na.rm = T, as.polygons = T))), 
    cols = -dplyr::any_of(fld_zones), names_to = "lyr", values_to = zonal_fun), 
    time = readr::parse_datetime(str_replace(lyr, glue("{var}\\|(.*)"), 
        "\\1")))
debug: if (!is.null(zonal_csv)) write_csv(d_r, zonal_csv)
debug: write_csv(d_r, zonal_csv)
debug: if (!keep_nc) unlink(dir_nc, recursive = T)
debug: unlink(dir_nc, recursive = T)
debug: return(d_r)
Downloading 1 requests, up to 125 time slices each
Called from: extractr::ed_extract(ed, var = v, sf_zones = ply, bbox = bb, 
    mask_tif = F, rast_tif = glue("{dir_out}/{nms}/{yr}.tif"), 
    zonal_fun = "mean", zonal_csv = glue("{dir_out}/{nms}/{yr}.csv"), 
    dir_nc = glue("{dir_out}/{nms}/{yr}_nc"), keep_nc = F, n_max_vals_per_req = 1e+05, 
    time_min = time_min, time_max = time_max, verbose = T)
debug: while (i_req <= n_reqs) {
    i_t_beg <- (i_req - 1) * n_t_per_req + 1
    i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
    t_req <- times_todo[c(i_t_beg, i_t_end)]
    t_req_str <- format_ISO8601(t_req, usetz = "Z")
    if (verbose) 
        message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
    ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
        ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
        0), nc)
    unlink(ncs0)
    nc_retry <- T
    nc_n_try <- 1
    n_max_retries
    while (nc_retry) {
        res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
            url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
                bbox[["xmax"]]), latitude = c(bbox[["ymin"]], 
                bbox[["ymax"]]), time = t_req_str, fmt = "nc", 
            store = rerddap::disk(path = dir_nc)))
        if (inherits(res, "try-error")) {
            err <- attr(res, "condition")
            msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
            nc_n_try <- nc_n_try + 1
            if (nc_n_try > n_max_retries) {
                stop(msg)
            }
            else {
                message(msg, "\nRETRYing...")
                Sys.sleep(1)
            }
        }
        else {
            nc_retry <- F
        }
    }
    i_req <- i_req + 1
}
debug: i_t_beg <- (i_req - 1) * n_t_per_req + 1
debug: i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
debug: t_req <- times_todo[c(i_t_beg, i_t_end)]
debug: t_req_str <- format_ISO8601(t_req, usetz = "Z")
debug: if (verbose) message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
debug: message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
Fetching request 1 of 1 (2020-01-01 to 2020-12-01) ~ 19:36:20 UTC
debug: ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
    0), nc)
debug: unlink(ncs0)
debug: nc_retry <- T
debug: nc_n_try <- 1
debug: n_max_retries
debug: while (nc_retry) {
    res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
        url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
            bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
        time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
    if (inherits(res, "try-error")) {
        err <- attr(res, "condition")
        msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
        nc_n_try <- nc_n_try + 1
        if (nc_n_try > n_max_retries) {
            stop(msg)
        }
        else {
            message(msg, "\nRETRYing...")
            Sys.sleep(1)
        }
    }
    else {
        nc_retry <- F
    }
}
debug: res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
    url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
        bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
    time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
debug: if (inherits(res, "try-error")) {
    err <- attr(res, "condition")
    msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
    nc_n_try <- nc_n_try + 1
    if (nc_n_try > n_max_retries) {
        stop(msg)
    }
    else {
        message(msg, "\nRETRYing...")
        Sys.sleep(1)
    }
} else {
    nc_retry <- F
}
debug: nc_retry <- F
debug: (while) nc_retry
debug: i_req <- i_req + 1
debug: (while) i_req <= n_reqs
debug: ncs <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size > 
    0), nc)
debug: r <- terra::rast(ncs)
debug: stopifnot(all(class(terra::time(r)) %in% c("POSIXct", "POSIXt")))
debug: idx <- dplyr::pull(dplyr::filter(dplyr::arrange(dplyr::tibble(idx = 1:terra::nlyr(r), 
    time = terra::time(r)), time), !duplicated(time)), idx)
debug: r <- terra::subset(r, idx)
debug: stopifnot(terra::crs(r, proj = T) == wgs84)
debug: if (mask_tif) r <- terra::mask(r, sf_zones)
debug: lyrs <- glue("{var}|{terra::time(r)}")
debug: if (length(dims_other) > 0 && !all(length(dims[dims_other]) == 
    1)) stop(glue("Other dimensions not yet supported: {paste(dims_other, collapse = ',')}"))
debug: names(r) <- lyrs
debug: if (!is.null(rast_tif)) {
    if (fs::file_exists(rast_tif)) {
        r_tmp_tif <- tempfile(fileext = ".tif")
        r_tmp <- c(rast(rast_tif), r)
        r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
        terra::writeRaster(r_tmp, r_tmp_tif)
        fs::file_delete(rast_tif)
        fs::file_move(r_tmp_tif, rast_tif)
        rm(r)
        rm(r_tmp)
    }
    else {
        terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
    }
    r <- terra::rast(rast_tif)
}
debug: if (fs::file_exists(rast_tif)) {
    r_tmp_tif <- tempfile(fileext = ".tif")
    r_tmp <- c(rast(rast_tif), r)
    r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
    terra::writeRaster(r_tmp, r_tmp_tif)
    fs::file_delete(rast_tif)
    fs::file_move(r_tmp_tif, rast_tif)
    rm(r)
    rm(r_tmp)
} else {
    terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
}
debug: terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
debug: r <- terra::rast(rast_tif)
debug: d_r <- mutate(tidyr::pivot_longer(sf::st_drop_geometry(sf::st_as_sf(terra::zonal(x = r, 
    z = terra::vect(dplyr::select(sf_zones, dplyr::all_of(fld_zones))), 
    fun = zonal_fun, exact = T, na.rm = T, as.polygons = T))), 
    cols = -dplyr::any_of(fld_zones), names_to = "lyr", values_to = zonal_fun), 
    time = readr::parse_datetime(str_replace(lyr, glue("{var}\\|(.*)"), 
        "\\1")))
debug: if (!is.null(zonal_csv)) write_csv(d_r, zonal_csv)
debug: write_csv(d_r, zonal_csv)
debug: if (!keep_nc) unlink(dir_nc, recursive = T)
debug: unlink(dir_nc, recursive = T)
debug: return(d_r)
Downloading 1 requests, up to 125 time slices each
Called from: extractr::ed_extract(ed, var = v, sf_zones = ply, bbox = bb, 
    mask_tif = F, rast_tif = glue("{dir_out}/{nms}/{yr}.tif"), 
    zonal_fun = "mean", zonal_csv = glue("{dir_out}/{nms}/{yr}.csv"), 
    dir_nc = glue("{dir_out}/{nms}/{yr}_nc"), keep_nc = F, n_max_vals_per_req = 1e+05, 
    time_min = time_min, time_max = time_max, verbose = T)
debug: while (i_req <= n_reqs) {
    i_t_beg <- (i_req - 1) * n_t_per_req + 1
    i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
    t_req <- times_todo[c(i_t_beg, i_t_end)]
    t_req_str <- format_ISO8601(t_req, usetz = "Z")
    if (verbose) 
        message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
    ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
        ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
        0), nc)
    unlink(ncs0)
    nc_retry <- T
    nc_n_try <- 1
    n_max_retries
    while (nc_retry) {
        res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
            url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
                bbox[["xmax"]]), latitude = c(bbox[["ymin"]], 
                bbox[["ymax"]]), time = t_req_str, fmt = "nc", 
            store = rerddap::disk(path = dir_nc)))
        if (inherits(res, "try-error")) {
            err <- attr(res, "condition")
            msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
            nc_n_try <- nc_n_try + 1
            if (nc_n_try > n_max_retries) {
                stop(msg)
            }
            else {
                message(msg, "\nRETRYing...")
                Sys.sleep(1)
            }
        }
        else {
            nc_retry <- F
        }
    }
    i_req <- i_req + 1
}
debug: i_t_beg <- (i_req - 1) * n_t_per_req + 1
debug: i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
debug: t_req <- times_todo[c(i_t_beg, i_t_end)]
debug: t_req_str <- format_ISO8601(t_req, usetz = "Z")
debug: if (verbose) message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
debug: message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
Fetching request 1 of 1 (2021-01-01 to 2021-12-01) ~ 19:36:23 UTC
debug: ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
    0), nc)
debug: unlink(ncs0)
debug: nc_retry <- T
debug: nc_n_try <- 1
debug: n_max_retries
debug: while (nc_retry) {
    res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
        url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
            bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
        time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
    if (inherits(res, "try-error")) {
        err <- attr(res, "condition")
        msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
        nc_n_try <- nc_n_try + 1
        if (nc_n_try > n_max_retries) {
            stop(msg)
        }
        else {
            message(msg, "\nRETRYing...")
            Sys.sleep(1)
        }
    }
    else {
        nc_retry <- F
    }
}
debug: res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
    url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
        bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
    time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
debug: if (inherits(res, "try-error")) {
    err <- attr(res, "condition")
    msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
    nc_n_try <- nc_n_try + 1
    if (nc_n_try > n_max_retries) {
        stop(msg)
    }
    else {
        message(msg, "\nRETRYing...")
        Sys.sleep(1)
    }
} else {
    nc_retry <- F
}
debug: nc_retry <- F
debug: (while) nc_retry
debug: i_req <- i_req + 1
debug: (while) i_req <= n_reqs
debug: ncs <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size > 
    0), nc)
debug: r <- terra::rast(ncs)
debug: stopifnot(all(class(terra::time(r)) %in% c("POSIXct", "POSIXt")))
debug: idx <- dplyr::pull(dplyr::filter(dplyr::arrange(dplyr::tibble(idx = 1:terra::nlyr(r), 
    time = terra::time(r)), time), !duplicated(time)), idx)
debug: r <- terra::subset(r, idx)
debug: stopifnot(terra::crs(r, proj = T) == wgs84)
debug: if (mask_tif) r <- terra::mask(r, sf_zones)
debug: lyrs <- glue("{var}|{terra::time(r)}")
debug: if (length(dims_other) > 0 && !all(length(dims[dims_other]) == 
    1)) stop(glue("Other dimensions not yet supported: {paste(dims_other, collapse = ',')}"))
debug: names(r) <- lyrs
debug: if (!is.null(rast_tif)) {
    if (fs::file_exists(rast_tif)) {
        r_tmp_tif <- tempfile(fileext = ".tif")
        r_tmp <- c(rast(rast_tif), r)
        r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
        terra::writeRaster(r_tmp, r_tmp_tif)
        fs::file_delete(rast_tif)
        fs::file_move(r_tmp_tif, rast_tif)
        rm(r)
        rm(r_tmp)
    }
    else {
        terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
    }
    r <- terra::rast(rast_tif)
}
debug: if (fs::file_exists(rast_tif)) {
    r_tmp_tif <- tempfile(fileext = ".tif")
    r_tmp <- c(rast(rast_tif), r)
    r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
    terra::writeRaster(r_tmp, r_tmp_tif)
    fs::file_delete(rast_tif)
    fs::file_move(r_tmp_tif, rast_tif)
    rm(r)
    rm(r_tmp)
} else {
    terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
}
debug: terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
debug: r <- terra::rast(rast_tif)
debug: d_r <- mutate(tidyr::pivot_longer(sf::st_drop_geometry(sf::st_as_sf(terra::zonal(x = r, 
    z = terra::vect(dplyr::select(sf_zones, dplyr::all_of(fld_zones))), 
    fun = zonal_fun, exact = T, na.rm = T, as.polygons = T))), 
    cols = -dplyr::any_of(fld_zones), names_to = "lyr", values_to = zonal_fun), 
    time = readr::parse_datetime(str_replace(lyr, glue("{var}\\|(.*)"), 
        "\\1")))
debug: if (!is.null(zonal_csv)) write_csv(d_r, zonal_csv)
debug: write_csv(d_r, zonal_csv)
debug: if (!keep_nc) unlink(dir_nc, recursive = T)
debug: unlink(dir_nc, recursive = T)
debug: return(d_r)
Downloading 1 requests, up to 125 time slices each
Called from: extractr::ed_extract(ed, var = v, sf_zones = ply, bbox = bb, 
    mask_tif = F, rast_tif = glue("{dir_out}/{nms}/{yr}.tif"), 
    zonal_fun = "mean", zonal_csv = glue("{dir_out}/{nms}/{yr}.csv"), 
    dir_nc = glue("{dir_out}/{nms}/{yr}_nc"), keep_nc = F, n_max_vals_per_req = 1e+05, 
    time_min = time_min, time_max = time_max, verbose = T)
debug: while (i_req <= n_reqs) {
    i_t_beg <- (i_req - 1) * n_t_per_req + 1
    i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
    t_req <- times_todo[c(i_t_beg, i_t_end)]
    t_req_str <- format_ISO8601(t_req, usetz = "Z")
    if (verbose) 
        message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
    ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
        ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
        0), nc)
    unlink(ncs0)
    nc_retry <- T
    nc_n_try <- 1
    n_max_retries
    while (nc_retry) {
        res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
            url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
                bbox[["xmax"]]), latitude = c(bbox[["ymin"]], 
                bbox[["ymax"]]), time = t_req_str, fmt = "nc", 
            store = rerddap::disk(path = dir_nc)))
        if (inherits(res, "try-error")) {
            err <- attr(res, "condition")
            msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
            nc_n_try <- nc_n_try + 1
            if (nc_n_try > n_max_retries) {
                stop(msg)
            }
            else {
                message(msg, "\nRETRYing...")
                Sys.sleep(1)
            }
        }
        else {
            nc_retry <- F
        }
    }
    i_req <- i_req + 1
}
debug: i_t_beg <- (i_req - 1) * n_t_per_req + 1
debug: i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
debug: t_req <- times_todo[c(i_t_beg, i_t_end)]
debug: t_req_str <- format_ISO8601(t_req, usetz = "Z")
debug: if (verbose) message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
debug: message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
Fetching request 1 of 1 (2022-01-01 to 2022-12-01) ~ 19:36:26 UTC
debug: ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
    0), nc)
debug: unlink(ncs0)
debug: nc_retry <- T
debug: nc_n_try <- 1
debug: n_max_retries
debug: while (nc_retry) {
    res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
        url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
            bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
        time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
    if (inherits(res, "try-error")) {
        err <- attr(res, "condition")
        msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
        nc_n_try <- nc_n_try + 1
        if (nc_n_try > n_max_retries) {
            stop(msg)
        }
        else {
            message(msg, "\nRETRYing...")
            Sys.sleep(1)
        }
    }
    else {
        nc_retry <- F
    }
}
debug: res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
    url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
        bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
    time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
debug: if (inherits(res, "try-error")) {
    err <- attr(res, "condition")
    msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
    nc_n_try <- nc_n_try + 1
    if (nc_n_try > n_max_retries) {
        stop(msg)
    }
    else {
        message(msg, "\nRETRYing...")
        Sys.sleep(1)
    }
} else {
    nc_retry <- F
}
debug: nc_retry <- F
debug: (while) nc_retry
debug: i_req <- i_req + 1
debug: (while) i_req <= n_reqs
debug: ncs <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size > 
    0), nc)
debug: r <- terra::rast(ncs)
debug: stopifnot(all(class(terra::time(r)) %in% c("POSIXct", "POSIXt")))
debug: idx <- dplyr::pull(dplyr::filter(dplyr::arrange(dplyr::tibble(idx = 1:terra::nlyr(r), 
    time = terra::time(r)), time), !duplicated(time)), idx)
debug: r <- terra::subset(r, idx)
debug: stopifnot(terra::crs(r, proj = T) == wgs84)
debug: if (mask_tif) r <- terra::mask(r, sf_zones)
debug: lyrs <- glue("{var}|{terra::time(r)}")
debug: if (length(dims_other) > 0 && !all(length(dims[dims_other]) == 
    1)) stop(glue("Other dimensions not yet supported: {paste(dims_other, collapse = ',')}"))
debug: names(r) <- lyrs
debug: if (!is.null(rast_tif)) {
    if (fs::file_exists(rast_tif)) {
        r_tmp_tif <- tempfile(fileext = ".tif")
        r_tmp <- c(rast(rast_tif), r)
        r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
        terra::writeRaster(r_tmp, r_tmp_tif)
        fs::file_delete(rast_tif)
        fs::file_move(r_tmp_tif, rast_tif)
        rm(r)
        rm(r_tmp)
    }
    else {
        terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
    }
    r <- terra::rast(rast_tif)
}
debug: if (fs::file_exists(rast_tif)) {
    r_tmp_tif <- tempfile(fileext = ".tif")
    r_tmp <- c(rast(rast_tif), r)
    r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
    terra::writeRaster(r_tmp, r_tmp_tif)
    fs::file_delete(rast_tif)
    fs::file_move(r_tmp_tif, rast_tif)
    rm(r)
    rm(r_tmp)
} else {
    terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
}
debug: terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
debug: r <- terra::rast(rast_tif)
debug: d_r <- mutate(tidyr::pivot_longer(sf::st_drop_geometry(sf::st_as_sf(terra::zonal(x = r, 
    z = terra::vect(dplyr::select(sf_zones, dplyr::all_of(fld_zones))), 
    fun = zonal_fun, exact = T, na.rm = T, as.polygons = T))), 
    cols = -dplyr::any_of(fld_zones), names_to = "lyr", values_to = zonal_fun), 
    time = readr::parse_datetime(str_replace(lyr, glue("{var}\\|(.*)"), 
        "\\1")))
debug: if (!is.null(zonal_csv)) write_csv(d_r, zonal_csv)
debug: write_csv(d_r, zonal_csv)
debug: if (!keep_nc) unlink(dir_nc, recursive = T)
debug: unlink(dir_nc, recursive = T)
debug: return(d_r)
Downloading 1 requests, up to 125 time slices each
Called from: extractr::ed_extract(ed, var = v, sf_zones = ply, bbox = bb, 
    mask_tif = F, rast_tif = glue("{dir_out}/{nms}/{yr}.tif"), 
    zonal_fun = "mean", zonal_csv = glue("{dir_out}/{nms}/{yr}.csv"), 
    dir_nc = glue("{dir_out}/{nms}/{yr}_nc"), keep_nc = F, n_max_vals_per_req = 1e+05, 
    time_min = time_min, time_max = time_max, verbose = T)
debug: while (i_req <= n_reqs) {
    i_t_beg <- (i_req - 1) * n_t_per_req + 1
    i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
    t_req <- times_todo[c(i_t_beg, i_t_end)]
    t_req_str <- format_ISO8601(t_req, usetz = "Z")
    if (verbose) 
        message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
    ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
        ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
        0), nc)
    unlink(ncs0)
    nc_retry <- T
    nc_n_try <- 1
    n_max_retries
    while (nc_retry) {
        res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
            url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
                bbox[["xmax"]]), latitude = c(bbox[["ymin"]], 
                bbox[["ymax"]]), time = t_req_str, fmt = "nc", 
            store = rerddap::disk(path = dir_nc)))
        if (inherits(res, "try-error")) {
            err <- attr(res, "condition")
            msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
            nc_n_try <- nc_n_try + 1
            if (nc_n_try > n_max_retries) {
                stop(msg)
            }
            else {
                message(msg, "\nRETRYing...")
                Sys.sleep(1)
            }
        }
        else {
            nc_retry <- F
        }
    }
    i_req <- i_req + 1
}
debug: i_t_beg <- (i_req - 1) * n_t_per_req + 1
debug: i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
debug: t_req <- times_todo[c(i_t_beg, i_t_end)]
debug: t_req_str <- format_ISO8601(t_req, usetz = "Z")
debug: if (verbose) message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
debug: message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
Fetching request 1 of 1 (2023-01-01 to 2023-12-01) ~ 19:36:29 UTC
debug: ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
    0), nc)
debug: unlink(ncs0)
debug: nc_retry <- T
debug: nc_n_try <- 1
debug: n_max_retries
debug: while (nc_retry) {
    res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
        url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
            bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
        time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
    if (inherits(res, "try-error")) {
        err <- attr(res, "condition")
        msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
        nc_n_try <- nc_n_try + 1
        if (nc_n_try > n_max_retries) {
            stop(msg)
        }
        else {
            message(msg, "\nRETRYing...")
            Sys.sleep(1)
        }
    }
    else {
        nc_retry <- F
    }
}
debug: res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
    url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
        bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
    time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
debug: if (inherits(res, "try-error")) {
    err <- attr(res, "condition")
    msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
    nc_n_try <- nc_n_try + 1
    if (nc_n_try > n_max_retries) {
        stop(msg)
    }
    else {
        message(msg, "\nRETRYing...")
        Sys.sleep(1)
    }
} else {
    nc_retry <- F
}
debug: nc_retry <- F
debug: (while) nc_retry
debug: i_req <- i_req + 1
debug: (while) i_req <= n_reqs
debug: ncs <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size > 
    0), nc)
debug: r <- terra::rast(ncs)
debug: stopifnot(all(class(terra::time(r)) %in% c("POSIXct", "POSIXt")))
debug: idx <- dplyr::pull(dplyr::filter(dplyr::arrange(dplyr::tibble(idx = 1:terra::nlyr(r), 
    time = terra::time(r)), time), !duplicated(time)), idx)
debug: r <- terra::subset(r, idx)
debug: stopifnot(terra::crs(r, proj = T) == wgs84)
debug: if (mask_tif) r <- terra::mask(r, sf_zones)
debug: lyrs <- glue("{var}|{terra::time(r)}")
debug: if (length(dims_other) > 0 && !all(length(dims[dims_other]) == 
    1)) stop(glue("Other dimensions not yet supported: {paste(dims_other, collapse = ',')}"))
debug: names(r) <- lyrs
debug: if (!is.null(rast_tif)) {
    if (fs::file_exists(rast_tif)) {
        r_tmp_tif <- tempfile(fileext = ".tif")
        r_tmp <- c(rast(rast_tif), r)
        r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
        terra::writeRaster(r_tmp, r_tmp_tif)
        fs::file_delete(rast_tif)
        fs::file_move(r_tmp_tif, rast_tif)
        rm(r)
        rm(r_tmp)
    }
    else {
        terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
    }
    r <- terra::rast(rast_tif)
}
debug: if (fs::file_exists(rast_tif)) {
    r_tmp_tif <- tempfile(fileext = ".tif")
    r_tmp <- c(rast(rast_tif), r)
    r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
    terra::writeRaster(r_tmp, r_tmp_tif)
    fs::file_delete(rast_tif)
    fs::file_move(r_tmp_tif, rast_tif)
    rm(r)
    rm(r_tmp)
} else {
    terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
}
debug: terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
debug: r <- terra::rast(rast_tif)
debug: d_r <- mutate(tidyr::pivot_longer(sf::st_drop_geometry(sf::st_as_sf(terra::zonal(x = r, 
    z = terra::vect(dplyr::select(sf_zones, dplyr::all_of(fld_zones))), 
    fun = zonal_fun, exact = T, na.rm = T, as.polygons = T))), 
    cols = -dplyr::any_of(fld_zones), names_to = "lyr", values_to = zonal_fun), 
    time = readr::parse_datetime(str_replace(lyr, glue("{var}\\|(.*)"), 
        "\\1")))
debug: if (!is.null(zonal_csv)) write_csv(d_r, zonal_csv)
debug: write_csv(d_r, zonal_csv)
debug: if (!keep_nc) unlink(dir_nc, recursive = T)
debug: unlink(dir_nc, recursive = T)
debug: return(d_r)
Downloading 1 requests, up to 125 time slices each
Called from: extractr::ed_extract(ed, var = v, sf_zones = ply, bbox = bb, 
    mask_tif = F, rast_tif = glue("{dir_out}/{nms}/{yr}.tif"), 
    zonal_fun = "mean", zonal_csv = glue("{dir_out}/{nms}/{yr}.csv"), 
    dir_nc = glue("{dir_out}/{nms}/{yr}_nc"), keep_nc = F, n_max_vals_per_req = 1e+05, 
    time_min = time_min, time_max = time_max, verbose = T)
debug: while (i_req <= n_reqs) {
    i_t_beg <- (i_req - 1) * n_t_per_req + 1
    i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
    t_req <- times_todo[c(i_t_beg, i_t_end)]
    t_req_str <- format_ISO8601(t_req, usetz = "Z")
    if (verbose) 
        message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
    ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
        ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
        0), nc)
    unlink(ncs0)
    nc_retry <- T
    nc_n_try <- 1
    n_max_retries
    while (nc_retry) {
        res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
            url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
                bbox[["xmax"]]), latitude = c(bbox[["ymin"]], 
                bbox[["ymax"]]), time = t_req_str, fmt = "nc", 
            store = rerddap::disk(path = dir_nc)))
        if (inherits(res, "try-error")) {
            err <- attr(res, "condition")
            msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
            nc_n_try <- nc_n_try + 1
            if (nc_n_try > n_max_retries) {
                stop(msg)
            }
            else {
                message(msg, "\nRETRYing...")
                Sys.sleep(1)
            }
        }
        else {
            nc_retry <- F
        }
    }
    i_req <- i_req + 1
}
debug: i_t_beg <- (i_req - 1) * n_t_per_req + 1
debug: i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
debug: t_req <- times_todo[c(i_t_beg, i_t_end)]
debug: t_req_str <- format_ISO8601(t_req, usetz = "Z")
debug: if (verbose) message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
debug: message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
Fetching request 1 of 1 (2024-01-01 to 2024-12-01) ~ 19:36:31 UTC
debug: ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
    0), nc)
debug: unlink(ncs0)
debug: nc_retry <- T
debug: nc_n_try <- 1
debug: n_max_retries
debug: while (nc_retry) {
    res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
        url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
            bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
        time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
    if (inherits(res, "try-error")) {
        err <- attr(res, "condition")
        msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
        nc_n_try <- nc_n_try + 1
        if (nc_n_try > n_max_retries) {
            stop(msg)
        }
        else {
            message(msg, "\nRETRYing...")
            Sys.sleep(1)
        }
    }
    else {
        nc_retry <- F
    }
}
debug: res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
    url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
        bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
    time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
debug: if (inherits(res, "try-error")) {
    err <- attr(res, "condition")
    msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
    nc_n_try <- nc_n_try + 1
    if (nc_n_try > n_max_retries) {
        stop(msg)
    }
    else {
        message(msg, "\nRETRYing...")
        Sys.sleep(1)
    }
} else {
    nc_retry <- F
}
debug: nc_retry <- F
debug: (while) nc_retry
debug: i_req <- i_req + 1
debug: (while) i_req <= n_reqs
debug: ncs <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size > 
    0), nc)
debug: r <- terra::rast(ncs)
debug: stopifnot(all(class(terra::time(r)) %in% c("POSIXct", "POSIXt")))
debug: idx <- dplyr::pull(dplyr::filter(dplyr::arrange(dplyr::tibble(idx = 1:terra::nlyr(r), 
    time = terra::time(r)), time), !duplicated(time)), idx)
debug: r <- terra::subset(r, idx)
debug: stopifnot(terra::crs(r, proj = T) == wgs84)
debug: if (mask_tif) r <- terra::mask(r, sf_zones)
debug: lyrs <- glue("{var}|{terra::time(r)}")
debug: if (length(dims_other) > 0 && !all(length(dims[dims_other]) == 
    1)) stop(glue("Other dimensions not yet supported: {paste(dims_other, collapse = ',')}"))
debug: names(r) <- lyrs
debug: if (!is.null(rast_tif)) {
    if (fs::file_exists(rast_tif)) {
        r_tmp_tif <- tempfile(fileext = ".tif")
        r_tmp <- c(rast(rast_tif), r)
        r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
        terra::writeRaster(r_tmp, r_tmp_tif)
        fs::file_delete(rast_tif)
        fs::file_move(r_tmp_tif, rast_tif)
        rm(r)
        rm(r_tmp)
    }
    else {
        terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
    }
    r <- terra::rast(rast_tif)
}
debug: if (fs::file_exists(rast_tif)) {
    r_tmp_tif <- tempfile(fileext = ".tif")
    r_tmp <- c(rast(rast_tif), r)
    r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
    terra::writeRaster(r_tmp, r_tmp_tif)
    fs::file_delete(rast_tif)
    fs::file_move(r_tmp_tif, rast_tif)
    rm(r)
    rm(r_tmp)
} else {
    terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
}
debug: terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
debug: r <- terra::rast(rast_tif)
debug: d_r <- mutate(tidyr::pivot_longer(sf::st_drop_geometry(sf::st_as_sf(terra::zonal(x = r, 
    z = terra::vect(dplyr::select(sf_zones, dplyr::all_of(fld_zones))), 
    fun = zonal_fun, exact = T, na.rm = T, as.polygons = T))), 
    cols = -dplyr::any_of(fld_zones), names_to = "lyr", values_to = zonal_fun), 
    time = readr::parse_datetime(str_replace(lyr, glue("{var}\\|(.*)"), 
        "\\1")))
debug: if (!is.null(zonal_csv)) write_csv(d_r, zonal_csv)
debug: write_csv(d_r, zonal_csv)
debug: if (!keep_nc) unlink(dir_nc, recursive = T)
debug: unlink(dir_nc, recursive = T)
debug: return(d_r)
Downloading 1 requests, up to 125 time slices each
Called from: extractr::ed_extract(ed, var = v, sf_zones = ply, bbox = bb, 
    mask_tif = F, rast_tif = glue("{dir_out}/{nms}/{yr}.tif"), 
    zonal_fun = "mean", zonal_csv = glue("{dir_out}/{nms}/{yr}.csv"), 
    dir_nc = glue("{dir_out}/{nms}/{yr}_nc"), keep_nc = F, n_max_vals_per_req = 1e+05, 
    time_min = time_min, time_max = time_max, verbose = T)
debug: while (i_req <= n_reqs) {
    i_t_beg <- (i_req - 1) * n_t_per_req + 1
    i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
    t_req <- times_todo[c(i_t_beg, i_t_end)]
    t_req_str <- format_ISO8601(t_req, usetz = "Z")
    if (verbose) 
        message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
    ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
        ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
        0), nc)
    unlink(ncs0)
    nc_retry <- T
    nc_n_try <- 1
    n_max_retries
    while (nc_retry) {
        res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
            url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
                bbox[["xmax"]]), latitude = c(bbox[["ymin"]], 
                bbox[["ymax"]]), time = t_req_str, fmt = "nc", 
            store = rerddap::disk(path = dir_nc)))
        if (inherits(res, "try-error")) {
            err <- attr(res, "condition")
            msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
            nc_n_try <- nc_n_try + 1
            if (nc_n_try > n_max_retries) {
                stop(msg)
            }
            else {
                message(msg, "\nRETRYing...")
                Sys.sleep(1)
            }
        }
        else {
            nc_retry <- F
        }
    }
    i_req <- i_req + 1
}
debug: i_t_beg <- (i_req - 1) * n_t_per_req + 1
debug: i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
debug: t_req <- times_todo[c(i_t_beg, i_t_end)]
debug: t_req_str <- format_ISO8601(t_req, usetz = "Z")
debug: if (verbose) message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
debug: message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
Fetching request 1 of 1 (2025-01-01 to 2025-07-01) ~ 19:36:34 UTC
debug: ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
    0), nc)
debug: unlink(ncs0)
debug: nc_retry <- T
debug: nc_n_try <- 1
debug: n_max_retries
debug: while (nc_retry) {
    res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
        url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
            bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
        time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
    if (inherits(res, "try-error")) {
        err <- attr(res, "condition")
        msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
        nc_n_try <- nc_n_try + 1
        if (nc_n_try > n_max_retries) {
            stop(msg)
        }
        else {
            message(msg, "\nRETRYing...")
            Sys.sleep(1)
        }
    }
    else {
        nc_retry <- F
    }
}
debug: res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
    url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
        bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
    time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
debug: if (inherits(res, "try-error")) {
    err <- attr(res, "condition")
    msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
    nc_n_try <- nc_n_try + 1
    if (nc_n_try > n_max_retries) {
        stop(msg)
    }
    else {
        message(msg, "\nRETRYing...")
        Sys.sleep(1)
    }
} else {
    nc_retry <- F
}
debug: nc_retry <- F
debug: (while) nc_retry
debug: i_req <- i_req + 1
debug: (while) i_req <= n_reqs
debug: ncs <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size > 
    0), nc)
debug: r <- terra::rast(ncs)
debug: stopifnot(all(class(terra::time(r)) %in% c("POSIXct", "POSIXt")))
debug: idx <- dplyr::pull(dplyr::filter(dplyr::arrange(dplyr::tibble(idx = 1:terra::nlyr(r), 
    time = terra::time(r)), time), !duplicated(time)), idx)
debug: r <- terra::subset(r, idx)
debug: stopifnot(terra::crs(r, proj = T) == wgs84)
debug: if (mask_tif) r <- terra::mask(r, sf_zones)
debug: lyrs <- glue("{var}|{terra::time(r)}")
debug: if (length(dims_other) > 0 && !all(length(dims[dims_other]) == 
    1)) stop(glue("Other dimensions not yet supported: {paste(dims_other, collapse = ',')}"))
debug: names(r) <- lyrs
debug: if (!is.null(rast_tif)) {
    if (fs::file_exists(rast_tif)) {
        r_tmp_tif <- tempfile(fileext = ".tif")
        r_tmp <- c(rast(rast_tif), r)
        r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
        terra::writeRaster(r_tmp, r_tmp_tif)
        fs::file_delete(rast_tif)
        fs::file_move(r_tmp_tif, rast_tif)
        rm(r)
        rm(r_tmp)
    }
    else {
        terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
    }
    r <- terra::rast(rast_tif)
}
debug: if (fs::file_exists(rast_tif)) {
    r_tmp_tif <- tempfile(fileext = ".tif")
    r_tmp <- c(rast(rast_tif), r)
    r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
    terra::writeRaster(r_tmp, r_tmp_tif)
    fs::file_delete(rast_tif)
    fs::file_move(r_tmp_tif, rast_tif)
    rm(r)
    rm(r_tmp)
} else {
    terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
}
debug: terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
debug: r <- terra::rast(rast_tif)
debug: d_r <- mutate(tidyr::pivot_longer(sf::st_drop_geometry(sf::st_as_sf(terra::zonal(x = r, 
    z = terra::vect(dplyr::select(sf_zones, dplyr::all_of(fld_zones))), 
    fun = zonal_fun, exact = T, na.rm = T, as.polygons = T))), 
    cols = -dplyr::any_of(fld_zones), names_to = "lyr", values_to = zonal_fun), 
    time = readr::parse_datetime(str_replace(lyr, glue("{var}\\|(.*)"), 
        "\\1")))
debug: if (!is.null(zonal_csv)) write_csv(d_r, zonal_csv)
debug: write_csv(d_r, zonal_csv)
debug: if (!keep_nc) unlink(dir_nc, recursive = T)
debug: unlink(dir_nc, recursive = T)
debug: return(d_r)
Downloading 1 requests, up to 167 time slices each
Called from: extractr::ed_extract(ed, var = v, sf_zones = ply, bbox = bb, 
    mask_tif = F, rast_tif = glue("{dir_out}/{nms}/{yr}.tif"), 
    zonal_fun = "mean", zonal_csv = glue("{dir_out}/{nms}/{yr}.csv"), 
    dir_nc = glue("{dir_out}/{nms}/{yr}_nc"), keep_nc = F, n_max_vals_per_req = 1e+05, 
    time_min = time_min, time_max = time_max, verbose = T)
debug: while (i_req <= n_reqs) {
    i_t_beg <- (i_req - 1) * n_t_per_req + 1
    i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
    t_req <- times_todo[c(i_t_beg, i_t_end)]
    t_req_str <- format_ISO8601(t_req, usetz = "Z")
    if (verbose) 
        message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
    ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
        ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
        0), nc)
    unlink(ncs0)
    nc_retry <- T
    nc_n_try <- 1
    n_max_retries
    while (nc_retry) {
        res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
            url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
                bbox[["xmax"]]), latitude = c(bbox[["ymin"]], 
                bbox[["ymax"]]), time = t_req_str, fmt = "nc", 
            store = rerddap::disk(path = dir_nc)))
        if (inherits(res, "try-error")) {
            err <- attr(res, "condition")
            msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
            nc_n_try <- nc_n_try + 1
            if (nc_n_try > n_max_retries) {
                stop(msg)
            }
            else {
                message(msg, "\nRETRYing...")
                Sys.sleep(1)
            }
        }
        else {
            nc_retry <- F
        }
    }
    i_req <- i_req + 1
}
debug: i_t_beg <- (i_req - 1) * n_t_per_req + 1
debug: i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
debug: t_req <- times_todo[c(i_t_beg, i_t_end)]
debug: t_req_str <- format_ISO8601(t_req, usetz = "Z")
debug: if (verbose) message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
debug: message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
Fetching request 1 of 1 (1998-01-01 to 1998-12-01) ~ 19:36:37 UTC
debug: ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
    0), nc)
debug: unlink(ncs0)
debug: nc_retry <- T
debug: nc_n_try <- 1
debug: n_max_retries
debug: while (nc_retry) {
    res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
        url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
            bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
        time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
    if (inherits(res, "try-error")) {
        err <- attr(res, "condition")
        msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
        nc_n_try <- nc_n_try + 1
        if (nc_n_try > n_max_retries) {
            stop(msg)
        }
        else {
            message(msg, "\nRETRYing...")
            Sys.sleep(1)
        }
    }
    else {
        nc_retry <- F
    }
}
debug: res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
    url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
        bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
    time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
debug: if (inherits(res, "try-error")) {
    err <- attr(res, "condition")
    msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
    nc_n_try <- nc_n_try + 1
    if (nc_n_try > n_max_retries) {
        stop(msg)
    }
    else {
        message(msg, "\nRETRYing...")
        Sys.sleep(1)
    }
} else {
    nc_retry <- F
}
debug: nc_retry <- F
debug: (while) nc_retry
debug: i_req <- i_req + 1
debug: (while) i_req <= n_reqs
debug: ncs <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size > 
    0), nc)
debug: r <- terra::rast(ncs)
debug: stopifnot(all(class(terra::time(r)) %in% c("POSIXct", "POSIXt")))
debug: idx <- dplyr::pull(dplyr::filter(dplyr::arrange(dplyr::tibble(idx = 1:terra::nlyr(r), 
    time = terra::time(r)), time), !duplicated(time)), idx)
debug: r <- terra::subset(r, idx)
debug: stopifnot(terra::crs(r, proj = T) == wgs84)
debug: if (mask_tif) r <- terra::mask(r, sf_zones)
debug: lyrs <- glue("{var}|{terra::time(r)}")
debug: if (length(dims_other) > 0 && !all(length(dims[dims_other]) == 
    1)) stop(glue("Other dimensions not yet supported: {paste(dims_other, collapse = ',')}"))
debug: names(r) <- lyrs
debug: if (!is.null(rast_tif)) {
    if (fs::file_exists(rast_tif)) {
        r_tmp_tif <- tempfile(fileext = ".tif")
        r_tmp <- c(rast(rast_tif), r)
        r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
        terra::writeRaster(r_tmp, r_tmp_tif)
        fs::file_delete(rast_tif)
        fs::file_move(r_tmp_tif, rast_tif)
        rm(r)
        rm(r_tmp)
    }
    else {
        terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
    }
    r <- terra::rast(rast_tif)
}
debug: if (fs::file_exists(rast_tif)) {
    r_tmp_tif <- tempfile(fileext = ".tif")
    r_tmp <- c(rast(rast_tif), r)
    r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
    terra::writeRaster(r_tmp, r_tmp_tif)
    fs::file_delete(rast_tif)
    fs::file_move(r_tmp_tif, rast_tif)
    rm(r)
    rm(r_tmp)
} else {
    terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
}
debug: terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
debug: r <- terra::rast(rast_tif)
debug: d_r <- mutate(tidyr::pivot_longer(sf::st_drop_geometry(sf::st_as_sf(terra::zonal(x = r, 
    z = terra::vect(dplyr::select(sf_zones, dplyr::all_of(fld_zones))), 
    fun = zonal_fun, exact = T, na.rm = T, as.polygons = T))), 
    cols = -dplyr::any_of(fld_zones), names_to = "lyr", values_to = zonal_fun), 
    time = readr::parse_datetime(str_replace(lyr, glue("{var}\\|(.*)"), 
        "\\1")))
debug: if (!is.null(zonal_csv)) write_csv(d_r, zonal_csv)
debug: write_csv(d_r, zonal_csv)
debug: if (!keep_nc) unlink(dir_nc, recursive = T)
debug: unlink(dir_nc, recursive = T)
debug: return(d_r)
Downloading 1 requests, up to 167 time slices each
Called from: extractr::ed_extract(ed, var = v, sf_zones = ply, bbox = bb, 
    mask_tif = F, rast_tif = glue("{dir_out}/{nms}/{yr}.tif"), 
    zonal_fun = "mean", zonal_csv = glue("{dir_out}/{nms}/{yr}.csv"), 
    dir_nc = glue("{dir_out}/{nms}/{yr}_nc"), keep_nc = F, n_max_vals_per_req = 1e+05, 
    time_min = time_min, time_max = time_max, verbose = T)
debug: while (i_req <= n_reqs) {
    i_t_beg <- (i_req - 1) * n_t_per_req + 1
    i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
    t_req <- times_todo[c(i_t_beg, i_t_end)]
    t_req_str <- format_ISO8601(t_req, usetz = "Z")
    if (verbose) 
        message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
    ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
        ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
        0), nc)
    unlink(ncs0)
    nc_retry <- T
    nc_n_try <- 1
    n_max_retries
    while (nc_retry) {
        res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
            url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
                bbox[["xmax"]]), latitude = c(bbox[["ymin"]], 
                bbox[["ymax"]]), time = t_req_str, fmt = "nc", 
            store = rerddap::disk(path = dir_nc)))
        if (inherits(res, "try-error")) {
            err <- attr(res, "condition")
            msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
            nc_n_try <- nc_n_try + 1
            if (nc_n_try > n_max_retries) {
                stop(msg)
            }
            else {
                message(msg, "\nRETRYing...")
                Sys.sleep(1)
            }
        }
        else {
            nc_retry <- F
        }
    }
    i_req <- i_req + 1
}
debug: i_t_beg <- (i_req - 1) * n_t_per_req + 1
debug: i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
debug: t_req <- times_todo[c(i_t_beg, i_t_end)]
debug: t_req_str <- format_ISO8601(t_req, usetz = "Z")
debug: if (verbose) message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
debug: message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
Fetching request 1 of 1 (1999-01-01 to 1999-12-01) ~ 19:36:39 UTC
debug: ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
    0), nc)
debug: unlink(ncs0)
debug: nc_retry <- T
debug: nc_n_try <- 1
debug: n_max_retries
debug: while (nc_retry) {
    res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
        url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
            bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
        time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
    if (inherits(res, "try-error")) {
        err <- attr(res, "condition")
        msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
        nc_n_try <- nc_n_try + 1
        if (nc_n_try > n_max_retries) {
            stop(msg)
        }
        else {
            message(msg, "\nRETRYing...")
            Sys.sleep(1)
        }
    }
    else {
        nc_retry <- F
    }
}
debug: res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
    url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
        bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
    time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
debug: if (inherits(res, "try-error")) {
    err <- attr(res, "condition")
    msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
    nc_n_try <- nc_n_try + 1
    if (nc_n_try > n_max_retries) {
        stop(msg)
    }
    else {
        message(msg, "\nRETRYing...")
        Sys.sleep(1)
    }
} else {
    nc_retry <- F
}
debug: nc_retry <- F
debug: (while) nc_retry
debug: i_req <- i_req + 1
debug: (while) i_req <= n_reqs
debug: ncs <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size > 
    0), nc)
debug: r <- terra::rast(ncs)
debug: stopifnot(all(class(terra::time(r)) %in% c("POSIXct", "POSIXt")))
debug: idx <- dplyr::pull(dplyr::filter(dplyr::arrange(dplyr::tibble(idx = 1:terra::nlyr(r), 
    time = terra::time(r)), time), !duplicated(time)), idx)
debug: r <- terra::subset(r, idx)
debug: stopifnot(terra::crs(r, proj = T) == wgs84)
debug: if (mask_tif) r <- terra::mask(r, sf_zones)
debug: lyrs <- glue("{var}|{terra::time(r)}")
debug: if (length(dims_other) > 0 && !all(length(dims[dims_other]) == 
    1)) stop(glue("Other dimensions not yet supported: {paste(dims_other, collapse = ',')}"))
debug: names(r) <- lyrs
debug: if (!is.null(rast_tif)) {
    if (fs::file_exists(rast_tif)) {
        r_tmp_tif <- tempfile(fileext = ".tif")
        r_tmp <- c(rast(rast_tif), r)
        r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
        terra::writeRaster(r_tmp, r_tmp_tif)
        fs::file_delete(rast_tif)
        fs::file_move(r_tmp_tif, rast_tif)
        rm(r)
        rm(r_tmp)
    }
    else {
        terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
    }
    r <- terra::rast(rast_tif)
}
debug: if (fs::file_exists(rast_tif)) {
    r_tmp_tif <- tempfile(fileext = ".tif")
    r_tmp <- c(rast(rast_tif), r)
    r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
    terra::writeRaster(r_tmp, r_tmp_tif)
    fs::file_delete(rast_tif)
    fs::file_move(r_tmp_tif, rast_tif)
    rm(r)
    rm(r_tmp)
} else {
    terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
}
debug: terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
debug: r <- terra::rast(rast_tif)
debug: d_r <- mutate(tidyr::pivot_longer(sf::st_drop_geometry(sf::st_as_sf(terra::zonal(x = r, 
    z = terra::vect(dplyr::select(sf_zones, dplyr::all_of(fld_zones))), 
    fun = zonal_fun, exact = T, na.rm = T, as.polygons = T))), 
    cols = -dplyr::any_of(fld_zones), names_to = "lyr", values_to = zonal_fun), 
    time = readr::parse_datetime(str_replace(lyr, glue("{var}\\|(.*)"), 
        "\\1")))
debug: if (!is.null(zonal_csv)) write_csv(d_r, zonal_csv)
debug: write_csv(d_r, zonal_csv)
debug: if (!keep_nc) unlink(dir_nc, recursive = T)
debug: unlink(dir_nc, recursive = T)
debug: return(d_r)
Downloading 1 requests, up to 167 time slices each
Called from: extractr::ed_extract(ed, var = v, sf_zones = ply, bbox = bb, 
    mask_tif = F, rast_tif = glue("{dir_out}/{nms}/{yr}.tif"), 
    zonal_fun = "mean", zonal_csv = glue("{dir_out}/{nms}/{yr}.csv"), 
    dir_nc = glue("{dir_out}/{nms}/{yr}_nc"), keep_nc = F, n_max_vals_per_req = 1e+05, 
    time_min = time_min, time_max = time_max, verbose = T)
debug: while (i_req <= n_reqs) {
    i_t_beg <- (i_req - 1) * n_t_per_req + 1
    i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
    t_req <- times_todo[c(i_t_beg, i_t_end)]
    t_req_str <- format_ISO8601(t_req, usetz = "Z")
    if (verbose) 
        message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
    ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
        ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
        0), nc)
    unlink(ncs0)
    nc_retry <- T
    nc_n_try <- 1
    n_max_retries
    while (nc_retry) {
        res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
            url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
                bbox[["xmax"]]), latitude = c(bbox[["ymin"]], 
                bbox[["ymax"]]), time = t_req_str, fmt = "nc", 
            store = rerddap::disk(path = dir_nc)))
        if (inherits(res, "try-error")) {
            err <- attr(res, "condition")
            msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
            nc_n_try <- nc_n_try + 1
            if (nc_n_try > n_max_retries) {
                stop(msg)
            }
            else {
                message(msg, "\nRETRYing...")
                Sys.sleep(1)
            }
        }
        else {
            nc_retry <- F
        }
    }
    i_req <- i_req + 1
}
debug: i_t_beg <- (i_req - 1) * n_t_per_req + 1
debug: i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
debug: t_req <- times_todo[c(i_t_beg, i_t_end)]
debug: t_req_str <- format_ISO8601(t_req, usetz = "Z")
debug: if (verbose) message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
debug: message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
Fetching request 1 of 1 (2000-01-01 to 2000-12-01) ~ 19:36:41 UTC
debug: ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
    0), nc)
debug: unlink(ncs0)
debug: nc_retry <- T
debug: nc_n_try <- 1
debug: n_max_retries
debug: while (nc_retry) {
    res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
        url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
            bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
        time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
    if (inherits(res, "try-error")) {
        err <- attr(res, "condition")
        msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
        nc_n_try <- nc_n_try + 1
        if (nc_n_try > n_max_retries) {
            stop(msg)
        }
        else {
            message(msg, "\nRETRYing...")
            Sys.sleep(1)
        }
    }
    else {
        nc_retry <- F
    }
}
debug: res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
    url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
        bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
    time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
debug: if (inherits(res, "try-error")) {
    err <- attr(res, "condition")
    msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
    nc_n_try <- nc_n_try + 1
    if (nc_n_try > n_max_retries) {
        stop(msg)
    }
    else {
        message(msg, "\nRETRYing...")
        Sys.sleep(1)
    }
} else {
    nc_retry <- F
}
debug: nc_retry <- F
debug: (while) nc_retry
debug: i_req <- i_req + 1
debug: (while) i_req <= n_reqs
debug: ncs <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size > 
    0), nc)
debug: r <- terra::rast(ncs)
debug: stopifnot(all(class(terra::time(r)) %in% c("POSIXct", "POSIXt")))
debug: idx <- dplyr::pull(dplyr::filter(dplyr::arrange(dplyr::tibble(idx = 1:terra::nlyr(r), 
    time = terra::time(r)), time), !duplicated(time)), idx)
debug: r <- terra::subset(r, idx)
debug: stopifnot(terra::crs(r, proj = T) == wgs84)
debug: if (mask_tif) r <- terra::mask(r, sf_zones)
debug: lyrs <- glue("{var}|{terra::time(r)}")
debug: if (length(dims_other) > 0 && !all(length(dims[dims_other]) == 
    1)) stop(glue("Other dimensions not yet supported: {paste(dims_other, collapse = ',')}"))
debug: names(r) <- lyrs
debug: if (!is.null(rast_tif)) {
    if (fs::file_exists(rast_tif)) {
        r_tmp_tif <- tempfile(fileext = ".tif")
        r_tmp <- c(rast(rast_tif), r)
        r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
        terra::writeRaster(r_tmp, r_tmp_tif)
        fs::file_delete(rast_tif)
        fs::file_move(r_tmp_tif, rast_tif)
        rm(r)
        rm(r_tmp)
    }
    else {
        terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
    }
    r <- terra::rast(rast_tif)
}
debug: if (fs::file_exists(rast_tif)) {
    r_tmp_tif <- tempfile(fileext = ".tif")
    r_tmp <- c(rast(rast_tif), r)
    r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
    terra::writeRaster(r_tmp, r_tmp_tif)
    fs::file_delete(rast_tif)
    fs::file_move(r_tmp_tif, rast_tif)
    rm(r)
    rm(r_tmp)
} else {
    terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
}
debug: terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
debug: r <- terra::rast(rast_tif)
debug: d_r <- mutate(tidyr::pivot_longer(sf::st_drop_geometry(sf::st_as_sf(terra::zonal(x = r, 
    z = terra::vect(dplyr::select(sf_zones, dplyr::all_of(fld_zones))), 
    fun = zonal_fun, exact = T, na.rm = T, as.polygons = T))), 
    cols = -dplyr::any_of(fld_zones), names_to = "lyr", values_to = zonal_fun), 
    time = readr::parse_datetime(str_replace(lyr, glue("{var}\\|(.*)"), 
        "\\1")))
debug: if (!is.null(zonal_csv)) write_csv(d_r, zonal_csv)
debug: write_csv(d_r, zonal_csv)
debug: if (!keep_nc) unlink(dir_nc, recursive = T)
debug: unlink(dir_nc, recursive = T)
debug: return(d_r)
Downloading 1 requests, up to 167 time slices each
Called from: extractr::ed_extract(ed, var = v, sf_zones = ply, bbox = bb, 
    mask_tif = F, rast_tif = glue("{dir_out}/{nms}/{yr}.tif"), 
    zonal_fun = "mean", zonal_csv = glue("{dir_out}/{nms}/{yr}.csv"), 
    dir_nc = glue("{dir_out}/{nms}/{yr}_nc"), keep_nc = F, n_max_vals_per_req = 1e+05, 
    time_min = time_min, time_max = time_max, verbose = T)
debug: while (i_req <= n_reqs) {
    i_t_beg <- (i_req - 1) * n_t_per_req + 1
    i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
    t_req <- times_todo[c(i_t_beg, i_t_end)]
    t_req_str <- format_ISO8601(t_req, usetz = "Z")
    if (verbose) 
        message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
    ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
        ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
        0), nc)
    unlink(ncs0)
    nc_retry <- T
    nc_n_try <- 1
    n_max_retries
    while (nc_retry) {
        res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
            url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
                bbox[["xmax"]]), latitude = c(bbox[["ymin"]], 
                bbox[["ymax"]]), time = t_req_str, fmt = "nc", 
            store = rerddap::disk(path = dir_nc)))
        if (inherits(res, "try-error")) {
            err <- attr(res, "condition")
            msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
            nc_n_try <- nc_n_try + 1
            if (nc_n_try > n_max_retries) {
                stop(msg)
            }
            else {
                message(msg, "\nRETRYing...")
                Sys.sleep(1)
            }
        }
        else {
            nc_retry <- F
        }
    }
    i_req <- i_req + 1
}
debug: i_t_beg <- (i_req - 1) * n_t_per_req + 1
debug: i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
debug: t_req <- times_todo[c(i_t_beg, i_t_end)]
debug: t_req_str <- format_ISO8601(t_req, usetz = "Z")
debug: if (verbose) message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
debug: message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
Fetching request 1 of 1 (2001-01-01 to 2001-12-01) ~ 19:36:44 UTC
debug: ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
    0), nc)
debug: unlink(ncs0)
debug: nc_retry <- T
debug: nc_n_try <- 1
debug: n_max_retries
debug: while (nc_retry) {
    res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
        url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
            bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
        time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
    if (inherits(res, "try-error")) {
        err <- attr(res, "condition")
        msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
        nc_n_try <- nc_n_try + 1
        if (nc_n_try > n_max_retries) {
            stop(msg)
        }
        else {
            message(msg, "\nRETRYing...")
            Sys.sleep(1)
        }
    }
    else {
        nc_retry <- F
    }
}
debug: res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
    url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
        bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
    time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
debug: if (inherits(res, "try-error")) {
    err <- attr(res, "condition")
    msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
    nc_n_try <- nc_n_try + 1
    if (nc_n_try > n_max_retries) {
        stop(msg)
    }
    else {
        message(msg, "\nRETRYing...")
        Sys.sleep(1)
    }
} else {
    nc_retry <- F
}
debug: nc_retry <- F
debug: (while) nc_retry
debug: i_req <- i_req + 1
debug: (while) i_req <= n_reqs
debug: ncs <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size > 
    0), nc)
debug: r <- terra::rast(ncs)
debug: stopifnot(all(class(terra::time(r)) %in% c("POSIXct", "POSIXt")))
debug: idx <- dplyr::pull(dplyr::filter(dplyr::arrange(dplyr::tibble(idx = 1:terra::nlyr(r), 
    time = terra::time(r)), time), !duplicated(time)), idx)
debug: r <- terra::subset(r, idx)
debug: stopifnot(terra::crs(r, proj = T) == wgs84)
debug: if (mask_tif) r <- terra::mask(r, sf_zones)
debug: lyrs <- glue("{var}|{terra::time(r)}")
debug: if (length(dims_other) > 0 && !all(length(dims[dims_other]) == 
    1)) stop(glue("Other dimensions not yet supported: {paste(dims_other, collapse = ',')}"))
debug: names(r) <- lyrs
debug: if (!is.null(rast_tif)) {
    if (fs::file_exists(rast_tif)) {
        r_tmp_tif <- tempfile(fileext = ".tif")
        r_tmp <- c(rast(rast_tif), r)
        r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
        terra::writeRaster(r_tmp, r_tmp_tif)
        fs::file_delete(rast_tif)
        fs::file_move(r_tmp_tif, rast_tif)
        rm(r)
        rm(r_tmp)
    }
    else {
        terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
    }
    r <- terra::rast(rast_tif)
}
debug: if (fs::file_exists(rast_tif)) {
    r_tmp_tif <- tempfile(fileext = ".tif")
    r_tmp <- c(rast(rast_tif), r)
    r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
    terra::writeRaster(r_tmp, r_tmp_tif)
    fs::file_delete(rast_tif)
    fs::file_move(r_tmp_tif, rast_tif)
    rm(r)
    rm(r_tmp)
} else {
    terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
}
debug: terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
debug: r <- terra::rast(rast_tif)
debug: d_r <- mutate(tidyr::pivot_longer(sf::st_drop_geometry(sf::st_as_sf(terra::zonal(x = r, 
    z = terra::vect(dplyr::select(sf_zones, dplyr::all_of(fld_zones))), 
    fun = zonal_fun, exact = T, na.rm = T, as.polygons = T))), 
    cols = -dplyr::any_of(fld_zones), names_to = "lyr", values_to = zonal_fun), 
    time = readr::parse_datetime(str_replace(lyr, glue("{var}\\|(.*)"), 
        "\\1")))
debug: if (!is.null(zonal_csv)) write_csv(d_r, zonal_csv)
debug: write_csv(d_r, zonal_csv)
debug: if (!keep_nc) unlink(dir_nc, recursive = T)
debug: unlink(dir_nc, recursive = T)
debug: return(d_r)
Downloading 1 requests, up to 167 time slices each
Called from: extractr::ed_extract(ed, var = v, sf_zones = ply, bbox = bb, 
    mask_tif = F, rast_tif = glue("{dir_out}/{nms}/{yr}.tif"), 
    zonal_fun = "mean", zonal_csv = glue("{dir_out}/{nms}/{yr}.csv"), 
    dir_nc = glue("{dir_out}/{nms}/{yr}_nc"), keep_nc = F, n_max_vals_per_req = 1e+05, 
    time_min = time_min, time_max = time_max, verbose = T)
debug: while (i_req <= n_reqs) {
    i_t_beg <- (i_req - 1) * n_t_per_req + 1
    i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
    t_req <- times_todo[c(i_t_beg, i_t_end)]
    t_req_str <- format_ISO8601(t_req, usetz = "Z")
    if (verbose) 
        message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
    ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
        ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
        0), nc)
    unlink(ncs0)
    nc_retry <- T
    nc_n_try <- 1
    n_max_retries
    while (nc_retry) {
        res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
            url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
                bbox[["xmax"]]), latitude = c(bbox[["ymin"]], 
                bbox[["ymax"]]), time = t_req_str, fmt = "nc", 
            store = rerddap::disk(path = dir_nc)))
        if (inherits(res, "try-error")) {
            err <- attr(res, "condition")
            msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
            nc_n_try <- nc_n_try + 1
            if (nc_n_try > n_max_retries) {
                stop(msg)
            }
            else {
                message(msg, "\nRETRYing...")
                Sys.sleep(1)
            }
        }
        else {
            nc_retry <- F
        }
    }
    i_req <- i_req + 1
}
debug: i_t_beg <- (i_req - 1) * n_t_per_req + 1
debug: i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
debug: t_req <- times_todo[c(i_t_beg, i_t_end)]
debug: t_req_str <- format_ISO8601(t_req, usetz = "Z")
debug: if (verbose) message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
debug: message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
Fetching request 1 of 1 (2002-01-01 to 2002-12-01) ~ 19:36:46 UTC
debug: ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
    0), nc)
debug: unlink(ncs0)
debug: nc_retry <- T
debug: nc_n_try <- 1
debug: n_max_retries
debug: while (nc_retry) {
    res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
        url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
            bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
        time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
    if (inherits(res, "try-error")) {
        err <- attr(res, "condition")
        msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
        nc_n_try <- nc_n_try + 1
        if (nc_n_try > n_max_retries) {
            stop(msg)
        }
        else {
            message(msg, "\nRETRYing...")
            Sys.sleep(1)
        }
    }
    else {
        nc_retry <- F
    }
}
debug: res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
    url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
        bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
    time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
debug: if (inherits(res, "try-error")) {
    err <- attr(res, "condition")
    msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
    nc_n_try <- nc_n_try + 1
    if (nc_n_try > n_max_retries) {
        stop(msg)
    }
    else {
        message(msg, "\nRETRYing...")
        Sys.sleep(1)
    }
} else {
    nc_retry <- F
}
debug: nc_retry <- F
debug: (while) nc_retry
debug: i_req <- i_req + 1
debug: (while) i_req <= n_reqs
debug: ncs <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size > 
    0), nc)
debug: r <- terra::rast(ncs)
debug: stopifnot(all(class(terra::time(r)) %in% c("POSIXct", "POSIXt")))
debug: idx <- dplyr::pull(dplyr::filter(dplyr::arrange(dplyr::tibble(idx = 1:terra::nlyr(r), 
    time = terra::time(r)), time), !duplicated(time)), idx)
debug: r <- terra::subset(r, idx)
debug: stopifnot(terra::crs(r, proj = T) == wgs84)
debug: if (mask_tif) r <- terra::mask(r, sf_zones)
debug: lyrs <- glue("{var}|{terra::time(r)}")
debug: if (length(dims_other) > 0 && !all(length(dims[dims_other]) == 
    1)) stop(glue("Other dimensions not yet supported: {paste(dims_other, collapse = ',')}"))
debug: names(r) <- lyrs
debug: if (!is.null(rast_tif)) {
    if (fs::file_exists(rast_tif)) {
        r_tmp_tif <- tempfile(fileext = ".tif")
        r_tmp <- c(rast(rast_tif), r)
        r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
        terra::writeRaster(r_tmp, r_tmp_tif)
        fs::file_delete(rast_tif)
        fs::file_move(r_tmp_tif, rast_tif)
        rm(r)
        rm(r_tmp)
    }
    else {
        terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
    }
    r <- terra::rast(rast_tif)
}
debug: if (fs::file_exists(rast_tif)) {
    r_tmp_tif <- tempfile(fileext = ".tif")
    r_tmp <- c(rast(rast_tif), r)
    r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
    terra::writeRaster(r_tmp, r_tmp_tif)
    fs::file_delete(rast_tif)
    fs::file_move(r_tmp_tif, rast_tif)
    rm(r)
    rm(r_tmp)
} else {
    terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
}
debug: terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
debug: r <- terra::rast(rast_tif)
debug: d_r <- mutate(tidyr::pivot_longer(sf::st_drop_geometry(sf::st_as_sf(terra::zonal(x = r, 
    z = terra::vect(dplyr::select(sf_zones, dplyr::all_of(fld_zones))), 
    fun = zonal_fun, exact = T, na.rm = T, as.polygons = T))), 
    cols = -dplyr::any_of(fld_zones), names_to = "lyr", values_to = zonal_fun), 
    time = readr::parse_datetime(str_replace(lyr, glue("{var}\\|(.*)"), 
        "\\1")))
debug: if (!is.null(zonal_csv)) write_csv(d_r, zonal_csv)
debug: write_csv(d_r, zonal_csv)
debug: if (!keep_nc) unlink(dir_nc, recursive = T)
debug: unlink(dir_nc, recursive = T)
debug: return(d_r)
Downloading 1 requests, up to 167 time slices each
Called from: extractr::ed_extract(ed, var = v, sf_zones = ply, bbox = bb, 
    mask_tif = F, rast_tif = glue("{dir_out}/{nms}/{yr}.tif"), 
    zonal_fun = "mean", zonal_csv = glue("{dir_out}/{nms}/{yr}.csv"), 
    dir_nc = glue("{dir_out}/{nms}/{yr}_nc"), keep_nc = F, n_max_vals_per_req = 1e+05, 
    time_min = time_min, time_max = time_max, verbose = T)
debug: while (i_req <= n_reqs) {
    i_t_beg <- (i_req - 1) * n_t_per_req + 1
    i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
    t_req <- times_todo[c(i_t_beg, i_t_end)]
    t_req_str <- format_ISO8601(t_req, usetz = "Z")
    if (verbose) 
        message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
    ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
        ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
        0), nc)
    unlink(ncs0)
    nc_retry <- T
    nc_n_try <- 1
    n_max_retries
    while (nc_retry) {
        res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
            url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
                bbox[["xmax"]]), latitude = c(bbox[["ymin"]], 
                bbox[["ymax"]]), time = t_req_str, fmt = "nc", 
            store = rerddap::disk(path = dir_nc)))
        if (inherits(res, "try-error")) {
            err <- attr(res, "condition")
            msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
            nc_n_try <- nc_n_try + 1
            if (nc_n_try > n_max_retries) {
                stop(msg)
            }
            else {
                message(msg, "\nRETRYing...")
                Sys.sleep(1)
            }
        }
        else {
            nc_retry <- F
        }
    }
    i_req <- i_req + 1
}
debug: i_t_beg <- (i_req - 1) * n_t_per_req + 1
debug: i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
debug: t_req <- times_todo[c(i_t_beg, i_t_end)]
debug: t_req_str <- format_ISO8601(t_req, usetz = "Z")
debug: if (verbose) message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
debug: message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
Fetching request 1 of 1 (2003-01-01 to 2003-12-01) ~ 19:36:48 UTC
debug: ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
    0), nc)
debug: unlink(ncs0)
debug: nc_retry <- T
debug: nc_n_try <- 1
debug: n_max_retries
debug: while (nc_retry) {
    res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
        url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
            bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
        time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
    if (inherits(res, "try-error")) {
        err <- attr(res, "condition")
        msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
        nc_n_try <- nc_n_try + 1
        if (nc_n_try > n_max_retries) {
            stop(msg)
        }
        else {
            message(msg, "\nRETRYing...")
            Sys.sleep(1)
        }
    }
    else {
        nc_retry <- F
    }
}
debug: res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
    url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
        bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
    time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
debug: if (inherits(res, "try-error")) {
    err <- attr(res, "condition")
    msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
    nc_n_try <- nc_n_try + 1
    if (nc_n_try > n_max_retries) {
        stop(msg)
    }
    else {
        message(msg, "\nRETRYing...")
        Sys.sleep(1)
    }
} else {
    nc_retry <- F
}
debug: nc_retry <- F
debug: (while) nc_retry
debug: i_req <- i_req + 1
debug: (while) i_req <= n_reqs
debug: ncs <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size > 
    0), nc)
debug: r <- terra::rast(ncs)
debug: stopifnot(all(class(terra::time(r)) %in% c("POSIXct", "POSIXt")))
debug: idx <- dplyr::pull(dplyr::filter(dplyr::arrange(dplyr::tibble(idx = 1:terra::nlyr(r), 
    time = terra::time(r)), time), !duplicated(time)), idx)
debug: r <- terra::subset(r, idx)
debug: stopifnot(terra::crs(r, proj = T) == wgs84)
debug: if (mask_tif) r <- terra::mask(r, sf_zones)
debug: lyrs <- glue("{var}|{terra::time(r)}")
debug: if (length(dims_other) > 0 && !all(length(dims[dims_other]) == 
    1)) stop(glue("Other dimensions not yet supported: {paste(dims_other, collapse = ',')}"))
debug: names(r) <- lyrs
debug: if (!is.null(rast_tif)) {
    if (fs::file_exists(rast_tif)) {
        r_tmp_tif <- tempfile(fileext = ".tif")
        r_tmp <- c(rast(rast_tif), r)
        r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
        terra::writeRaster(r_tmp, r_tmp_tif)
        fs::file_delete(rast_tif)
        fs::file_move(r_tmp_tif, rast_tif)
        rm(r)
        rm(r_tmp)
    }
    else {
        terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
    }
    r <- terra::rast(rast_tif)
}
debug: if (fs::file_exists(rast_tif)) {
    r_tmp_tif <- tempfile(fileext = ".tif")
    r_tmp <- c(rast(rast_tif), r)
    r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
    terra::writeRaster(r_tmp, r_tmp_tif)
    fs::file_delete(rast_tif)
    fs::file_move(r_tmp_tif, rast_tif)
    rm(r)
    rm(r_tmp)
} else {
    terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
}
debug: terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
debug: r <- terra::rast(rast_tif)
debug: d_r <- mutate(tidyr::pivot_longer(sf::st_drop_geometry(sf::st_as_sf(terra::zonal(x = r, 
    z = terra::vect(dplyr::select(sf_zones, dplyr::all_of(fld_zones))), 
    fun = zonal_fun, exact = T, na.rm = T, as.polygons = T))), 
    cols = -dplyr::any_of(fld_zones), names_to = "lyr", values_to = zonal_fun), 
    time = readr::parse_datetime(str_replace(lyr, glue("{var}\\|(.*)"), 
        "\\1")))
debug: if (!is.null(zonal_csv)) write_csv(d_r, zonal_csv)
debug: write_csv(d_r, zonal_csv)
debug: if (!keep_nc) unlink(dir_nc, recursive = T)
debug: unlink(dir_nc, recursive = T)
debug: return(d_r)
Downloading 1 requests, up to 167 time slices each
Called from: extractr::ed_extract(ed, var = v, sf_zones = ply, bbox = bb, 
    mask_tif = F, rast_tif = glue("{dir_out}/{nms}/{yr}.tif"), 
    zonal_fun = "mean", zonal_csv = glue("{dir_out}/{nms}/{yr}.csv"), 
    dir_nc = glue("{dir_out}/{nms}/{yr}_nc"), keep_nc = F, n_max_vals_per_req = 1e+05, 
    time_min = time_min, time_max = time_max, verbose = T)
debug: while (i_req <= n_reqs) {
    i_t_beg <- (i_req - 1) * n_t_per_req + 1
    i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
    t_req <- times_todo[c(i_t_beg, i_t_end)]
    t_req_str <- format_ISO8601(t_req, usetz = "Z")
    if (verbose) 
        message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
    ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
        ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
        0), nc)
    unlink(ncs0)
    nc_retry <- T
    nc_n_try <- 1
    n_max_retries
    while (nc_retry) {
        res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
            url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
                bbox[["xmax"]]), latitude = c(bbox[["ymin"]], 
                bbox[["ymax"]]), time = t_req_str, fmt = "nc", 
            store = rerddap::disk(path = dir_nc)))
        if (inherits(res, "try-error")) {
            err <- attr(res, "condition")
            msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
            nc_n_try <- nc_n_try + 1
            if (nc_n_try > n_max_retries) {
                stop(msg)
            }
            else {
                message(msg, "\nRETRYing...")
                Sys.sleep(1)
            }
        }
        else {
            nc_retry <- F
        }
    }
    i_req <- i_req + 1
}
debug: i_t_beg <- (i_req - 1) * n_t_per_req + 1
debug: i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
debug: t_req <- times_todo[c(i_t_beg, i_t_end)]
debug: t_req_str <- format_ISO8601(t_req, usetz = "Z")
debug: if (verbose) message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
debug: message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
Fetching request 1 of 1 (2004-01-01 to 2004-12-01) ~ 19:36:51 UTC
debug: ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
    0), nc)
debug: unlink(ncs0)
debug: nc_retry <- T
debug: nc_n_try <- 1
debug: n_max_retries
debug: while (nc_retry) {
    res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
        url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
            bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
        time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
    if (inherits(res, "try-error")) {
        err <- attr(res, "condition")
        msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
        nc_n_try <- nc_n_try + 1
        if (nc_n_try > n_max_retries) {
            stop(msg)
        }
        else {
            message(msg, "\nRETRYing...")
            Sys.sleep(1)
        }
    }
    else {
        nc_retry <- F
    }
}
debug: res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
    url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
        bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
    time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
debug: if (inherits(res, "try-error")) {
    err <- attr(res, "condition")
    msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
    nc_n_try <- nc_n_try + 1
    if (nc_n_try > n_max_retries) {
        stop(msg)
    }
    else {
        message(msg, "\nRETRYing...")
        Sys.sleep(1)
    }
} else {
    nc_retry <- F
}
debug: nc_retry <- F
debug: (while) nc_retry
debug: i_req <- i_req + 1
debug: (while) i_req <= n_reqs
debug: ncs <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size > 
    0), nc)
debug: r <- terra::rast(ncs)
debug: stopifnot(all(class(terra::time(r)) %in% c("POSIXct", "POSIXt")))
debug: idx <- dplyr::pull(dplyr::filter(dplyr::arrange(dplyr::tibble(idx = 1:terra::nlyr(r), 
    time = terra::time(r)), time), !duplicated(time)), idx)
debug: r <- terra::subset(r, idx)
debug: stopifnot(terra::crs(r, proj = T) == wgs84)
debug: if (mask_tif) r <- terra::mask(r, sf_zones)
debug: lyrs <- glue("{var}|{terra::time(r)}")
debug: if (length(dims_other) > 0 && !all(length(dims[dims_other]) == 
    1)) stop(glue("Other dimensions not yet supported: {paste(dims_other, collapse = ',')}"))
debug: names(r) <- lyrs
debug: if (!is.null(rast_tif)) {
    if (fs::file_exists(rast_tif)) {
        r_tmp_tif <- tempfile(fileext = ".tif")
        r_tmp <- c(rast(rast_tif), r)
        r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
        terra::writeRaster(r_tmp, r_tmp_tif)
        fs::file_delete(rast_tif)
        fs::file_move(r_tmp_tif, rast_tif)
        rm(r)
        rm(r_tmp)
    }
    else {
        terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
    }
    r <- terra::rast(rast_tif)
}
debug: if (fs::file_exists(rast_tif)) {
    r_tmp_tif <- tempfile(fileext = ".tif")
    r_tmp <- c(rast(rast_tif), r)
    r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
    terra::writeRaster(r_tmp, r_tmp_tif)
    fs::file_delete(rast_tif)
    fs::file_move(r_tmp_tif, rast_tif)
    rm(r)
    rm(r_tmp)
} else {
    terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
}
debug: terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
debug: r <- terra::rast(rast_tif)
debug: d_r <- mutate(tidyr::pivot_longer(sf::st_drop_geometry(sf::st_as_sf(terra::zonal(x = r, 
    z = terra::vect(dplyr::select(sf_zones, dplyr::all_of(fld_zones))), 
    fun = zonal_fun, exact = T, na.rm = T, as.polygons = T))), 
    cols = -dplyr::any_of(fld_zones), names_to = "lyr", values_to = zonal_fun), 
    time = readr::parse_datetime(str_replace(lyr, glue("{var}\\|(.*)"), 
        "\\1")))
debug: if (!is.null(zonal_csv)) write_csv(d_r, zonal_csv)
debug: write_csv(d_r, zonal_csv)
debug: if (!keep_nc) unlink(dir_nc, recursive = T)
debug: unlink(dir_nc, recursive = T)
debug: return(d_r)
Downloading 1 requests, up to 167 time slices each
Called from: extractr::ed_extract(ed, var = v, sf_zones = ply, bbox = bb, 
    mask_tif = F, rast_tif = glue("{dir_out}/{nms}/{yr}.tif"), 
    zonal_fun = "mean", zonal_csv = glue("{dir_out}/{nms}/{yr}.csv"), 
    dir_nc = glue("{dir_out}/{nms}/{yr}_nc"), keep_nc = F, n_max_vals_per_req = 1e+05, 
    time_min = time_min, time_max = time_max, verbose = T)
debug: while (i_req <= n_reqs) {
    i_t_beg <- (i_req - 1) * n_t_per_req + 1
    i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
    t_req <- times_todo[c(i_t_beg, i_t_end)]
    t_req_str <- format_ISO8601(t_req, usetz = "Z")
    if (verbose) 
        message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
    ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
        ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
        0), nc)
    unlink(ncs0)
    nc_retry <- T
    nc_n_try <- 1
    n_max_retries
    while (nc_retry) {
        res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
            url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
                bbox[["xmax"]]), latitude = c(bbox[["ymin"]], 
                bbox[["ymax"]]), time = t_req_str, fmt = "nc", 
            store = rerddap::disk(path = dir_nc)))
        if (inherits(res, "try-error")) {
            err <- attr(res, "condition")
            msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
            nc_n_try <- nc_n_try + 1
            if (nc_n_try > n_max_retries) {
                stop(msg)
            }
            else {
                message(msg, "\nRETRYing...")
                Sys.sleep(1)
            }
        }
        else {
            nc_retry <- F
        }
    }
    i_req <- i_req + 1
}
debug: i_t_beg <- (i_req - 1) * n_t_per_req + 1
debug: i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
debug: t_req <- times_todo[c(i_t_beg, i_t_end)]
debug: t_req_str <- format_ISO8601(t_req, usetz = "Z")
debug: if (verbose) message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
debug: message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
Fetching request 1 of 1 (2005-01-01 to 2005-12-01) ~ 19:36:53 UTC
debug: ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
    0), nc)
debug: unlink(ncs0)
debug: nc_retry <- T
debug: nc_n_try <- 1
debug: n_max_retries
debug: while (nc_retry) {
    res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
        url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
            bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
        time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
    if (inherits(res, "try-error")) {
        err <- attr(res, "condition")
        msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
        nc_n_try <- nc_n_try + 1
        if (nc_n_try > n_max_retries) {
            stop(msg)
        }
        else {
            message(msg, "\nRETRYing...")
            Sys.sleep(1)
        }
    }
    else {
        nc_retry <- F
    }
}
debug: res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
    url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
        bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
    time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
debug: if (inherits(res, "try-error")) {
    err <- attr(res, "condition")
    msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
    nc_n_try <- nc_n_try + 1
    if (nc_n_try > n_max_retries) {
        stop(msg)
    }
    else {
        message(msg, "\nRETRYing...")
        Sys.sleep(1)
    }
} else {
    nc_retry <- F
}
debug: nc_retry <- F
debug: (while) nc_retry
debug: i_req <- i_req + 1
debug: (while) i_req <= n_reqs
debug: ncs <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size > 
    0), nc)
debug: r <- terra::rast(ncs)
debug: stopifnot(all(class(terra::time(r)) %in% c("POSIXct", "POSIXt")))
debug: idx <- dplyr::pull(dplyr::filter(dplyr::arrange(dplyr::tibble(idx = 1:terra::nlyr(r), 
    time = terra::time(r)), time), !duplicated(time)), idx)
debug: r <- terra::subset(r, idx)
debug: stopifnot(terra::crs(r, proj = T) == wgs84)
debug: if (mask_tif) r <- terra::mask(r, sf_zones)
debug: lyrs <- glue("{var}|{terra::time(r)}")
debug: if (length(dims_other) > 0 && !all(length(dims[dims_other]) == 
    1)) stop(glue("Other dimensions not yet supported: {paste(dims_other, collapse = ',')}"))
debug: names(r) <- lyrs
debug: if (!is.null(rast_tif)) {
    if (fs::file_exists(rast_tif)) {
        r_tmp_tif <- tempfile(fileext = ".tif")
        r_tmp <- c(rast(rast_tif), r)
        r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
        terra::writeRaster(r_tmp, r_tmp_tif)
        fs::file_delete(rast_tif)
        fs::file_move(r_tmp_tif, rast_tif)
        rm(r)
        rm(r_tmp)
    }
    else {
        terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
    }
    r <- terra::rast(rast_tif)
}
debug: if (fs::file_exists(rast_tif)) {
    r_tmp_tif <- tempfile(fileext = ".tif")
    r_tmp <- c(rast(rast_tif), r)
    r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
    terra::writeRaster(r_tmp, r_tmp_tif)
    fs::file_delete(rast_tif)
    fs::file_move(r_tmp_tif, rast_tif)
    rm(r)
    rm(r_tmp)
} else {
    terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
}
debug: terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
debug: r <- terra::rast(rast_tif)
debug: d_r <- mutate(tidyr::pivot_longer(sf::st_drop_geometry(sf::st_as_sf(terra::zonal(x = r, 
    z = terra::vect(dplyr::select(sf_zones, dplyr::all_of(fld_zones))), 
    fun = zonal_fun, exact = T, na.rm = T, as.polygons = T))), 
    cols = -dplyr::any_of(fld_zones), names_to = "lyr", values_to = zonal_fun), 
    time = readr::parse_datetime(str_replace(lyr, glue("{var}\\|(.*)"), 
        "\\1")))
debug: if (!is.null(zonal_csv)) write_csv(d_r, zonal_csv)
debug: write_csv(d_r, zonal_csv)
debug: if (!keep_nc) unlink(dir_nc, recursive = T)
debug: unlink(dir_nc, recursive = T)
debug: return(d_r)
Downloading 1 requests, up to 167 time slices each
Called from: extractr::ed_extract(ed, var = v, sf_zones = ply, bbox = bb, 
    mask_tif = F, rast_tif = glue("{dir_out}/{nms}/{yr}.tif"), 
    zonal_fun = "mean", zonal_csv = glue("{dir_out}/{nms}/{yr}.csv"), 
    dir_nc = glue("{dir_out}/{nms}/{yr}_nc"), keep_nc = F, n_max_vals_per_req = 1e+05, 
    time_min = time_min, time_max = time_max, verbose = T)
debug: while (i_req <= n_reqs) {
    i_t_beg <- (i_req - 1) * n_t_per_req + 1
    i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
    t_req <- times_todo[c(i_t_beg, i_t_end)]
    t_req_str <- format_ISO8601(t_req, usetz = "Z")
    if (verbose) 
        message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
    ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
        ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
        0), nc)
    unlink(ncs0)
    nc_retry <- T
    nc_n_try <- 1
    n_max_retries
    while (nc_retry) {
        res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
            url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
                bbox[["xmax"]]), latitude = c(bbox[["ymin"]], 
                bbox[["ymax"]]), time = t_req_str, fmt = "nc", 
            store = rerddap::disk(path = dir_nc)))
        if (inherits(res, "try-error")) {
            err <- attr(res, "condition")
            msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
            nc_n_try <- nc_n_try + 1
            if (nc_n_try > n_max_retries) {
                stop(msg)
            }
            else {
                message(msg, "\nRETRYing...")
                Sys.sleep(1)
            }
        }
        else {
            nc_retry <- F
        }
    }
    i_req <- i_req + 1
}
debug: i_t_beg <- (i_req - 1) * n_t_per_req + 1
debug: i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
debug: t_req <- times_todo[c(i_t_beg, i_t_end)]
debug: t_req_str <- format_ISO8601(t_req, usetz = "Z")
debug: if (verbose) message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
debug: message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
Fetching request 1 of 1 (2006-01-01 to 2006-12-01) ~ 19:36:55 UTC
debug: ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
    0), nc)
debug: unlink(ncs0)
debug: nc_retry <- T
debug: nc_n_try <- 1
debug: n_max_retries
debug: while (nc_retry) {
    res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
        url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
            bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
        time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
    if (inherits(res, "try-error")) {
        err <- attr(res, "condition")
        msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
        nc_n_try <- nc_n_try + 1
        if (nc_n_try > n_max_retries) {
            stop(msg)
        }
        else {
            message(msg, "\nRETRYing...")
            Sys.sleep(1)
        }
    }
    else {
        nc_retry <- F
    }
}
debug: res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
    url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
        bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
    time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
debug: if (inherits(res, "try-error")) {
    err <- attr(res, "condition")
    msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
    nc_n_try <- nc_n_try + 1
    if (nc_n_try > n_max_retries) {
        stop(msg)
    }
    else {
        message(msg, "\nRETRYing...")
        Sys.sleep(1)
    }
} else {
    nc_retry <- F
}
debug: nc_retry <- F
debug: (while) nc_retry
debug: i_req <- i_req + 1
debug: (while) i_req <= n_reqs
debug: ncs <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size > 
    0), nc)
debug: r <- terra::rast(ncs)
debug: stopifnot(all(class(terra::time(r)) %in% c("POSIXct", "POSIXt")))
debug: idx <- dplyr::pull(dplyr::filter(dplyr::arrange(dplyr::tibble(idx = 1:terra::nlyr(r), 
    time = terra::time(r)), time), !duplicated(time)), idx)
debug: r <- terra::subset(r, idx)
debug: stopifnot(terra::crs(r, proj = T) == wgs84)
debug: if (mask_tif) r <- terra::mask(r, sf_zones)
debug: lyrs <- glue("{var}|{terra::time(r)}")
debug: if (length(dims_other) > 0 && !all(length(dims[dims_other]) == 
    1)) stop(glue("Other dimensions not yet supported: {paste(dims_other, collapse = ',')}"))
debug: names(r) <- lyrs
debug: if (!is.null(rast_tif)) {
    if (fs::file_exists(rast_tif)) {
        r_tmp_tif <- tempfile(fileext = ".tif")
        r_tmp <- c(rast(rast_tif), r)
        r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
        terra::writeRaster(r_tmp, r_tmp_tif)
        fs::file_delete(rast_tif)
        fs::file_move(r_tmp_tif, rast_tif)
        rm(r)
        rm(r_tmp)
    }
    else {
        terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
    }
    r <- terra::rast(rast_tif)
}
debug: if (fs::file_exists(rast_tif)) {
    r_tmp_tif <- tempfile(fileext = ".tif")
    r_tmp <- c(rast(rast_tif), r)
    r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
    terra::writeRaster(r_tmp, r_tmp_tif)
    fs::file_delete(rast_tif)
    fs::file_move(r_tmp_tif, rast_tif)
    rm(r)
    rm(r_tmp)
} else {
    terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
}
debug: terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
debug: r <- terra::rast(rast_tif)
debug: d_r <- mutate(tidyr::pivot_longer(sf::st_drop_geometry(sf::st_as_sf(terra::zonal(x = r, 
    z = terra::vect(dplyr::select(sf_zones, dplyr::all_of(fld_zones))), 
    fun = zonal_fun, exact = T, na.rm = T, as.polygons = T))), 
    cols = -dplyr::any_of(fld_zones), names_to = "lyr", values_to = zonal_fun), 
    time = readr::parse_datetime(str_replace(lyr, glue("{var}\\|(.*)"), 
        "\\1")))
debug: if (!is.null(zonal_csv)) write_csv(d_r, zonal_csv)
debug: write_csv(d_r, zonal_csv)
debug: if (!keep_nc) unlink(dir_nc, recursive = T)
debug: unlink(dir_nc, recursive = T)
debug: return(d_r)
Downloading 1 requests, up to 167 time slices each
Called from: extractr::ed_extract(ed, var = v, sf_zones = ply, bbox = bb, 
    mask_tif = F, rast_tif = glue("{dir_out}/{nms}/{yr}.tif"), 
    zonal_fun = "mean", zonal_csv = glue("{dir_out}/{nms}/{yr}.csv"), 
    dir_nc = glue("{dir_out}/{nms}/{yr}_nc"), keep_nc = F, n_max_vals_per_req = 1e+05, 
    time_min = time_min, time_max = time_max, verbose = T)
debug: while (i_req <= n_reqs) {
    i_t_beg <- (i_req - 1) * n_t_per_req + 1
    i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
    t_req <- times_todo[c(i_t_beg, i_t_end)]
    t_req_str <- format_ISO8601(t_req, usetz = "Z")
    if (verbose) 
        message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
    ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
        ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
        0), nc)
    unlink(ncs0)
    nc_retry <- T
    nc_n_try <- 1
    n_max_retries
    while (nc_retry) {
        res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
            url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
                bbox[["xmax"]]), latitude = c(bbox[["ymin"]], 
                bbox[["ymax"]]), time = t_req_str, fmt = "nc", 
            store = rerddap::disk(path = dir_nc)))
        if (inherits(res, "try-error")) {
            err <- attr(res, "condition")
            msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
            nc_n_try <- nc_n_try + 1
            if (nc_n_try > n_max_retries) {
                stop(msg)
            }
            else {
                message(msg, "\nRETRYing...")
                Sys.sleep(1)
            }
        }
        else {
            nc_retry <- F
        }
    }
    i_req <- i_req + 1
}
debug: i_t_beg <- (i_req - 1) * n_t_per_req + 1
debug: i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
debug: t_req <- times_todo[c(i_t_beg, i_t_end)]
debug: t_req_str <- format_ISO8601(t_req, usetz = "Z")
debug: if (verbose) message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
debug: message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
Fetching request 1 of 1 (2007-01-01 to 2007-12-01) ~ 19:36:58 UTC
debug: ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
    0), nc)
debug: unlink(ncs0)
debug: nc_retry <- T
debug: nc_n_try <- 1
debug: n_max_retries
debug: while (nc_retry) {
    res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
        url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
            bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
        time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
    if (inherits(res, "try-error")) {
        err <- attr(res, "condition")
        msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
        nc_n_try <- nc_n_try + 1
        if (nc_n_try > n_max_retries) {
            stop(msg)
        }
        else {
            message(msg, "\nRETRYing...")
            Sys.sleep(1)
        }
    }
    else {
        nc_retry <- F
    }
}
debug: res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
    url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
        bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
    time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
debug: if (inherits(res, "try-error")) {
    err <- attr(res, "condition")
    msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
    nc_n_try <- nc_n_try + 1
    if (nc_n_try > n_max_retries) {
        stop(msg)
    }
    else {
        message(msg, "\nRETRYing...")
        Sys.sleep(1)
    }
} else {
    nc_retry <- F
}
debug: nc_retry <- F
debug: (while) nc_retry
debug: i_req <- i_req + 1
debug: (while) i_req <= n_reqs
debug: ncs <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size > 
    0), nc)
debug: r <- terra::rast(ncs)
debug: stopifnot(all(class(terra::time(r)) %in% c("POSIXct", "POSIXt")))
debug: idx <- dplyr::pull(dplyr::filter(dplyr::arrange(dplyr::tibble(idx = 1:terra::nlyr(r), 
    time = terra::time(r)), time), !duplicated(time)), idx)
debug: r <- terra::subset(r, idx)
debug: stopifnot(terra::crs(r, proj = T) == wgs84)
debug: if (mask_tif) r <- terra::mask(r, sf_zones)
debug: lyrs <- glue("{var}|{terra::time(r)}")
debug: if (length(dims_other) > 0 && !all(length(dims[dims_other]) == 
    1)) stop(glue("Other dimensions not yet supported: {paste(dims_other, collapse = ',')}"))
debug: names(r) <- lyrs
debug: if (!is.null(rast_tif)) {
    if (fs::file_exists(rast_tif)) {
        r_tmp_tif <- tempfile(fileext = ".tif")
        r_tmp <- c(rast(rast_tif), r)
        r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
        terra::writeRaster(r_tmp, r_tmp_tif)
        fs::file_delete(rast_tif)
        fs::file_move(r_tmp_tif, rast_tif)
        rm(r)
        rm(r_tmp)
    }
    else {
        terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
    }
    r <- terra::rast(rast_tif)
}
debug: if (fs::file_exists(rast_tif)) {
    r_tmp_tif <- tempfile(fileext = ".tif")
    r_tmp <- c(rast(rast_tif), r)
    r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
    terra::writeRaster(r_tmp, r_tmp_tif)
    fs::file_delete(rast_tif)
    fs::file_move(r_tmp_tif, rast_tif)
    rm(r)
    rm(r_tmp)
} else {
    terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
}
debug: terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
debug: r <- terra::rast(rast_tif)
debug: d_r <- mutate(tidyr::pivot_longer(sf::st_drop_geometry(sf::st_as_sf(terra::zonal(x = r, 
    z = terra::vect(dplyr::select(sf_zones, dplyr::all_of(fld_zones))), 
    fun = zonal_fun, exact = T, na.rm = T, as.polygons = T))), 
    cols = -dplyr::any_of(fld_zones), names_to = "lyr", values_to = zonal_fun), 
    time = readr::parse_datetime(str_replace(lyr, glue("{var}\\|(.*)"), 
        "\\1")))
debug: if (!is.null(zonal_csv)) write_csv(d_r, zonal_csv)
debug: write_csv(d_r, zonal_csv)
debug: if (!keep_nc) unlink(dir_nc, recursive = T)
debug: unlink(dir_nc, recursive = T)
debug: return(d_r)
Downloading 1 requests, up to 167 time slices each
Called from: extractr::ed_extract(ed, var = v, sf_zones = ply, bbox = bb, 
    mask_tif = F, rast_tif = glue("{dir_out}/{nms}/{yr}.tif"), 
    zonal_fun = "mean", zonal_csv = glue("{dir_out}/{nms}/{yr}.csv"), 
    dir_nc = glue("{dir_out}/{nms}/{yr}_nc"), keep_nc = F, n_max_vals_per_req = 1e+05, 
    time_min = time_min, time_max = time_max, verbose = T)
debug: while (i_req <= n_reqs) {
    i_t_beg <- (i_req - 1) * n_t_per_req + 1
    i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
    t_req <- times_todo[c(i_t_beg, i_t_end)]
    t_req_str <- format_ISO8601(t_req, usetz = "Z")
    if (verbose) 
        message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
    ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
        ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
        0), nc)
    unlink(ncs0)
    nc_retry <- T
    nc_n_try <- 1
    n_max_retries
    while (nc_retry) {
        res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
            url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
                bbox[["xmax"]]), latitude = c(bbox[["ymin"]], 
                bbox[["ymax"]]), time = t_req_str, fmt = "nc", 
            store = rerddap::disk(path = dir_nc)))
        if (inherits(res, "try-error")) {
            err <- attr(res, "condition")
            msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
            nc_n_try <- nc_n_try + 1
            if (nc_n_try > n_max_retries) {
                stop(msg)
            }
            else {
                message(msg, "\nRETRYing...")
                Sys.sleep(1)
            }
        }
        else {
            nc_retry <- F
        }
    }
    i_req <- i_req + 1
}
debug: i_t_beg <- (i_req - 1) * n_t_per_req + 1
debug: i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
debug: t_req <- times_todo[c(i_t_beg, i_t_end)]
debug: t_req_str <- format_ISO8601(t_req, usetz = "Z")
debug: if (verbose) message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
debug: message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
Fetching request 1 of 1 (2008-01-01 to 2008-12-01) ~ 19:37:00 UTC
debug: ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
    0), nc)
debug: unlink(ncs0)
debug: nc_retry <- T
debug: nc_n_try <- 1
debug: n_max_retries
debug: while (nc_retry) {
    res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
        url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
            bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
        time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
    if (inherits(res, "try-error")) {
        err <- attr(res, "condition")
        msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
        nc_n_try <- nc_n_try + 1
        if (nc_n_try > n_max_retries) {
            stop(msg)
        }
        else {
            message(msg, "\nRETRYing...")
            Sys.sleep(1)
        }
    }
    else {
        nc_retry <- F
    }
}
debug: res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
    url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
        bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
    time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
debug: if (inherits(res, "try-error")) {
    err <- attr(res, "condition")
    msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
    nc_n_try <- nc_n_try + 1
    if (nc_n_try > n_max_retries) {
        stop(msg)
    }
    else {
        message(msg, "\nRETRYing...")
        Sys.sleep(1)
    }
} else {
    nc_retry <- F
}
debug: nc_retry <- F
debug: (while) nc_retry
debug: i_req <- i_req + 1
debug: (while) i_req <= n_reqs
debug: ncs <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size > 
    0), nc)
debug: r <- terra::rast(ncs)
debug: stopifnot(all(class(terra::time(r)) %in% c("POSIXct", "POSIXt")))
debug: idx <- dplyr::pull(dplyr::filter(dplyr::arrange(dplyr::tibble(idx = 1:terra::nlyr(r), 
    time = terra::time(r)), time), !duplicated(time)), idx)
debug: r <- terra::subset(r, idx)
debug: stopifnot(terra::crs(r, proj = T) == wgs84)
debug: if (mask_tif) r <- terra::mask(r, sf_zones)
debug: lyrs <- glue("{var}|{terra::time(r)}")
debug: if (length(dims_other) > 0 && !all(length(dims[dims_other]) == 
    1)) stop(glue("Other dimensions not yet supported: {paste(dims_other, collapse = ',')}"))
debug: names(r) <- lyrs
debug: if (!is.null(rast_tif)) {
    if (fs::file_exists(rast_tif)) {
        r_tmp_tif <- tempfile(fileext = ".tif")
        r_tmp <- c(rast(rast_tif), r)
        r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
        terra::writeRaster(r_tmp, r_tmp_tif)
        fs::file_delete(rast_tif)
        fs::file_move(r_tmp_tif, rast_tif)
        rm(r)
        rm(r_tmp)
    }
    else {
        terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
    }
    r <- terra::rast(rast_tif)
}
debug: if (fs::file_exists(rast_tif)) {
    r_tmp_tif <- tempfile(fileext = ".tif")
    r_tmp <- c(rast(rast_tif), r)
    r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
    terra::writeRaster(r_tmp, r_tmp_tif)
    fs::file_delete(rast_tif)
    fs::file_move(r_tmp_tif, rast_tif)
    rm(r)
    rm(r_tmp)
} else {
    terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
}
debug: terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
debug: r <- terra::rast(rast_tif)
debug: d_r <- mutate(tidyr::pivot_longer(sf::st_drop_geometry(sf::st_as_sf(terra::zonal(x = r, 
    z = terra::vect(dplyr::select(sf_zones, dplyr::all_of(fld_zones))), 
    fun = zonal_fun, exact = T, na.rm = T, as.polygons = T))), 
    cols = -dplyr::any_of(fld_zones), names_to = "lyr", values_to = zonal_fun), 
    time = readr::parse_datetime(str_replace(lyr, glue("{var}\\|(.*)"), 
        "\\1")))
debug: if (!is.null(zonal_csv)) write_csv(d_r, zonal_csv)
debug: write_csv(d_r, zonal_csv)
debug: if (!keep_nc) unlink(dir_nc, recursive = T)
debug: unlink(dir_nc, recursive = T)
debug: return(d_r)
Downloading 1 requests, up to 167 time slices each
Called from: extractr::ed_extract(ed, var = v, sf_zones = ply, bbox = bb, 
    mask_tif = F, rast_tif = glue("{dir_out}/{nms}/{yr}.tif"), 
    zonal_fun = "mean", zonal_csv = glue("{dir_out}/{nms}/{yr}.csv"), 
    dir_nc = glue("{dir_out}/{nms}/{yr}_nc"), keep_nc = F, n_max_vals_per_req = 1e+05, 
    time_min = time_min, time_max = time_max, verbose = T)
debug: while (i_req <= n_reqs) {
    i_t_beg <- (i_req - 1) * n_t_per_req + 1
    i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
    t_req <- times_todo[c(i_t_beg, i_t_end)]
    t_req_str <- format_ISO8601(t_req, usetz = "Z")
    if (verbose) 
        message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
    ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
        ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
        0), nc)
    unlink(ncs0)
    nc_retry <- T
    nc_n_try <- 1
    n_max_retries
    while (nc_retry) {
        res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
            url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
                bbox[["xmax"]]), latitude = c(bbox[["ymin"]], 
                bbox[["ymax"]]), time = t_req_str, fmt = "nc", 
            store = rerddap::disk(path = dir_nc)))
        if (inherits(res, "try-error")) {
            err <- attr(res, "condition")
            msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
            nc_n_try <- nc_n_try + 1
            if (nc_n_try > n_max_retries) {
                stop(msg)
            }
            else {
                message(msg, "\nRETRYing...")
                Sys.sleep(1)
            }
        }
        else {
            nc_retry <- F
        }
    }
    i_req <- i_req + 1
}
debug: i_t_beg <- (i_req - 1) * n_t_per_req + 1
debug: i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
debug: t_req <- times_todo[c(i_t_beg, i_t_end)]
debug: t_req_str <- format_ISO8601(t_req, usetz = "Z")
debug: if (verbose) message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
debug: message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
Fetching request 1 of 1 (2009-01-01 to 2009-12-01) ~ 19:37:03 UTC
debug: ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
    0), nc)
debug: unlink(ncs0)
debug: nc_retry <- T
debug: nc_n_try <- 1
debug: n_max_retries
debug: while (nc_retry) {
    res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
        url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
            bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
        time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
    if (inherits(res, "try-error")) {
        err <- attr(res, "condition")
        msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
        nc_n_try <- nc_n_try + 1
        if (nc_n_try > n_max_retries) {
            stop(msg)
        }
        else {
            message(msg, "\nRETRYing...")
            Sys.sleep(1)
        }
    }
    else {
        nc_retry <- F
    }
}
debug: res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
    url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
        bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
    time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
debug: if (inherits(res, "try-error")) {
    err <- attr(res, "condition")
    msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
    nc_n_try <- nc_n_try + 1
    if (nc_n_try > n_max_retries) {
        stop(msg)
    }
    else {
        message(msg, "\nRETRYing...")
        Sys.sleep(1)
    }
} else {
    nc_retry <- F
}
debug: nc_retry <- F
debug: (while) nc_retry
debug: i_req <- i_req + 1
debug: (while) i_req <= n_reqs
debug: ncs <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size > 
    0), nc)
debug: r <- terra::rast(ncs)
debug: stopifnot(all(class(terra::time(r)) %in% c("POSIXct", "POSIXt")))
debug: idx <- dplyr::pull(dplyr::filter(dplyr::arrange(dplyr::tibble(idx = 1:terra::nlyr(r), 
    time = terra::time(r)), time), !duplicated(time)), idx)
debug: r <- terra::subset(r, idx)
debug: stopifnot(terra::crs(r, proj = T) == wgs84)
debug: if (mask_tif) r <- terra::mask(r, sf_zones)
debug: lyrs <- glue("{var}|{terra::time(r)}")
debug: if (length(dims_other) > 0 && !all(length(dims[dims_other]) == 
    1)) stop(glue("Other dimensions not yet supported: {paste(dims_other, collapse = ',')}"))
debug: names(r) <- lyrs
debug: if (!is.null(rast_tif)) {
    if (fs::file_exists(rast_tif)) {
        r_tmp_tif <- tempfile(fileext = ".tif")
        r_tmp <- c(rast(rast_tif), r)
        r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
        terra::writeRaster(r_tmp, r_tmp_tif)
        fs::file_delete(rast_tif)
        fs::file_move(r_tmp_tif, rast_tif)
        rm(r)
        rm(r_tmp)
    }
    else {
        terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
    }
    r <- terra::rast(rast_tif)
}
debug: if (fs::file_exists(rast_tif)) {
    r_tmp_tif <- tempfile(fileext = ".tif")
    r_tmp <- c(rast(rast_tif), r)
    r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
    terra::writeRaster(r_tmp, r_tmp_tif)
    fs::file_delete(rast_tif)
    fs::file_move(r_tmp_tif, rast_tif)
    rm(r)
    rm(r_tmp)
} else {
    terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
}
debug: terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
debug: r <- terra::rast(rast_tif)
debug: d_r <- mutate(tidyr::pivot_longer(sf::st_drop_geometry(sf::st_as_sf(terra::zonal(x = r, 
    z = terra::vect(dplyr::select(sf_zones, dplyr::all_of(fld_zones))), 
    fun = zonal_fun, exact = T, na.rm = T, as.polygons = T))), 
    cols = -dplyr::any_of(fld_zones), names_to = "lyr", values_to = zonal_fun), 
    time = readr::parse_datetime(str_replace(lyr, glue("{var}\\|(.*)"), 
        "\\1")))
debug: if (!is.null(zonal_csv)) write_csv(d_r, zonal_csv)
debug: write_csv(d_r, zonal_csv)
debug: if (!keep_nc) unlink(dir_nc, recursive = T)
debug: unlink(dir_nc, recursive = T)
debug: return(d_r)
Downloading 1 requests, up to 167 time slices each
Called from: extractr::ed_extract(ed, var = v, sf_zones = ply, bbox = bb, 
    mask_tif = F, rast_tif = glue("{dir_out}/{nms}/{yr}.tif"), 
    zonal_fun = "mean", zonal_csv = glue("{dir_out}/{nms}/{yr}.csv"), 
    dir_nc = glue("{dir_out}/{nms}/{yr}_nc"), keep_nc = F, n_max_vals_per_req = 1e+05, 
    time_min = time_min, time_max = time_max, verbose = T)
debug: while (i_req <= n_reqs) {
    i_t_beg <- (i_req - 1) * n_t_per_req + 1
    i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
    t_req <- times_todo[c(i_t_beg, i_t_end)]
    t_req_str <- format_ISO8601(t_req, usetz = "Z")
    if (verbose) 
        message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
    ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
        ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
        0), nc)
    unlink(ncs0)
    nc_retry <- T
    nc_n_try <- 1
    n_max_retries
    while (nc_retry) {
        res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
            url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
                bbox[["xmax"]]), latitude = c(bbox[["ymin"]], 
                bbox[["ymax"]]), time = t_req_str, fmt = "nc", 
            store = rerddap::disk(path = dir_nc)))
        if (inherits(res, "try-error")) {
            err <- attr(res, "condition")
            msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
            nc_n_try <- nc_n_try + 1
            if (nc_n_try > n_max_retries) {
                stop(msg)
            }
            else {
                message(msg, "\nRETRYing...")
                Sys.sleep(1)
            }
        }
        else {
            nc_retry <- F
        }
    }
    i_req <- i_req + 1
}
debug: i_t_beg <- (i_req - 1) * n_t_per_req + 1
debug: i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
debug: t_req <- times_todo[c(i_t_beg, i_t_end)]
debug: t_req_str <- format_ISO8601(t_req, usetz = "Z")
debug: if (verbose) message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
debug: message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
Fetching request 1 of 1 (2010-01-01 to 2010-12-01) ~ 19:37:05 UTC
debug: ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
    0), nc)
debug: unlink(ncs0)
debug: nc_retry <- T
debug: nc_n_try <- 1
debug: n_max_retries
debug: while (nc_retry) {
    res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
        url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
            bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
        time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
    if (inherits(res, "try-error")) {
        err <- attr(res, "condition")
        msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
        nc_n_try <- nc_n_try + 1
        if (nc_n_try > n_max_retries) {
            stop(msg)
        }
        else {
            message(msg, "\nRETRYing...")
            Sys.sleep(1)
        }
    }
    else {
        nc_retry <- F
    }
}
debug: res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
    url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
        bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
    time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
debug: if (inherits(res, "try-error")) {
    err <- attr(res, "condition")
    msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
    nc_n_try <- nc_n_try + 1
    if (nc_n_try > n_max_retries) {
        stop(msg)
    }
    else {
        message(msg, "\nRETRYing...")
        Sys.sleep(1)
    }
} else {
    nc_retry <- F
}
debug: nc_retry <- F
debug: (while) nc_retry
debug: i_req <- i_req + 1
debug: (while) i_req <= n_reqs
debug: ncs <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size > 
    0), nc)
debug: r <- terra::rast(ncs)
debug: stopifnot(all(class(terra::time(r)) %in% c("POSIXct", "POSIXt")))
debug: idx <- dplyr::pull(dplyr::filter(dplyr::arrange(dplyr::tibble(idx = 1:terra::nlyr(r), 
    time = terra::time(r)), time), !duplicated(time)), idx)
debug: r <- terra::subset(r, idx)
debug: stopifnot(terra::crs(r, proj = T) == wgs84)
debug: if (mask_tif) r <- terra::mask(r, sf_zones)
debug: lyrs <- glue("{var}|{terra::time(r)}")
debug: if (length(dims_other) > 0 && !all(length(dims[dims_other]) == 
    1)) stop(glue("Other dimensions not yet supported: {paste(dims_other, collapse = ',')}"))
debug: names(r) <- lyrs
debug: if (!is.null(rast_tif)) {
    if (fs::file_exists(rast_tif)) {
        r_tmp_tif <- tempfile(fileext = ".tif")
        r_tmp <- c(rast(rast_tif), r)
        r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
        terra::writeRaster(r_tmp, r_tmp_tif)
        fs::file_delete(rast_tif)
        fs::file_move(r_tmp_tif, rast_tif)
        rm(r)
        rm(r_tmp)
    }
    else {
        terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
    }
    r <- terra::rast(rast_tif)
}
debug: if (fs::file_exists(rast_tif)) {
    r_tmp_tif <- tempfile(fileext = ".tif")
    r_tmp <- c(rast(rast_tif), r)
    r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
    terra::writeRaster(r_tmp, r_tmp_tif)
    fs::file_delete(rast_tif)
    fs::file_move(r_tmp_tif, rast_tif)
    rm(r)
    rm(r_tmp)
} else {
    terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
}
debug: terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
debug: r <- terra::rast(rast_tif)
debug: d_r <- mutate(tidyr::pivot_longer(sf::st_drop_geometry(sf::st_as_sf(terra::zonal(x = r, 
    z = terra::vect(dplyr::select(sf_zones, dplyr::all_of(fld_zones))), 
    fun = zonal_fun, exact = T, na.rm = T, as.polygons = T))), 
    cols = -dplyr::any_of(fld_zones), names_to = "lyr", values_to = zonal_fun), 
    time = readr::parse_datetime(str_replace(lyr, glue("{var}\\|(.*)"), 
        "\\1")))
debug: if (!is.null(zonal_csv)) write_csv(d_r, zonal_csv)
debug: write_csv(d_r, zonal_csv)
debug: if (!keep_nc) unlink(dir_nc, recursive = T)
debug: unlink(dir_nc, recursive = T)
debug: return(d_r)
Downloading 1 requests, up to 167 time slices each
Called from: extractr::ed_extract(ed, var = v, sf_zones = ply, bbox = bb, 
    mask_tif = F, rast_tif = glue("{dir_out}/{nms}/{yr}.tif"), 
    zonal_fun = "mean", zonal_csv = glue("{dir_out}/{nms}/{yr}.csv"), 
    dir_nc = glue("{dir_out}/{nms}/{yr}_nc"), keep_nc = F, n_max_vals_per_req = 1e+05, 
    time_min = time_min, time_max = time_max, verbose = T)
debug: while (i_req <= n_reqs) {
    i_t_beg <- (i_req - 1) * n_t_per_req + 1
    i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
    t_req <- times_todo[c(i_t_beg, i_t_end)]
    t_req_str <- format_ISO8601(t_req, usetz = "Z")
    if (verbose) 
        message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
    ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
        ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
        0), nc)
    unlink(ncs0)
    nc_retry <- T
    nc_n_try <- 1
    n_max_retries
    while (nc_retry) {
        res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
            url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
                bbox[["xmax"]]), latitude = c(bbox[["ymin"]], 
                bbox[["ymax"]]), time = t_req_str, fmt = "nc", 
            store = rerddap::disk(path = dir_nc)))
        if (inherits(res, "try-error")) {
            err <- attr(res, "condition")
            msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
            nc_n_try <- nc_n_try + 1
            if (nc_n_try > n_max_retries) {
                stop(msg)
            }
            else {
                message(msg, "\nRETRYing...")
                Sys.sleep(1)
            }
        }
        else {
            nc_retry <- F
        }
    }
    i_req <- i_req + 1
}
debug: i_t_beg <- (i_req - 1) * n_t_per_req + 1
debug: i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
debug: t_req <- times_todo[c(i_t_beg, i_t_end)]
debug: t_req_str <- format_ISO8601(t_req, usetz = "Z")
debug: if (verbose) message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
debug: message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
Fetching request 1 of 1 (2011-01-01 to 2011-12-01) ~ 19:37:08 UTC
debug: ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
    0), nc)
debug: unlink(ncs0)
debug: nc_retry <- T
debug: nc_n_try <- 1
debug: n_max_retries
debug: while (nc_retry) {
    res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
        url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
            bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
        time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
    if (inherits(res, "try-error")) {
        err <- attr(res, "condition")
        msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
        nc_n_try <- nc_n_try + 1
        if (nc_n_try > n_max_retries) {
            stop(msg)
        }
        else {
            message(msg, "\nRETRYing...")
            Sys.sleep(1)
        }
    }
    else {
        nc_retry <- F
    }
}
debug: res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
    url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
        bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
    time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
debug: if (inherits(res, "try-error")) {
    err <- attr(res, "condition")
    msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
    nc_n_try <- nc_n_try + 1
    if (nc_n_try > n_max_retries) {
        stop(msg)
    }
    else {
        message(msg, "\nRETRYing...")
        Sys.sleep(1)
    }
} else {
    nc_retry <- F
}
debug: nc_retry <- F
debug: (while) nc_retry
debug: i_req <- i_req + 1
debug: (while) i_req <= n_reqs
debug: ncs <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size > 
    0), nc)
debug: r <- terra::rast(ncs)
debug: stopifnot(all(class(terra::time(r)) %in% c("POSIXct", "POSIXt")))
debug: idx <- dplyr::pull(dplyr::filter(dplyr::arrange(dplyr::tibble(idx = 1:terra::nlyr(r), 
    time = terra::time(r)), time), !duplicated(time)), idx)
debug: r <- terra::subset(r, idx)
debug: stopifnot(terra::crs(r, proj = T) == wgs84)
debug: if (mask_tif) r <- terra::mask(r, sf_zones)
debug: lyrs <- glue("{var}|{terra::time(r)}")
debug: if (length(dims_other) > 0 && !all(length(dims[dims_other]) == 
    1)) stop(glue("Other dimensions not yet supported: {paste(dims_other, collapse = ',')}"))
debug: names(r) <- lyrs
debug: if (!is.null(rast_tif)) {
    if (fs::file_exists(rast_tif)) {
        r_tmp_tif <- tempfile(fileext = ".tif")
        r_tmp <- c(rast(rast_tif), r)
        r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
        terra::writeRaster(r_tmp, r_tmp_tif)
        fs::file_delete(rast_tif)
        fs::file_move(r_tmp_tif, rast_tif)
        rm(r)
        rm(r_tmp)
    }
    else {
        terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
    }
    r <- terra::rast(rast_tif)
}
debug: if (fs::file_exists(rast_tif)) {
    r_tmp_tif <- tempfile(fileext = ".tif")
    r_tmp <- c(rast(rast_tif), r)
    r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
    terra::writeRaster(r_tmp, r_tmp_tif)
    fs::file_delete(rast_tif)
    fs::file_move(r_tmp_tif, rast_tif)
    rm(r)
    rm(r_tmp)
} else {
    terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
}
debug: terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
debug: r <- terra::rast(rast_tif)
debug: d_r <- mutate(tidyr::pivot_longer(sf::st_drop_geometry(sf::st_as_sf(terra::zonal(x = r, 
    z = terra::vect(dplyr::select(sf_zones, dplyr::all_of(fld_zones))), 
    fun = zonal_fun, exact = T, na.rm = T, as.polygons = T))), 
    cols = -dplyr::any_of(fld_zones), names_to = "lyr", values_to = zonal_fun), 
    time = readr::parse_datetime(str_replace(lyr, glue("{var}\\|(.*)"), 
        "\\1")))
debug: if (!is.null(zonal_csv)) write_csv(d_r, zonal_csv)
debug: write_csv(d_r, zonal_csv)
debug: if (!keep_nc) unlink(dir_nc, recursive = T)
debug: unlink(dir_nc, recursive = T)
debug: return(d_r)
Downloading 1 requests, up to 167 time slices each
Called from: extractr::ed_extract(ed, var = v, sf_zones = ply, bbox = bb, 
    mask_tif = F, rast_tif = glue("{dir_out}/{nms}/{yr}.tif"), 
    zonal_fun = "mean", zonal_csv = glue("{dir_out}/{nms}/{yr}.csv"), 
    dir_nc = glue("{dir_out}/{nms}/{yr}_nc"), keep_nc = F, n_max_vals_per_req = 1e+05, 
    time_min = time_min, time_max = time_max, verbose = T)
debug: while (i_req <= n_reqs) {
    i_t_beg <- (i_req - 1) * n_t_per_req + 1
    i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
    t_req <- times_todo[c(i_t_beg, i_t_end)]
    t_req_str <- format_ISO8601(t_req, usetz = "Z")
    if (verbose) 
        message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
    ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
        ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
        0), nc)
    unlink(ncs0)
    nc_retry <- T
    nc_n_try <- 1
    n_max_retries
    while (nc_retry) {
        res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
            url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
                bbox[["xmax"]]), latitude = c(bbox[["ymin"]], 
                bbox[["ymax"]]), time = t_req_str, fmt = "nc", 
            store = rerddap::disk(path = dir_nc)))
        if (inherits(res, "try-error")) {
            err <- attr(res, "condition")
            msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
            nc_n_try <- nc_n_try + 1
            if (nc_n_try > n_max_retries) {
                stop(msg)
            }
            else {
                message(msg, "\nRETRYing...")
                Sys.sleep(1)
            }
        }
        else {
            nc_retry <- F
        }
    }
    i_req <- i_req + 1
}
debug: i_t_beg <- (i_req - 1) * n_t_per_req + 1
debug: i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
debug: t_req <- times_todo[c(i_t_beg, i_t_end)]
debug: t_req_str <- format_ISO8601(t_req, usetz = "Z")
debug: if (verbose) message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
debug: message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
Fetching request 1 of 1 (2012-01-01 to 2012-12-01) ~ 19:37:10 UTC
debug: ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
    0), nc)
debug: unlink(ncs0)
debug: nc_retry <- T
debug: nc_n_try <- 1
debug: n_max_retries
debug: while (nc_retry) {
    res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
        url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
            bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
        time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
    if (inherits(res, "try-error")) {
        err <- attr(res, "condition")
        msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
        nc_n_try <- nc_n_try + 1
        if (nc_n_try > n_max_retries) {
            stop(msg)
        }
        else {
            message(msg, "\nRETRYing...")
            Sys.sleep(1)
        }
    }
    else {
        nc_retry <- F
    }
}
debug: res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
    url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
        bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
    time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
debug: if (inherits(res, "try-error")) {
    err <- attr(res, "condition")
    msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
    nc_n_try <- nc_n_try + 1
    if (nc_n_try > n_max_retries) {
        stop(msg)
    }
    else {
        message(msg, "\nRETRYing...")
        Sys.sleep(1)
    }
} else {
    nc_retry <- F
}
debug: nc_retry <- F
debug: (while) nc_retry
debug: i_req <- i_req + 1
debug: (while) i_req <= n_reqs
debug: ncs <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size > 
    0), nc)
debug: r <- terra::rast(ncs)
debug: stopifnot(all(class(terra::time(r)) %in% c("POSIXct", "POSIXt")))
debug: idx <- dplyr::pull(dplyr::filter(dplyr::arrange(dplyr::tibble(idx = 1:terra::nlyr(r), 
    time = terra::time(r)), time), !duplicated(time)), idx)
debug: r <- terra::subset(r, idx)
debug: stopifnot(terra::crs(r, proj = T) == wgs84)
debug: if (mask_tif) r <- terra::mask(r, sf_zones)
debug: lyrs <- glue("{var}|{terra::time(r)}")
debug: if (length(dims_other) > 0 && !all(length(dims[dims_other]) == 
    1)) stop(glue("Other dimensions not yet supported: {paste(dims_other, collapse = ',')}"))
debug: names(r) <- lyrs
debug: if (!is.null(rast_tif)) {
    if (fs::file_exists(rast_tif)) {
        r_tmp_tif <- tempfile(fileext = ".tif")
        r_tmp <- c(rast(rast_tif), r)
        r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
        terra::writeRaster(r_tmp, r_tmp_tif)
        fs::file_delete(rast_tif)
        fs::file_move(r_tmp_tif, rast_tif)
        rm(r)
        rm(r_tmp)
    }
    else {
        terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
    }
    r <- terra::rast(rast_tif)
}
debug: if (fs::file_exists(rast_tif)) {
    r_tmp_tif <- tempfile(fileext = ".tif")
    r_tmp <- c(rast(rast_tif), r)
    r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
    terra::writeRaster(r_tmp, r_tmp_tif)
    fs::file_delete(rast_tif)
    fs::file_move(r_tmp_tif, rast_tif)
    rm(r)
    rm(r_tmp)
} else {
    terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
}
debug: terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
debug: r <- terra::rast(rast_tif)
debug: d_r <- mutate(tidyr::pivot_longer(sf::st_drop_geometry(sf::st_as_sf(terra::zonal(x = r, 
    z = terra::vect(dplyr::select(sf_zones, dplyr::all_of(fld_zones))), 
    fun = zonal_fun, exact = T, na.rm = T, as.polygons = T))), 
    cols = -dplyr::any_of(fld_zones), names_to = "lyr", values_to = zonal_fun), 
    time = readr::parse_datetime(str_replace(lyr, glue("{var}\\|(.*)"), 
        "\\1")))
debug: if (!is.null(zonal_csv)) write_csv(d_r, zonal_csv)
debug: write_csv(d_r, zonal_csv)
debug: if (!keep_nc) unlink(dir_nc, recursive = T)
debug: unlink(dir_nc, recursive = T)
debug: return(d_r)
Downloading 1 requests, up to 167 time slices each
Called from: extractr::ed_extract(ed, var = v, sf_zones = ply, bbox = bb, 
    mask_tif = F, rast_tif = glue("{dir_out}/{nms}/{yr}.tif"), 
    zonal_fun = "mean", zonal_csv = glue("{dir_out}/{nms}/{yr}.csv"), 
    dir_nc = glue("{dir_out}/{nms}/{yr}_nc"), keep_nc = F, n_max_vals_per_req = 1e+05, 
    time_min = time_min, time_max = time_max, verbose = T)
debug: while (i_req <= n_reqs) {
    i_t_beg <- (i_req - 1) * n_t_per_req + 1
    i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
    t_req <- times_todo[c(i_t_beg, i_t_end)]
    t_req_str <- format_ISO8601(t_req, usetz = "Z")
    if (verbose) 
        message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
    ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
        ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
        0), nc)
    unlink(ncs0)
    nc_retry <- T
    nc_n_try <- 1
    n_max_retries
    while (nc_retry) {
        res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
            url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
                bbox[["xmax"]]), latitude = c(bbox[["ymin"]], 
                bbox[["ymax"]]), time = t_req_str, fmt = "nc", 
            store = rerddap::disk(path = dir_nc)))
        if (inherits(res, "try-error")) {
            err <- attr(res, "condition")
            msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
            nc_n_try <- nc_n_try + 1
            if (nc_n_try > n_max_retries) {
                stop(msg)
            }
            else {
                message(msg, "\nRETRYing...")
                Sys.sleep(1)
            }
        }
        else {
            nc_retry <- F
        }
    }
    i_req <- i_req + 1
}
debug: i_t_beg <- (i_req - 1) * n_t_per_req + 1
debug: i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
debug: t_req <- times_todo[c(i_t_beg, i_t_end)]
debug: t_req_str <- format_ISO8601(t_req, usetz = "Z")
debug: if (verbose) message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
debug: message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
Fetching request 1 of 1 (2013-01-01 to 2013-12-01) ~ 19:37:13 UTC
debug: ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
    0), nc)
debug: unlink(ncs0)
debug: nc_retry <- T
debug: nc_n_try <- 1
debug: n_max_retries
debug: while (nc_retry) {
    res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
        url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
            bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
        time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
    if (inherits(res, "try-error")) {
        err <- attr(res, "condition")
        msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
        nc_n_try <- nc_n_try + 1
        if (nc_n_try > n_max_retries) {
            stop(msg)
        }
        else {
            message(msg, "\nRETRYing...")
            Sys.sleep(1)
        }
    }
    else {
        nc_retry <- F
    }
}
debug: res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
    url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
        bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
    time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
debug: if (inherits(res, "try-error")) {
    err <- attr(res, "condition")
    msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
    nc_n_try <- nc_n_try + 1
    if (nc_n_try > n_max_retries) {
        stop(msg)
    }
    else {
        message(msg, "\nRETRYing...")
        Sys.sleep(1)
    }
} else {
    nc_retry <- F
}
debug: nc_retry <- F
debug: (while) nc_retry
debug: i_req <- i_req + 1
debug: (while) i_req <= n_reqs
debug: ncs <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size > 
    0), nc)
debug: r <- terra::rast(ncs)
debug: stopifnot(all(class(terra::time(r)) %in% c("POSIXct", "POSIXt")))
debug: idx <- dplyr::pull(dplyr::filter(dplyr::arrange(dplyr::tibble(idx = 1:terra::nlyr(r), 
    time = terra::time(r)), time), !duplicated(time)), idx)
debug: r <- terra::subset(r, idx)
debug: stopifnot(terra::crs(r, proj = T) == wgs84)
debug: if (mask_tif) r <- terra::mask(r, sf_zones)
debug: lyrs <- glue("{var}|{terra::time(r)}")
debug: if (length(dims_other) > 0 && !all(length(dims[dims_other]) == 
    1)) stop(glue("Other dimensions not yet supported: {paste(dims_other, collapse = ',')}"))
debug: names(r) <- lyrs
debug: if (!is.null(rast_tif)) {
    if (fs::file_exists(rast_tif)) {
        r_tmp_tif <- tempfile(fileext = ".tif")
        r_tmp <- c(rast(rast_tif), r)
        r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
        terra::writeRaster(r_tmp, r_tmp_tif)
        fs::file_delete(rast_tif)
        fs::file_move(r_tmp_tif, rast_tif)
        rm(r)
        rm(r_tmp)
    }
    else {
        terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
    }
    r <- terra::rast(rast_tif)
}
debug: if (fs::file_exists(rast_tif)) {
    r_tmp_tif <- tempfile(fileext = ".tif")
    r_tmp <- c(rast(rast_tif), r)
    r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
    terra::writeRaster(r_tmp, r_tmp_tif)
    fs::file_delete(rast_tif)
    fs::file_move(r_tmp_tif, rast_tif)
    rm(r)
    rm(r_tmp)
} else {
    terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
}
debug: terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
debug: r <- terra::rast(rast_tif)
debug: d_r <- mutate(tidyr::pivot_longer(sf::st_drop_geometry(sf::st_as_sf(terra::zonal(x = r, 
    z = terra::vect(dplyr::select(sf_zones, dplyr::all_of(fld_zones))), 
    fun = zonal_fun, exact = T, na.rm = T, as.polygons = T))), 
    cols = -dplyr::any_of(fld_zones), names_to = "lyr", values_to = zonal_fun), 
    time = readr::parse_datetime(str_replace(lyr, glue("{var}\\|(.*)"), 
        "\\1")))
debug: if (!is.null(zonal_csv)) write_csv(d_r, zonal_csv)
debug: write_csv(d_r, zonal_csv)
debug: if (!keep_nc) unlink(dir_nc, recursive = T)
debug: unlink(dir_nc, recursive = T)
debug: return(d_r)
Downloading 1 requests, up to 167 time slices each
Called from: extractr::ed_extract(ed, var = v, sf_zones = ply, bbox = bb, 
    mask_tif = F, rast_tif = glue("{dir_out}/{nms}/{yr}.tif"), 
    zonal_fun = "mean", zonal_csv = glue("{dir_out}/{nms}/{yr}.csv"), 
    dir_nc = glue("{dir_out}/{nms}/{yr}_nc"), keep_nc = F, n_max_vals_per_req = 1e+05, 
    time_min = time_min, time_max = time_max, verbose = T)
debug: while (i_req <= n_reqs) {
    i_t_beg <- (i_req - 1) * n_t_per_req + 1
    i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
    t_req <- times_todo[c(i_t_beg, i_t_end)]
    t_req_str <- format_ISO8601(t_req, usetz = "Z")
    if (verbose) 
        message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
    ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
        ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
        0), nc)
    unlink(ncs0)
    nc_retry <- T
    nc_n_try <- 1
    n_max_retries
    while (nc_retry) {
        res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
            url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
                bbox[["xmax"]]), latitude = c(bbox[["ymin"]], 
                bbox[["ymax"]]), time = t_req_str, fmt = "nc", 
            store = rerddap::disk(path = dir_nc)))
        if (inherits(res, "try-error")) {
            err <- attr(res, "condition")
            msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
            nc_n_try <- nc_n_try + 1
            if (nc_n_try > n_max_retries) {
                stop(msg)
            }
            else {
                message(msg, "\nRETRYing...")
                Sys.sleep(1)
            }
        }
        else {
            nc_retry <- F
        }
    }
    i_req <- i_req + 1
}
debug: i_t_beg <- (i_req - 1) * n_t_per_req + 1
debug: i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
debug: t_req <- times_todo[c(i_t_beg, i_t_end)]
debug: t_req_str <- format_ISO8601(t_req, usetz = "Z")
debug: if (verbose) message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
debug: message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
Fetching request 1 of 1 (2014-01-01 to 2014-12-01) ~ 19:37:15 UTC
debug: ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
    0), nc)
debug: unlink(ncs0)
debug: nc_retry <- T
debug: nc_n_try <- 1
debug: n_max_retries
debug: while (nc_retry) {
    res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
        url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
            bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
        time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
    if (inherits(res, "try-error")) {
        err <- attr(res, "condition")
        msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
        nc_n_try <- nc_n_try + 1
        if (nc_n_try > n_max_retries) {
            stop(msg)
        }
        else {
            message(msg, "\nRETRYing...")
            Sys.sleep(1)
        }
    }
    else {
        nc_retry <- F
    }
}
debug: res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
    url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
        bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
    time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
debug: if (inherits(res, "try-error")) {
    err <- attr(res, "condition")
    msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
    nc_n_try <- nc_n_try + 1
    if (nc_n_try > n_max_retries) {
        stop(msg)
    }
    else {
        message(msg, "\nRETRYing...")
        Sys.sleep(1)
    }
} else {
    nc_retry <- F
}
debug: nc_retry <- F
debug: (while) nc_retry
debug: i_req <- i_req + 1
debug: (while) i_req <= n_reqs
debug: ncs <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size > 
    0), nc)
debug: r <- terra::rast(ncs)
debug: stopifnot(all(class(terra::time(r)) %in% c("POSIXct", "POSIXt")))
debug: idx <- dplyr::pull(dplyr::filter(dplyr::arrange(dplyr::tibble(idx = 1:terra::nlyr(r), 
    time = terra::time(r)), time), !duplicated(time)), idx)
debug: r <- terra::subset(r, idx)
debug: stopifnot(terra::crs(r, proj = T) == wgs84)
debug: if (mask_tif) r <- terra::mask(r, sf_zones)
debug: lyrs <- glue("{var}|{terra::time(r)}")
debug: if (length(dims_other) > 0 && !all(length(dims[dims_other]) == 
    1)) stop(glue("Other dimensions not yet supported: {paste(dims_other, collapse = ',')}"))
debug: names(r) <- lyrs
debug: if (!is.null(rast_tif)) {
    if (fs::file_exists(rast_tif)) {
        r_tmp_tif <- tempfile(fileext = ".tif")
        r_tmp <- c(rast(rast_tif), r)
        r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
        terra::writeRaster(r_tmp, r_tmp_tif)
        fs::file_delete(rast_tif)
        fs::file_move(r_tmp_tif, rast_tif)
        rm(r)
        rm(r_tmp)
    }
    else {
        terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
    }
    r <- terra::rast(rast_tif)
}
debug: if (fs::file_exists(rast_tif)) {
    r_tmp_tif <- tempfile(fileext = ".tif")
    r_tmp <- c(rast(rast_tif), r)
    r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
    terra::writeRaster(r_tmp, r_tmp_tif)
    fs::file_delete(rast_tif)
    fs::file_move(r_tmp_tif, rast_tif)
    rm(r)
    rm(r_tmp)
} else {
    terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
}
debug: terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
debug: r <- terra::rast(rast_tif)
debug: d_r <- mutate(tidyr::pivot_longer(sf::st_drop_geometry(sf::st_as_sf(terra::zonal(x = r, 
    z = terra::vect(dplyr::select(sf_zones, dplyr::all_of(fld_zones))), 
    fun = zonal_fun, exact = T, na.rm = T, as.polygons = T))), 
    cols = -dplyr::any_of(fld_zones), names_to = "lyr", values_to = zonal_fun), 
    time = readr::parse_datetime(str_replace(lyr, glue("{var}\\|(.*)"), 
        "\\1")))
debug: if (!is.null(zonal_csv)) write_csv(d_r, zonal_csv)
debug: write_csv(d_r, zonal_csv)
debug: if (!keep_nc) unlink(dir_nc, recursive = T)
debug: unlink(dir_nc, recursive = T)
debug: return(d_r)
Downloading 1 requests, up to 167 time slices each
Called from: extractr::ed_extract(ed, var = v, sf_zones = ply, bbox = bb, 
    mask_tif = F, rast_tif = glue("{dir_out}/{nms}/{yr}.tif"), 
    zonal_fun = "mean", zonal_csv = glue("{dir_out}/{nms}/{yr}.csv"), 
    dir_nc = glue("{dir_out}/{nms}/{yr}_nc"), keep_nc = F, n_max_vals_per_req = 1e+05, 
    time_min = time_min, time_max = time_max, verbose = T)
debug: while (i_req <= n_reqs) {
    i_t_beg <- (i_req - 1) * n_t_per_req + 1
    i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
    t_req <- times_todo[c(i_t_beg, i_t_end)]
    t_req_str <- format_ISO8601(t_req, usetz = "Z")
    if (verbose) 
        message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
    ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
        ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
        0), nc)
    unlink(ncs0)
    nc_retry <- T
    nc_n_try <- 1
    n_max_retries
    while (nc_retry) {
        res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
            url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
                bbox[["xmax"]]), latitude = c(bbox[["ymin"]], 
                bbox[["ymax"]]), time = t_req_str, fmt = "nc", 
            store = rerddap::disk(path = dir_nc)))
        if (inherits(res, "try-error")) {
            err <- attr(res, "condition")
            msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
            nc_n_try <- nc_n_try + 1
            if (nc_n_try > n_max_retries) {
                stop(msg)
            }
            else {
                message(msg, "\nRETRYing...")
                Sys.sleep(1)
            }
        }
        else {
            nc_retry <- F
        }
    }
    i_req <- i_req + 1
}
debug: i_t_beg <- (i_req - 1) * n_t_per_req + 1
debug: i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
debug: t_req <- times_todo[c(i_t_beg, i_t_end)]
debug: t_req_str <- format_ISO8601(t_req, usetz = "Z")
debug: if (verbose) message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
debug: message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
Fetching request 1 of 1 (2015-01-01 to 2015-12-01) ~ 19:37:17 UTC
debug: ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
    0), nc)
debug: unlink(ncs0)
debug: nc_retry <- T
debug: nc_n_try <- 1
debug: n_max_retries
debug: while (nc_retry) {
    res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
        url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
            bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
        time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
    if (inherits(res, "try-error")) {
        err <- attr(res, "condition")
        msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
        nc_n_try <- nc_n_try + 1
        if (nc_n_try > n_max_retries) {
            stop(msg)
        }
        else {
            message(msg, "\nRETRYing...")
            Sys.sleep(1)
        }
    }
    else {
        nc_retry <- F
    }
}
debug: res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
    url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
        bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
    time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
debug: if (inherits(res, "try-error")) {
    err <- attr(res, "condition")
    msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
    nc_n_try <- nc_n_try + 1
    if (nc_n_try > n_max_retries) {
        stop(msg)
    }
    else {
        message(msg, "\nRETRYing...")
        Sys.sleep(1)
    }
} else {
    nc_retry <- F
}
debug: nc_retry <- F
debug: (while) nc_retry
debug: i_req <- i_req + 1
debug: (while) i_req <= n_reqs
debug: ncs <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size > 
    0), nc)
debug: r <- terra::rast(ncs)
debug: stopifnot(all(class(terra::time(r)) %in% c("POSIXct", "POSIXt")))
debug: idx <- dplyr::pull(dplyr::filter(dplyr::arrange(dplyr::tibble(idx = 1:terra::nlyr(r), 
    time = terra::time(r)), time), !duplicated(time)), idx)
debug: r <- terra::subset(r, idx)
debug: stopifnot(terra::crs(r, proj = T) == wgs84)
debug: if (mask_tif) r <- terra::mask(r, sf_zones)
debug: lyrs <- glue("{var}|{terra::time(r)}")
debug: if (length(dims_other) > 0 && !all(length(dims[dims_other]) == 
    1)) stop(glue("Other dimensions not yet supported: {paste(dims_other, collapse = ',')}"))
debug: names(r) <- lyrs
debug: if (!is.null(rast_tif)) {
    if (fs::file_exists(rast_tif)) {
        r_tmp_tif <- tempfile(fileext = ".tif")
        r_tmp <- c(rast(rast_tif), r)
        r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
        terra::writeRaster(r_tmp, r_tmp_tif)
        fs::file_delete(rast_tif)
        fs::file_move(r_tmp_tif, rast_tif)
        rm(r)
        rm(r_tmp)
    }
    else {
        terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
    }
    r <- terra::rast(rast_tif)
}
debug: if (fs::file_exists(rast_tif)) {
    r_tmp_tif <- tempfile(fileext = ".tif")
    r_tmp <- c(rast(rast_tif), r)
    r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
    terra::writeRaster(r_tmp, r_tmp_tif)
    fs::file_delete(rast_tif)
    fs::file_move(r_tmp_tif, rast_tif)
    rm(r)
    rm(r_tmp)
} else {
    terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
}
debug: terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
debug: r <- terra::rast(rast_tif)
debug: d_r <- mutate(tidyr::pivot_longer(sf::st_drop_geometry(sf::st_as_sf(terra::zonal(x = r, 
    z = terra::vect(dplyr::select(sf_zones, dplyr::all_of(fld_zones))), 
    fun = zonal_fun, exact = T, na.rm = T, as.polygons = T))), 
    cols = -dplyr::any_of(fld_zones), names_to = "lyr", values_to = zonal_fun), 
    time = readr::parse_datetime(str_replace(lyr, glue("{var}\\|(.*)"), 
        "\\1")))
debug: if (!is.null(zonal_csv)) write_csv(d_r, zonal_csv)
debug: write_csv(d_r, zonal_csv)
debug: if (!keep_nc) unlink(dir_nc, recursive = T)
debug: unlink(dir_nc, recursive = T)
debug: return(d_r)
Downloading 1 requests, up to 167 time slices each
Called from: extractr::ed_extract(ed, var = v, sf_zones = ply, bbox = bb, 
    mask_tif = F, rast_tif = glue("{dir_out}/{nms}/{yr}.tif"), 
    zonal_fun = "mean", zonal_csv = glue("{dir_out}/{nms}/{yr}.csv"), 
    dir_nc = glue("{dir_out}/{nms}/{yr}_nc"), keep_nc = F, n_max_vals_per_req = 1e+05, 
    time_min = time_min, time_max = time_max, verbose = T)
debug: while (i_req <= n_reqs) {
    i_t_beg <- (i_req - 1) * n_t_per_req + 1
    i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
    t_req <- times_todo[c(i_t_beg, i_t_end)]
    t_req_str <- format_ISO8601(t_req, usetz = "Z")
    if (verbose) 
        message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
    ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
        ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
        0), nc)
    unlink(ncs0)
    nc_retry <- T
    nc_n_try <- 1
    n_max_retries
    while (nc_retry) {
        res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
            url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
                bbox[["xmax"]]), latitude = c(bbox[["ymin"]], 
                bbox[["ymax"]]), time = t_req_str, fmt = "nc", 
            store = rerddap::disk(path = dir_nc)))
        if (inherits(res, "try-error")) {
            err <- attr(res, "condition")
            msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
            nc_n_try <- nc_n_try + 1
            if (nc_n_try > n_max_retries) {
                stop(msg)
            }
            else {
                message(msg, "\nRETRYing...")
                Sys.sleep(1)
            }
        }
        else {
            nc_retry <- F
        }
    }
    i_req <- i_req + 1
}
debug: i_t_beg <- (i_req - 1) * n_t_per_req + 1
debug: i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
debug: t_req <- times_todo[c(i_t_beg, i_t_end)]
debug: t_req_str <- format_ISO8601(t_req, usetz = "Z")
debug: if (verbose) message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
debug: message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
Fetching request 1 of 1 (2016-01-01 to 2016-12-01) ~ 19:37:20 UTC
debug: ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
    0), nc)
debug: unlink(ncs0)
debug: nc_retry <- T
debug: nc_n_try <- 1
debug: n_max_retries
debug: while (nc_retry) {
    res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
        url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
            bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
        time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
    if (inherits(res, "try-error")) {
        err <- attr(res, "condition")
        msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
        nc_n_try <- nc_n_try + 1
        if (nc_n_try > n_max_retries) {
            stop(msg)
        }
        else {
            message(msg, "\nRETRYing...")
            Sys.sleep(1)
        }
    }
    else {
        nc_retry <- F
    }
}
debug: res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
    url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
        bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
    time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
debug: if (inherits(res, "try-error")) {
    err <- attr(res, "condition")
    msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
    nc_n_try <- nc_n_try + 1
    if (nc_n_try > n_max_retries) {
        stop(msg)
    }
    else {
        message(msg, "\nRETRYing...")
        Sys.sleep(1)
    }
} else {
    nc_retry <- F
}
debug: nc_retry <- F
debug: (while) nc_retry
debug: i_req <- i_req + 1
debug: (while) i_req <= n_reqs
debug: ncs <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size > 
    0), nc)
debug: r <- terra::rast(ncs)
debug: stopifnot(all(class(terra::time(r)) %in% c("POSIXct", "POSIXt")))
debug: idx <- dplyr::pull(dplyr::filter(dplyr::arrange(dplyr::tibble(idx = 1:terra::nlyr(r), 
    time = terra::time(r)), time), !duplicated(time)), idx)
debug: r <- terra::subset(r, idx)
debug: stopifnot(terra::crs(r, proj = T) == wgs84)
debug: if (mask_tif) r <- terra::mask(r, sf_zones)
debug: lyrs <- glue("{var}|{terra::time(r)}")
debug: if (length(dims_other) > 0 && !all(length(dims[dims_other]) == 
    1)) stop(glue("Other dimensions not yet supported: {paste(dims_other, collapse = ',')}"))
debug: names(r) <- lyrs
debug: if (!is.null(rast_tif)) {
    if (fs::file_exists(rast_tif)) {
        r_tmp_tif <- tempfile(fileext = ".tif")
        r_tmp <- c(rast(rast_tif), r)
        r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
        terra::writeRaster(r_tmp, r_tmp_tif)
        fs::file_delete(rast_tif)
        fs::file_move(r_tmp_tif, rast_tif)
        rm(r)
        rm(r_tmp)
    }
    else {
        terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
    }
    r <- terra::rast(rast_tif)
}
debug: if (fs::file_exists(rast_tif)) {
    r_tmp_tif <- tempfile(fileext = ".tif")
    r_tmp <- c(rast(rast_tif), r)
    r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
    terra::writeRaster(r_tmp, r_tmp_tif)
    fs::file_delete(rast_tif)
    fs::file_move(r_tmp_tif, rast_tif)
    rm(r)
    rm(r_tmp)
} else {
    terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
}
debug: terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
debug: r <- terra::rast(rast_tif)
debug: d_r <- mutate(tidyr::pivot_longer(sf::st_drop_geometry(sf::st_as_sf(terra::zonal(x = r, 
    z = terra::vect(dplyr::select(sf_zones, dplyr::all_of(fld_zones))), 
    fun = zonal_fun, exact = T, na.rm = T, as.polygons = T))), 
    cols = -dplyr::any_of(fld_zones), names_to = "lyr", values_to = zonal_fun), 
    time = readr::parse_datetime(str_replace(lyr, glue("{var}\\|(.*)"), 
        "\\1")))
debug: if (!is.null(zonal_csv)) write_csv(d_r, zonal_csv)
debug: write_csv(d_r, zonal_csv)
debug: if (!keep_nc) unlink(dir_nc, recursive = T)
debug: unlink(dir_nc, recursive = T)
debug: return(d_r)
Downloading 1 requests, up to 167 time slices each
Called from: extractr::ed_extract(ed, var = v, sf_zones = ply, bbox = bb, 
    mask_tif = F, rast_tif = glue("{dir_out}/{nms}/{yr}.tif"), 
    zonal_fun = "mean", zonal_csv = glue("{dir_out}/{nms}/{yr}.csv"), 
    dir_nc = glue("{dir_out}/{nms}/{yr}_nc"), keep_nc = F, n_max_vals_per_req = 1e+05, 
    time_min = time_min, time_max = time_max, verbose = T)
debug: while (i_req <= n_reqs) {
    i_t_beg <- (i_req - 1) * n_t_per_req + 1
    i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
    t_req <- times_todo[c(i_t_beg, i_t_end)]
    t_req_str <- format_ISO8601(t_req, usetz = "Z")
    if (verbose) 
        message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
    ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
        ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
        0), nc)
    unlink(ncs0)
    nc_retry <- T
    nc_n_try <- 1
    n_max_retries
    while (nc_retry) {
        res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
            url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
                bbox[["xmax"]]), latitude = c(bbox[["ymin"]], 
                bbox[["ymax"]]), time = t_req_str, fmt = "nc", 
            store = rerddap::disk(path = dir_nc)))
        if (inherits(res, "try-error")) {
            err <- attr(res, "condition")
            msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
            nc_n_try <- nc_n_try + 1
            if (nc_n_try > n_max_retries) {
                stop(msg)
            }
            else {
                message(msg, "\nRETRYing...")
                Sys.sleep(1)
            }
        }
        else {
            nc_retry <- F
        }
    }
    i_req <- i_req + 1
}
debug: i_t_beg <- (i_req - 1) * n_t_per_req + 1
debug: i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
debug: t_req <- times_todo[c(i_t_beg, i_t_end)]
debug: t_req_str <- format_ISO8601(t_req, usetz = "Z")
debug: if (verbose) message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
debug: message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
Fetching request 1 of 1 (2017-01-01 to 2017-12-01) ~ 19:37:22 UTC
debug: ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
    0), nc)
debug: unlink(ncs0)
debug: nc_retry <- T
debug: nc_n_try <- 1
debug: n_max_retries
debug: while (nc_retry) {
    res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
        url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
            bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
        time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
    if (inherits(res, "try-error")) {
        err <- attr(res, "condition")
        msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
        nc_n_try <- nc_n_try + 1
        if (nc_n_try > n_max_retries) {
            stop(msg)
        }
        else {
            message(msg, "\nRETRYing...")
            Sys.sleep(1)
        }
    }
    else {
        nc_retry <- F
    }
}
debug: res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
    url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
        bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
    time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
debug: if (inherits(res, "try-error")) {
    err <- attr(res, "condition")
    msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
    nc_n_try <- nc_n_try + 1
    if (nc_n_try > n_max_retries) {
        stop(msg)
    }
    else {
        message(msg, "\nRETRYing...")
        Sys.sleep(1)
    }
} else {
    nc_retry <- F
}
debug: nc_retry <- F
debug: (while) nc_retry
debug: i_req <- i_req + 1
debug: (while) i_req <= n_reqs
debug: ncs <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size > 
    0), nc)
debug: r <- terra::rast(ncs)
debug: stopifnot(all(class(terra::time(r)) %in% c("POSIXct", "POSIXt")))
debug: idx <- dplyr::pull(dplyr::filter(dplyr::arrange(dplyr::tibble(idx = 1:terra::nlyr(r), 
    time = terra::time(r)), time), !duplicated(time)), idx)
debug: r <- terra::subset(r, idx)
debug: stopifnot(terra::crs(r, proj = T) == wgs84)
debug: if (mask_tif) r <- terra::mask(r, sf_zones)
debug: lyrs <- glue("{var}|{terra::time(r)}")
debug: if (length(dims_other) > 0 && !all(length(dims[dims_other]) == 
    1)) stop(glue("Other dimensions not yet supported: {paste(dims_other, collapse = ',')}"))
debug: names(r) <- lyrs
debug: if (!is.null(rast_tif)) {
    if (fs::file_exists(rast_tif)) {
        r_tmp_tif <- tempfile(fileext = ".tif")
        r_tmp <- c(rast(rast_tif), r)
        r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
        terra::writeRaster(r_tmp, r_tmp_tif)
        fs::file_delete(rast_tif)
        fs::file_move(r_tmp_tif, rast_tif)
        rm(r)
        rm(r_tmp)
    }
    else {
        terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
    }
    r <- terra::rast(rast_tif)
}
debug: if (fs::file_exists(rast_tif)) {
    r_tmp_tif <- tempfile(fileext = ".tif")
    r_tmp <- c(rast(rast_tif), r)
    r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
    terra::writeRaster(r_tmp, r_tmp_tif)
    fs::file_delete(rast_tif)
    fs::file_move(r_tmp_tif, rast_tif)
    rm(r)
    rm(r_tmp)
} else {
    terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
}
debug: terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
debug: r <- terra::rast(rast_tif)
debug: d_r <- mutate(tidyr::pivot_longer(sf::st_drop_geometry(sf::st_as_sf(terra::zonal(x = r, 
    z = terra::vect(dplyr::select(sf_zones, dplyr::all_of(fld_zones))), 
    fun = zonal_fun, exact = T, na.rm = T, as.polygons = T))), 
    cols = -dplyr::any_of(fld_zones), names_to = "lyr", values_to = zonal_fun), 
    time = readr::parse_datetime(str_replace(lyr, glue("{var}\\|(.*)"), 
        "\\1")))
debug: if (!is.null(zonal_csv)) write_csv(d_r, zonal_csv)
debug: write_csv(d_r, zonal_csv)
debug: if (!keep_nc) unlink(dir_nc, recursive = T)
debug: unlink(dir_nc, recursive = T)
debug: return(d_r)
Downloading 1 requests, up to 167 time slices each
Called from: extractr::ed_extract(ed, var = v, sf_zones = ply, bbox = bb, 
    mask_tif = F, rast_tif = glue("{dir_out}/{nms}/{yr}.tif"), 
    zonal_fun = "mean", zonal_csv = glue("{dir_out}/{nms}/{yr}.csv"), 
    dir_nc = glue("{dir_out}/{nms}/{yr}_nc"), keep_nc = F, n_max_vals_per_req = 1e+05, 
    time_min = time_min, time_max = time_max, verbose = T)
debug: while (i_req <= n_reqs) {
    i_t_beg <- (i_req - 1) * n_t_per_req + 1
    i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
    t_req <- times_todo[c(i_t_beg, i_t_end)]
    t_req_str <- format_ISO8601(t_req, usetz = "Z")
    if (verbose) 
        message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
    ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
        ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
        0), nc)
    unlink(ncs0)
    nc_retry <- T
    nc_n_try <- 1
    n_max_retries
    while (nc_retry) {
        res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
            url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
                bbox[["xmax"]]), latitude = c(bbox[["ymin"]], 
                bbox[["ymax"]]), time = t_req_str, fmt = "nc", 
            store = rerddap::disk(path = dir_nc)))
        if (inherits(res, "try-error")) {
            err <- attr(res, "condition")
            msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
            nc_n_try <- nc_n_try + 1
            if (nc_n_try > n_max_retries) {
                stop(msg)
            }
            else {
                message(msg, "\nRETRYing...")
                Sys.sleep(1)
            }
        }
        else {
            nc_retry <- F
        }
    }
    i_req <- i_req + 1
}
debug: i_t_beg <- (i_req - 1) * n_t_per_req + 1
debug: i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
debug: t_req <- times_todo[c(i_t_beg, i_t_end)]
debug: t_req_str <- format_ISO8601(t_req, usetz = "Z")
debug: if (verbose) message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
debug: message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
Fetching request 1 of 1 (2018-01-01 to 2018-12-01) ~ 19:37:25 UTC
debug: ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
    0), nc)
debug: unlink(ncs0)
debug: nc_retry <- T
debug: nc_n_try <- 1
debug: n_max_retries
debug: while (nc_retry) {
    res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
        url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
            bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
        time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
    if (inherits(res, "try-error")) {
        err <- attr(res, "condition")
        msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
        nc_n_try <- nc_n_try + 1
        if (nc_n_try > n_max_retries) {
            stop(msg)
        }
        else {
            message(msg, "\nRETRYing...")
            Sys.sleep(1)
        }
    }
    else {
        nc_retry <- F
    }
}
debug: res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
    url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
        bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
    time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
debug: if (inherits(res, "try-error")) {
    err <- attr(res, "condition")
    msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
    nc_n_try <- nc_n_try + 1
    if (nc_n_try > n_max_retries) {
        stop(msg)
    }
    else {
        message(msg, "\nRETRYing...")
        Sys.sleep(1)
    }
} else {
    nc_retry <- F
}
debug: nc_retry <- F
debug: (while) nc_retry
debug: i_req <- i_req + 1
debug: (while) i_req <= n_reqs
debug: ncs <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size > 
    0), nc)
debug: r <- terra::rast(ncs)
debug: stopifnot(all(class(terra::time(r)) %in% c("POSIXct", "POSIXt")))
debug: idx <- dplyr::pull(dplyr::filter(dplyr::arrange(dplyr::tibble(idx = 1:terra::nlyr(r), 
    time = terra::time(r)), time), !duplicated(time)), idx)
debug: r <- terra::subset(r, idx)
debug: stopifnot(terra::crs(r, proj = T) == wgs84)
debug: if (mask_tif) r <- terra::mask(r, sf_zones)
debug: lyrs <- glue("{var}|{terra::time(r)}")
debug: if (length(dims_other) > 0 && !all(length(dims[dims_other]) == 
    1)) stop(glue("Other dimensions not yet supported: {paste(dims_other, collapse = ',')}"))
debug: names(r) <- lyrs
debug: if (!is.null(rast_tif)) {
    if (fs::file_exists(rast_tif)) {
        r_tmp_tif <- tempfile(fileext = ".tif")
        r_tmp <- c(rast(rast_tif), r)
        r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
        terra::writeRaster(r_tmp, r_tmp_tif)
        fs::file_delete(rast_tif)
        fs::file_move(r_tmp_tif, rast_tif)
        rm(r)
        rm(r_tmp)
    }
    else {
        terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
    }
    r <- terra::rast(rast_tif)
}
debug: if (fs::file_exists(rast_tif)) {
    r_tmp_tif <- tempfile(fileext = ".tif")
    r_tmp <- c(rast(rast_tif), r)
    r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
    terra::writeRaster(r_tmp, r_tmp_tif)
    fs::file_delete(rast_tif)
    fs::file_move(r_tmp_tif, rast_tif)
    rm(r)
    rm(r_tmp)
} else {
    terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
}
debug: terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
debug: r <- terra::rast(rast_tif)
debug: d_r <- mutate(tidyr::pivot_longer(sf::st_drop_geometry(sf::st_as_sf(terra::zonal(x = r, 
    z = terra::vect(dplyr::select(sf_zones, dplyr::all_of(fld_zones))), 
    fun = zonal_fun, exact = T, na.rm = T, as.polygons = T))), 
    cols = -dplyr::any_of(fld_zones), names_to = "lyr", values_to = zonal_fun), 
    time = readr::parse_datetime(str_replace(lyr, glue("{var}\\|(.*)"), 
        "\\1")))
debug: if (!is.null(zonal_csv)) write_csv(d_r, zonal_csv)
debug: write_csv(d_r, zonal_csv)
debug: if (!keep_nc) unlink(dir_nc, recursive = T)
debug: unlink(dir_nc, recursive = T)
debug: return(d_r)
Downloading 1 requests, up to 167 time slices each
Called from: extractr::ed_extract(ed, var = v, sf_zones = ply, bbox = bb, 
    mask_tif = F, rast_tif = glue("{dir_out}/{nms}/{yr}.tif"), 
    zonal_fun = "mean", zonal_csv = glue("{dir_out}/{nms}/{yr}.csv"), 
    dir_nc = glue("{dir_out}/{nms}/{yr}_nc"), keep_nc = F, n_max_vals_per_req = 1e+05, 
    time_min = time_min, time_max = time_max, verbose = T)
debug: while (i_req <= n_reqs) {
    i_t_beg <- (i_req - 1) * n_t_per_req + 1
    i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
    t_req <- times_todo[c(i_t_beg, i_t_end)]
    t_req_str <- format_ISO8601(t_req, usetz = "Z")
    if (verbose) 
        message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
    ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
        ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
        0), nc)
    unlink(ncs0)
    nc_retry <- T
    nc_n_try <- 1
    n_max_retries
    while (nc_retry) {
        res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
            url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
                bbox[["xmax"]]), latitude = c(bbox[["ymin"]], 
                bbox[["ymax"]]), time = t_req_str, fmt = "nc", 
            store = rerddap::disk(path = dir_nc)))
        if (inherits(res, "try-error")) {
            err <- attr(res, "condition")
            msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
            nc_n_try <- nc_n_try + 1
            if (nc_n_try > n_max_retries) {
                stop(msg)
            }
            else {
                message(msg, "\nRETRYing...")
                Sys.sleep(1)
            }
        }
        else {
            nc_retry <- F
        }
    }
    i_req <- i_req + 1
}
debug: i_t_beg <- (i_req - 1) * n_t_per_req + 1
debug: i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
debug: t_req <- times_todo[c(i_t_beg, i_t_end)]
debug: t_req_str <- format_ISO8601(t_req, usetz = "Z")
debug: if (verbose) message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
debug: message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
Fetching request 1 of 1 (2019-01-01 to 2019-12-01) ~ 19:37:27 UTC
debug: ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
    0), nc)
debug: unlink(ncs0)
debug: nc_retry <- T
debug: nc_n_try <- 1
debug: n_max_retries
debug: while (nc_retry) {
    res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
        url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
            bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
        time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
    if (inherits(res, "try-error")) {
        err <- attr(res, "condition")
        msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
        nc_n_try <- nc_n_try + 1
        if (nc_n_try > n_max_retries) {
            stop(msg)
        }
        else {
            message(msg, "\nRETRYing...")
            Sys.sleep(1)
        }
    }
    else {
        nc_retry <- F
    }
}
debug: res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
    url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
        bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
    time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
debug: if (inherits(res, "try-error")) {
    err <- attr(res, "condition")
    msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
    nc_n_try <- nc_n_try + 1
    if (nc_n_try > n_max_retries) {
        stop(msg)
    }
    else {
        message(msg, "\nRETRYing...")
        Sys.sleep(1)
    }
} else {
    nc_retry <- F
}
debug: nc_retry <- F
debug: (while) nc_retry
debug: i_req <- i_req + 1
debug: (while) i_req <= n_reqs
debug: ncs <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size > 
    0), nc)
debug: r <- terra::rast(ncs)
debug: stopifnot(all(class(terra::time(r)) %in% c("POSIXct", "POSIXt")))
debug: idx <- dplyr::pull(dplyr::filter(dplyr::arrange(dplyr::tibble(idx = 1:terra::nlyr(r), 
    time = terra::time(r)), time), !duplicated(time)), idx)
debug: r <- terra::subset(r, idx)
debug: stopifnot(terra::crs(r, proj = T) == wgs84)
debug: if (mask_tif) r <- terra::mask(r, sf_zones)
debug: lyrs <- glue("{var}|{terra::time(r)}")
debug: if (length(dims_other) > 0 && !all(length(dims[dims_other]) == 
    1)) stop(glue("Other dimensions not yet supported: {paste(dims_other, collapse = ',')}"))
debug: names(r) <- lyrs
debug: if (!is.null(rast_tif)) {
    if (fs::file_exists(rast_tif)) {
        r_tmp_tif <- tempfile(fileext = ".tif")
        r_tmp <- c(rast(rast_tif), r)
        r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
        terra::writeRaster(r_tmp, r_tmp_tif)
        fs::file_delete(rast_tif)
        fs::file_move(r_tmp_tif, rast_tif)
        rm(r)
        rm(r_tmp)
    }
    else {
        terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
    }
    r <- terra::rast(rast_tif)
}
debug: if (fs::file_exists(rast_tif)) {
    r_tmp_tif <- tempfile(fileext = ".tif")
    r_tmp <- c(rast(rast_tif), r)
    r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
    terra::writeRaster(r_tmp, r_tmp_tif)
    fs::file_delete(rast_tif)
    fs::file_move(r_tmp_tif, rast_tif)
    rm(r)
    rm(r_tmp)
} else {
    terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
}
debug: terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
debug: r <- terra::rast(rast_tif)
debug: d_r <- mutate(tidyr::pivot_longer(sf::st_drop_geometry(sf::st_as_sf(terra::zonal(x = r, 
    z = terra::vect(dplyr::select(sf_zones, dplyr::all_of(fld_zones))), 
    fun = zonal_fun, exact = T, na.rm = T, as.polygons = T))), 
    cols = -dplyr::any_of(fld_zones), names_to = "lyr", values_to = zonal_fun), 
    time = readr::parse_datetime(str_replace(lyr, glue("{var}\\|(.*)"), 
        "\\1")))
debug: if (!is.null(zonal_csv)) write_csv(d_r, zonal_csv)
debug: write_csv(d_r, zonal_csv)
debug: if (!keep_nc) unlink(dir_nc, recursive = T)
debug: unlink(dir_nc, recursive = T)
debug: return(d_r)
Downloading 1 requests, up to 167 time slices each
Called from: extractr::ed_extract(ed, var = v, sf_zones = ply, bbox = bb, 
    mask_tif = F, rast_tif = glue("{dir_out}/{nms}/{yr}.tif"), 
    zonal_fun = "mean", zonal_csv = glue("{dir_out}/{nms}/{yr}.csv"), 
    dir_nc = glue("{dir_out}/{nms}/{yr}_nc"), keep_nc = F, n_max_vals_per_req = 1e+05, 
    time_min = time_min, time_max = time_max, verbose = T)
debug: while (i_req <= n_reqs) {
    i_t_beg <- (i_req - 1) * n_t_per_req + 1
    i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
    t_req <- times_todo[c(i_t_beg, i_t_end)]
    t_req_str <- format_ISO8601(t_req, usetz = "Z")
    if (verbose) 
        message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
    ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
        ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
        0), nc)
    unlink(ncs0)
    nc_retry <- T
    nc_n_try <- 1
    n_max_retries
    while (nc_retry) {
        res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
            url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
                bbox[["xmax"]]), latitude = c(bbox[["ymin"]], 
                bbox[["ymax"]]), time = t_req_str, fmt = "nc", 
            store = rerddap::disk(path = dir_nc)))
        if (inherits(res, "try-error")) {
            err <- attr(res, "condition")
            msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
            nc_n_try <- nc_n_try + 1
            if (nc_n_try > n_max_retries) {
                stop(msg)
            }
            else {
                message(msg, "\nRETRYing...")
                Sys.sleep(1)
            }
        }
        else {
            nc_retry <- F
        }
    }
    i_req <- i_req + 1
}
debug: i_t_beg <- (i_req - 1) * n_t_per_req + 1
debug: i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
debug: t_req <- times_todo[c(i_t_beg, i_t_end)]
debug: t_req_str <- format_ISO8601(t_req, usetz = "Z")
debug: if (verbose) message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
debug: message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
Fetching request 1 of 1 (2020-01-01 to 2020-12-01) ~ 19:37:30 UTC
debug: ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
    0), nc)
debug: unlink(ncs0)
debug: nc_retry <- T
debug: nc_n_try <- 1
debug: n_max_retries
debug: while (nc_retry) {
    res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
        url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
            bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
        time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
    if (inherits(res, "try-error")) {
        err <- attr(res, "condition")
        msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
        nc_n_try <- nc_n_try + 1
        if (nc_n_try > n_max_retries) {
            stop(msg)
        }
        else {
            message(msg, "\nRETRYing...")
            Sys.sleep(1)
        }
    }
    else {
        nc_retry <- F
    }
}
debug: res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
    url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
        bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
    time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
debug: if (inherits(res, "try-error")) {
    err <- attr(res, "condition")
    msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
    nc_n_try <- nc_n_try + 1
    if (nc_n_try > n_max_retries) {
        stop(msg)
    }
    else {
        message(msg, "\nRETRYing...")
        Sys.sleep(1)
    }
} else {
    nc_retry <- F
}
debug: nc_retry <- F
debug: (while) nc_retry
debug: i_req <- i_req + 1
debug: (while) i_req <= n_reqs
debug: ncs <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size > 
    0), nc)
debug: r <- terra::rast(ncs)
debug: stopifnot(all(class(terra::time(r)) %in% c("POSIXct", "POSIXt")))
debug: idx <- dplyr::pull(dplyr::filter(dplyr::arrange(dplyr::tibble(idx = 1:terra::nlyr(r), 
    time = terra::time(r)), time), !duplicated(time)), idx)
debug: r <- terra::subset(r, idx)
debug: stopifnot(terra::crs(r, proj = T) == wgs84)
debug: if (mask_tif) r <- terra::mask(r, sf_zones)
debug: lyrs <- glue("{var}|{terra::time(r)}")
debug: if (length(dims_other) > 0 && !all(length(dims[dims_other]) == 
    1)) stop(glue("Other dimensions not yet supported: {paste(dims_other, collapse = ',')}"))
debug: names(r) <- lyrs
debug: if (!is.null(rast_tif)) {
    if (fs::file_exists(rast_tif)) {
        r_tmp_tif <- tempfile(fileext = ".tif")
        r_tmp <- c(rast(rast_tif), r)
        r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
        terra::writeRaster(r_tmp, r_tmp_tif)
        fs::file_delete(rast_tif)
        fs::file_move(r_tmp_tif, rast_tif)
        rm(r)
        rm(r_tmp)
    }
    else {
        terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
    }
    r <- terra::rast(rast_tif)
}
debug: if (fs::file_exists(rast_tif)) {
    r_tmp_tif <- tempfile(fileext = ".tif")
    r_tmp <- c(rast(rast_tif), r)
    r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
    terra::writeRaster(r_tmp, r_tmp_tif)
    fs::file_delete(rast_tif)
    fs::file_move(r_tmp_tif, rast_tif)
    rm(r)
    rm(r_tmp)
} else {
    terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
}
debug: terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
debug: r <- terra::rast(rast_tif)
debug: d_r <- mutate(tidyr::pivot_longer(sf::st_drop_geometry(sf::st_as_sf(terra::zonal(x = r, 
    z = terra::vect(dplyr::select(sf_zones, dplyr::all_of(fld_zones))), 
    fun = zonal_fun, exact = T, na.rm = T, as.polygons = T))), 
    cols = -dplyr::any_of(fld_zones), names_to = "lyr", values_to = zonal_fun), 
    time = readr::parse_datetime(str_replace(lyr, glue("{var}\\|(.*)"), 
        "\\1")))
debug: if (!is.null(zonal_csv)) write_csv(d_r, zonal_csv)
debug: write_csv(d_r, zonal_csv)
debug: if (!keep_nc) unlink(dir_nc, recursive = T)
debug: unlink(dir_nc, recursive = T)
debug: return(d_r)
Downloading 1 requests, up to 167 time slices each
Called from: extractr::ed_extract(ed, var = v, sf_zones = ply, bbox = bb, 
    mask_tif = F, rast_tif = glue("{dir_out}/{nms}/{yr}.tif"), 
    zonal_fun = "mean", zonal_csv = glue("{dir_out}/{nms}/{yr}.csv"), 
    dir_nc = glue("{dir_out}/{nms}/{yr}_nc"), keep_nc = F, n_max_vals_per_req = 1e+05, 
    time_min = time_min, time_max = time_max, verbose = T)
debug: while (i_req <= n_reqs) {
    i_t_beg <- (i_req - 1) * n_t_per_req + 1
    i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
    t_req <- times_todo[c(i_t_beg, i_t_end)]
    t_req_str <- format_ISO8601(t_req, usetz = "Z")
    if (verbose) 
        message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
    ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
        ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
        0), nc)
    unlink(ncs0)
    nc_retry <- T
    nc_n_try <- 1
    n_max_retries
    while (nc_retry) {
        res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
            url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
                bbox[["xmax"]]), latitude = c(bbox[["ymin"]], 
                bbox[["ymax"]]), time = t_req_str, fmt = "nc", 
            store = rerddap::disk(path = dir_nc)))
        if (inherits(res, "try-error")) {
            err <- attr(res, "condition")
            msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
            nc_n_try <- nc_n_try + 1
            if (nc_n_try > n_max_retries) {
                stop(msg)
            }
            else {
                message(msg, "\nRETRYing...")
                Sys.sleep(1)
            }
        }
        else {
            nc_retry <- F
        }
    }
    i_req <- i_req + 1
}
debug: i_t_beg <- (i_req - 1) * n_t_per_req + 1
debug: i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
debug: t_req <- times_todo[c(i_t_beg, i_t_end)]
debug: t_req_str <- format_ISO8601(t_req, usetz = "Z")
debug: if (verbose) message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
debug: message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
Fetching request 1 of 1 (2021-01-01 to 2021-12-01) ~ 19:37:32 UTC
debug: ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
    0), nc)
debug: unlink(ncs0)
debug: nc_retry <- T
debug: nc_n_try <- 1
debug: n_max_retries
debug: while (nc_retry) {
    res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
        url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
            bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
        time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
    if (inherits(res, "try-error")) {
        err <- attr(res, "condition")
        msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
        nc_n_try <- nc_n_try + 1
        if (nc_n_try > n_max_retries) {
            stop(msg)
        }
        else {
            message(msg, "\nRETRYing...")
            Sys.sleep(1)
        }
    }
    else {
        nc_retry <- F
    }
}
debug: res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
    url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
        bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
    time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
debug: if (inherits(res, "try-error")) {
    err <- attr(res, "condition")
    msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
    nc_n_try <- nc_n_try + 1
    if (nc_n_try > n_max_retries) {
        stop(msg)
    }
    else {
        message(msg, "\nRETRYing...")
        Sys.sleep(1)
    }
} else {
    nc_retry <- F
}
debug: nc_retry <- F
debug: (while) nc_retry
debug: i_req <- i_req + 1
debug: (while) i_req <= n_reqs
debug: ncs <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size > 
    0), nc)
debug: r <- terra::rast(ncs)
debug: stopifnot(all(class(terra::time(r)) %in% c("POSIXct", "POSIXt")))
debug: idx <- dplyr::pull(dplyr::filter(dplyr::arrange(dplyr::tibble(idx = 1:terra::nlyr(r), 
    time = terra::time(r)), time), !duplicated(time)), idx)
debug: r <- terra::subset(r, idx)
debug: stopifnot(terra::crs(r, proj = T) == wgs84)
debug: if (mask_tif) r <- terra::mask(r, sf_zones)
debug: lyrs <- glue("{var}|{terra::time(r)}")
debug: if (length(dims_other) > 0 && !all(length(dims[dims_other]) == 
    1)) stop(glue("Other dimensions not yet supported: {paste(dims_other, collapse = ',')}"))
debug: names(r) <- lyrs
debug: if (!is.null(rast_tif)) {
    if (fs::file_exists(rast_tif)) {
        r_tmp_tif <- tempfile(fileext = ".tif")
        r_tmp <- c(rast(rast_tif), r)
        r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
        terra::writeRaster(r_tmp, r_tmp_tif)
        fs::file_delete(rast_tif)
        fs::file_move(r_tmp_tif, rast_tif)
        rm(r)
        rm(r_tmp)
    }
    else {
        terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
    }
    r <- terra::rast(rast_tif)
}
debug: if (fs::file_exists(rast_tif)) {
    r_tmp_tif <- tempfile(fileext = ".tif")
    r_tmp <- c(rast(rast_tif), r)
    r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
    terra::writeRaster(r_tmp, r_tmp_tif)
    fs::file_delete(rast_tif)
    fs::file_move(r_tmp_tif, rast_tif)
    rm(r)
    rm(r_tmp)
} else {
    terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
}
debug: terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
debug: r <- terra::rast(rast_tif)
debug: d_r <- mutate(tidyr::pivot_longer(sf::st_drop_geometry(sf::st_as_sf(terra::zonal(x = r, 
    z = terra::vect(dplyr::select(sf_zones, dplyr::all_of(fld_zones))), 
    fun = zonal_fun, exact = T, na.rm = T, as.polygons = T))), 
    cols = -dplyr::any_of(fld_zones), names_to = "lyr", values_to = zonal_fun), 
    time = readr::parse_datetime(str_replace(lyr, glue("{var}\\|(.*)"), 
        "\\1")))
debug: if (!is.null(zonal_csv)) write_csv(d_r, zonal_csv)
debug: write_csv(d_r, zonal_csv)
debug: if (!keep_nc) unlink(dir_nc, recursive = T)
debug: unlink(dir_nc, recursive = T)
debug: return(d_r)
Downloading 1 requests, up to 167 time slices each
Called from: extractr::ed_extract(ed, var = v, sf_zones = ply, bbox = bb, 
    mask_tif = F, rast_tif = glue("{dir_out}/{nms}/{yr}.tif"), 
    zonal_fun = "mean", zonal_csv = glue("{dir_out}/{nms}/{yr}.csv"), 
    dir_nc = glue("{dir_out}/{nms}/{yr}_nc"), keep_nc = F, n_max_vals_per_req = 1e+05, 
    time_min = time_min, time_max = time_max, verbose = T)
debug: while (i_req <= n_reqs) {
    i_t_beg <- (i_req - 1) * n_t_per_req + 1
    i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
    t_req <- times_todo[c(i_t_beg, i_t_end)]
    t_req_str <- format_ISO8601(t_req, usetz = "Z")
    if (verbose) 
        message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
    ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
        ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
        0), nc)
    unlink(ncs0)
    nc_retry <- T
    nc_n_try <- 1
    n_max_retries
    while (nc_retry) {
        res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
            url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
                bbox[["xmax"]]), latitude = c(bbox[["ymin"]], 
                bbox[["ymax"]]), time = t_req_str, fmt = "nc", 
            store = rerddap::disk(path = dir_nc)))
        if (inherits(res, "try-error")) {
            err <- attr(res, "condition")
            msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
            nc_n_try <- nc_n_try + 1
            if (nc_n_try > n_max_retries) {
                stop(msg)
            }
            else {
                message(msg, "\nRETRYing...")
                Sys.sleep(1)
            }
        }
        else {
            nc_retry <- F
        }
    }
    i_req <- i_req + 1
}
debug: i_t_beg <- (i_req - 1) * n_t_per_req + 1
debug: i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
debug: t_req <- times_todo[c(i_t_beg, i_t_end)]
debug: t_req_str <- format_ISO8601(t_req, usetz = "Z")
debug: if (verbose) message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
debug: message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
Fetching request 1 of 1 (2022-01-01 to 2022-12-01) ~ 19:37:35 UTC
debug: ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
    0), nc)
debug: unlink(ncs0)
debug: nc_retry <- T
debug: nc_n_try <- 1
debug: n_max_retries
debug: while (nc_retry) {
    res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
        url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
            bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
        time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
    if (inherits(res, "try-error")) {
        err <- attr(res, "condition")
        msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
        nc_n_try <- nc_n_try + 1
        if (nc_n_try > n_max_retries) {
            stop(msg)
        }
        else {
            message(msg, "\nRETRYing...")
            Sys.sleep(1)
        }
    }
    else {
        nc_retry <- F
    }
}
debug: res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
    url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
        bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
    time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
debug: if (inherits(res, "try-error")) {
    err <- attr(res, "condition")
    msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
    nc_n_try <- nc_n_try + 1
    if (nc_n_try > n_max_retries) {
        stop(msg)
    }
    else {
        message(msg, "\nRETRYing...")
        Sys.sleep(1)
    }
} else {
    nc_retry <- F
}
debug: nc_retry <- F
debug: (while) nc_retry
debug: i_req <- i_req + 1
debug: (while) i_req <= n_reqs
debug: ncs <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size > 
    0), nc)
debug: r <- terra::rast(ncs)
debug: stopifnot(all(class(terra::time(r)) %in% c("POSIXct", "POSIXt")))
debug: idx <- dplyr::pull(dplyr::filter(dplyr::arrange(dplyr::tibble(idx = 1:terra::nlyr(r), 
    time = terra::time(r)), time), !duplicated(time)), idx)
debug: r <- terra::subset(r, idx)
debug: stopifnot(terra::crs(r, proj = T) == wgs84)
debug: if (mask_tif) r <- terra::mask(r, sf_zones)
debug: lyrs <- glue("{var}|{terra::time(r)}")
debug: if (length(dims_other) > 0 && !all(length(dims[dims_other]) == 
    1)) stop(glue("Other dimensions not yet supported: {paste(dims_other, collapse = ',')}"))
debug: names(r) <- lyrs
debug: if (!is.null(rast_tif)) {
    if (fs::file_exists(rast_tif)) {
        r_tmp_tif <- tempfile(fileext = ".tif")
        r_tmp <- c(rast(rast_tif), r)
        r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
        terra::writeRaster(r_tmp, r_tmp_tif)
        fs::file_delete(rast_tif)
        fs::file_move(r_tmp_tif, rast_tif)
        rm(r)
        rm(r_tmp)
    }
    else {
        terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
    }
    r <- terra::rast(rast_tif)
}
debug: if (fs::file_exists(rast_tif)) {
    r_tmp_tif <- tempfile(fileext = ".tif")
    r_tmp <- c(rast(rast_tif), r)
    r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
    terra::writeRaster(r_tmp, r_tmp_tif)
    fs::file_delete(rast_tif)
    fs::file_move(r_tmp_tif, rast_tif)
    rm(r)
    rm(r_tmp)
} else {
    terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
}
debug: terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
debug: r <- terra::rast(rast_tif)
debug: d_r <- mutate(tidyr::pivot_longer(sf::st_drop_geometry(sf::st_as_sf(terra::zonal(x = r, 
    z = terra::vect(dplyr::select(sf_zones, dplyr::all_of(fld_zones))), 
    fun = zonal_fun, exact = T, na.rm = T, as.polygons = T))), 
    cols = -dplyr::any_of(fld_zones), names_to = "lyr", values_to = zonal_fun), 
    time = readr::parse_datetime(str_replace(lyr, glue("{var}\\|(.*)"), 
        "\\1")))
debug: if (!is.null(zonal_csv)) write_csv(d_r, zonal_csv)
debug: write_csv(d_r, zonal_csv)
debug: if (!keep_nc) unlink(dir_nc, recursive = T)
debug: unlink(dir_nc, recursive = T)
debug: return(d_r)
Downloading 1 requests, up to 167 time slices each
Called from: extractr::ed_extract(ed, var = v, sf_zones = ply, bbox = bb, 
    mask_tif = F, rast_tif = glue("{dir_out}/{nms}/{yr}.tif"), 
    zonal_fun = "mean", zonal_csv = glue("{dir_out}/{nms}/{yr}.csv"), 
    dir_nc = glue("{dir_out}/{nms}/{yr}_nc"), keep_nc = F, n_max_vals_per_req = 1e+05, 
    time_min = time_min, time_max = time_max, verbose = T)
debug: while (i_req <= n_reqs) {
    i_t_beg <- (i_req - 1) * n_t_per_req + 1
    i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
    t_req <- times_todo[c(i_t_beg, i_t_end)]
    t_req_str <- format_ISO8601(t_req, usetz = "Z")
    if (verbose) 
        message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
    ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
        ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
        0), nc)
    unlink(ncs0)
    nc_retry <- T
    nc_n_try <- 1
    n_max_retries
    while (nc_retry) {
        res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
            url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
                bbox[["xmax"]]), latitude = c(bbox[["ymin"]], 
                bbox[["ymax"]]), time = t_req_str, fmt = "nc", 
            store = rerddap::disk(path = dir_nc)))
        if (inherits(res, "try-error")) {
            err <- attr(res, "condition")
            msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
            nc_n_try <- nc_n_try + 1
            if (nc_n_try > n_max_retries) {
                stop(msg)
            }
            else {
                message(msg, "\nRETRYing...")
                Sys.sleep(1)
            }
        }
        else {
            nc_retry <- F
        }
    }
    i_req <- i_req + 1
}
debug: i_t_beg <- (i_req - 1) * n_t_per_req + 1
debug: i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
debug: t_req <- times_todo[c(i_t_beg, i_t_end)]
debug: t_req_str <- format_ISO8601(t_req, usetz = "Z")
debug: if (verbose) message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
debug: message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
Fetching request 1 of 1 (2023-01-01 to 2023-12-01) ~ 19:37:38 UTC
debug: ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
    0), nc)
debug: unlink(ncs0)
debug: nc_retry <- T
debug: nc_n_try <- 1
debug: n_max_retries
debug: while (nc_retry) {
    res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
        url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
            bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
        time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
    if (inherits(res, "try-error")) {
        err <- attr(res, "condition")
        msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
        nc_n_try <- nc_n_try + 1
        if (nc_n_try > n_max_retries) {
            stop(msg)
        }
        else {
            message(msg, "\nRETRYing...")
            Sys.sleep(1)
        }
    }
    else {
        nc_retry <- F
    }
}
debug: res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
    url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
        bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
    time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
debug: if (inherits(res, "try-error")) {
    err <- attr(res, "condition")
    msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
    nc_n_try <- nc_n_try + 1
    if (nc_n_try > n_max_retries) {
        stop(msg)
    }
    else {
        message(msg, "\nRETRYing...")
        Sys.sleep(1)
    }
} else {
    nc_retry <- F
}
debug: nc_retry <- F
debug: (while) nc_retry
debug: i_req <- i_req + 1
debug: (while) i_req <= n_reqs
debug: ncs <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size > 
    0), nc)
debug: r <- terra::rast(ncs)
debug: stopifnot(all(class(terra::time(r)) %in% c("POSIXct", "POSIXt")))
debug: idx <- dplyr::pull(dplyr::filter(dplyr::arrange(dplyr::tibble(idx = 1:terra::nlyr(r), 
    time = terra::time(r)), time), !duplicated(time)), idx)
debug: r <- terra::subset(r, idx)
debug: stopifnot(terra::crs(r, proj = T) == wgs84)
debug: if (mask_tif) r <- terra::mask(r, sf_zones)
debug: lyrs <- glue("{var}|{terra::time(r)}")
debug: if (length(dims_other) > 0 && !all(length(dims[dims_other]) == 
    1)) stop(glue("Other dimensions not yet supported: {paste(dims_other, collapse = ',')}"))
debug: names(r) <- lyrs
debug: if (!is.null(rast_tif)) {
    if (fs::file_exists(rast_tif)) {
        r_tmp_tif <- tempfile(fileext = ".tif")
        r_tmp <- c(rast(rast_tif), r)
        r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
        terra::writeRaster(r_tmp, r_tmp_tif)
        fs::file_delete(rast_tif)
        fs::file_move(r_tmp_tif, rast_tif)
        rm(r)
        rm(r_tmp)
    }
    else {
        terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
    }
    r <- terra::rast(rast_tif)
}
debug: if (fs::file_exists(rast_tif)) {
    r_tmp_tif <- tempfile(fileext = ".tif")
    r_tmp <- c(rast(rast_tif), r)
    r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
    terra::writeRaster(r_tmp, r_tmp_tif)
    fs::file_delete(rast_tif)
    fs::file_move(r_tmp_tif, rast_tif)
    rm(r)
    rm(r_tmp)
} else {
    terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
}
debug: terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
debug: r <- terra::rast(rast_tif)
debug: d_r <- mutate(tidyr::pivot_longer(sf::st_drop_geometry(sf::st_as_sf(terra::zonal(x = r, 
    z = terra::vect(dplyr::select(sf_zones, dplyr::all_of(fld_zones))), 
    fun = zonal_fun, exact = T, na.rm = T, as.polygons = T))), 
    cols = -dplyr::any_of(fld_zones), names_to = "lyr", values_to = zonal_fun), 
    time = readr::parse_datetime(str_replace(lyr, glue("{var}\\|(.*)"), 
        "\\1")))
debug: if (!is.null(zonal_csv)) write_csv(d_r, zonal_csv)
debug: write_csv(d_r, zonal_csv)
debug: if (!keep_nc) unlink(dir_nc, recursive = T)
debug: unlink(dir_nc, recursive = T)
debug: return(d_r)
Downloading 1 requests, up to 167 time slices each
Called from: extractr::ed_extract(ed, var = v, sf_zones = ply, bbox = bb, 
    mask_tif = F, rast_tif = glue("{dir_out}/{nms}/{yr}.tif"), 
    zonal_fun = "mean", zonal_csv = glue("{dir_out}/{nms}/{yr}.csv"), 
    dir_nc = glue("{dir_out}/{nms}/{yr}_nc"), keep_nc = F, n_max_vals_per_req = 1e+05, 
    time_min = time_min, time_max = time_max, verbose = T)
debug: while (i_req <= n_reqs) {
    i_t_beg <- (i_req - 1) * n_t_per_req + 1
    i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
    t_req <- times_todo[c(i_t_beg, i_t_end)]
    t_req_str <- format_ISO8601(t_req, usetz = "Z")
    if (verbose) 
        message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
    ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
        ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
        0), nc)
    unlink(ncs0)
    nc_retry <- T
    nc_n_try <- 1
    n_max_retries
    while (nc_retry) {
        res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
            url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
                bbox[["xmax"]]), latitude = c(bbox[["ymin"]], 
                bbox[["ymax"]]), time = t_req_str, fmt = "nc", 
            store = rerddap::disk(path = dir_nc)))
        if (inherits(res, "try-error")) {
            err <- attr(res, "condition")
            msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
            nc_n_try <- nc_n_try + 1
            if (nc_n_try > n_max_retries) {
                stop(msg)
            }
            else {
                message(msg, "\nRETRYing...")
                Sys.sleep(1)
            }
        }
        else {
            nc_retry <- F
        }
    }
    i_req <- i_req + 1
}
debug: i_t_beg <- (i_req - 1) * n_t_per_req + 1
debug: i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
debug: t_req <- times_todo[c(i_t_beg, i_t_end)]
debug: t_req_str <- format_ISO8601(t_req, usetz = "Z")
debug: if (verbose) message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
debug: message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
Fetching request 1 of 1 (2024-01-01 to 2024-12-01) ~ 19:37:40 UTC
debug: ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
    0), nc)
debug: unlink(ncs0)
debug: nc_retry <- T
debug: nc_n_try <- 1
debug: n_max_retries
debug: while (nc_retry) {
    res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
        url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
            bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
        time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
    if (inherits(res, "try-error")) {
        err <- attr(res, "condition")
        msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
        nc_n_try <- nc_n_try + 1
        if (nc_n_try > n_max_retries) {
            stop(msg)
        }
        else {
            message(msg, "\nRETRYing...")
            Sys.sleep(1)
        }
    }
    else {
        nc_retry <- F
    }
}
debug: res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
    url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
        bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
    time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
debug: if (inherits(res, "try-error")) {
    err <- attr(res, "condition")
    msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
    nc_n_try <- nc_n_try + 1
    if (nc_n_try > n_max_retries) {
        stop(msg)
    }
    else {
        message(msg, "\nRETRYing...")
        Sys.sleep(1)
    }
} else {
    nc_retry <- F
}
debug: nc_retry <- F
debug: (while) nc_retry
debug: i_req <- i_req + 1
debug: (while) i_req <= n_reqs
debug: ncs <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size > 
    0), nc)
debug: r <- terra::rast(ncs)
debug: stopifnot(all(class(terra::time(r)) %in% c("POSIXct", "POSIXt")))
debug: idx <- dplyr::pull(dplyr::filter(dplyr::arrange(dplyr::tibble(idx = 1:terra::nlyr(r), 
    time = terra::time(r)), time), !duplicated(time)), idx)
debug: r <- terra::subset(r, idx)
debug: stopifnot(terra::crs(r, proj = T) == wgs84)
debug: if (mask_tif) r <- terra::mask(r, sf_zones)
debug: lyrs <- glue("{var}|{terra::time(r)}")
debug: if (length(dims_other) > 0 && !all(length(dims[dims_other]) == 
    1)) stop(glue("Other dimensions not yet supported: {paste(dims_other, collapse = ',')}"))
debug: names(r) <- lyrs
debug: if (!is.null(rast_tif)) {
    if (fs::file_exists(rast_tif)) {
        r_tmp_tif <- tempfile(fileext = ".tif")
        r_tmp <- c(rast(rast_tif), r)
        r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
        terra::writeRaster(r_tmp, r_tmp_tif)
        fs::file_delete(rast_tif)
        fs::file_move(r_tmp_tif, rast_tif)
        rm(r)
        rm(r_tmp)
    }
    else {
        terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
    }
    r <- terra::rast(rast_tif)
}
debug: if (fs::file_exists(rast_tif)) {
    r_tmp_tif <- tempfile(fileext = ".tif")
    r_tmp <- c(rast(rast_tif), r)
    r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
    terra::writeRaster(r_tmp, r_tmp_tif)
    fs::file_delete(rast_tif)
    fs::file_move(r_tmp_tif, rast_tif)
    rm(r)
    rm(r_tmp)
} else {
    terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
}
debug: terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
debug: r <- terra::rast(rast_tif)
debug: d_r <- mutate(tidyr::pivot_longer(sf::st_drop_geometry(sf::st_as_sf(terra::zonal(x = r, 
    z = terra::vect(dplyr::select(sf_zones, dplyr::all_of(fld_zones))), 
    fun = zonal_fun, exact = T, na.rm = T, as.polygons = T))), 
    cols = -dplyr::any_of(fld_zones), names_to = "lyr", values_to = zonal_fun), 
    time = readr::parse_datetime(str_replace(lyr, glue("{var}\\|(.*)"), 
        "\\1")))
debug: if (!is.null(zonal_csv)) write_csv(d_r, zonal_csv)
debug: write_csv(d_r, zonal_csv)
debug: if (!keep_nc) unlink(dir_nc, recursive = T)
debug: unlink(dir_nc, recursive = T)
debug: return(d_r)
Downloading 1 requests, up to 167 time slices each
Called from: extractr::ed_extract(ed, var = v, sf_zones = ply, bbox = bb, 
    mask_tif = F, rast_tif = glue("{dir_out}/{nms}/{yr}.tif"), 
    zonal_fun = "mean", zonal_csv = glue("{dir_out}/{nms}/{yr}.csv"), 
    dir_nc = glue("{dir_out}/{nms}/{yr}_nc"), keep_nc = F, n_max_vals_per_req = 1e+05, 
    time_min = time_min, time_max = time_max, verbose = T)
debug: while (i_req <= n_reqs) {
    i_t_beg <- (i_req - 1) * n_t_per_req + 1
    i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
    t_req <- times_todo[c(i_t_beg, i_t_end)]
    t_req_str <- format_ISO8601(t_req, usetz = "Z")
    if (verbose) 
        message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
    ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
        ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
        0), nc)
    unlink(ncs0)
    nc_retry <- T
    nc_n_try <- 1
    n_max_retries
    while (nc_retry) {
        res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
            url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
                bbox[["xmax"]]), latitude = c(bbox[["ymin"]], 
                bbox[["ymax"]]), time = t_req_str, fmt = "nc", 
            store = rerddap::disk(path = dir_nc)))
        if (inherits(res, "try-error")) {
            err <- attr(res, "condition")
            msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
            nc_n_try <- nc_n_try + 1
            if (nc_n_try > n_max_retries) {
                stop(msg)
            }
            else {
                message(msg, "\nRETRYing...")
                Sys.sleep(1)
            }
        }
        else {
            nc_retry <- F
        }
    }
    i_req <- i_req + 1
}
debug: i_t_beg <- (i_req - 1) * n_t_per_req + 1
debug: i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
debug: t_req <- times_todo[c(i_t_beg, i_t_end)]
debug: t_req_str <- format_ISO8601(t_req, usetz = "Z")
debug: if (verbose) message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
debug: message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
Fetching request 1 of 1 (2025-01-01 to 2025-07-01) ~ 19:37:43 UTC
debug: ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
    0), nc)
debug: unlink(ncs0)
debug: nc_retry <- T
debug: nc_n_try <- 1
debug: n_max_retries
debug: while (nc_retry) {
    res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
        url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
            bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
        time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
    if (inherits(res, "try-error")) {
        err <- attr(res, "condition")
        msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
        nc_n_try <- nc_n_try + 1
        if (nc_n_try > n_max_retries) {
            stop(msg)
        }
        else {
            message(msg, "\nRETRYing...")
            Sys.sleep(1)
        }
    }
    else {
        nc_retry <- F
    }
}
debug: res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
    url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
        bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
    time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
debug: if (inherits(res, "try-error")) {
    err <- attr(res, "condition")
    msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
    nc_n_try <- nc_n_try + 1
    if (nc_n_try > n_max_retries) {
        stop(msg)
    }
    else {
        message(msg, "\nRETRYing...")
        Sys.sleep(1)
    }
} else {
    nc_retry <- F
}
debug: nc_retry <- F
debug: (while) nc_retry
debug: i_req <- i_req + 1
debug: (while) i_req <= n_reqs
debug: ncs <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size > 
    0), nc)
debug: r <- terra::rast(ncs)
debug: stopifnot(all(class(terra::time(r)) %in% c("POSIXct", "POSIXt")))
debug: idx <- dplyr::pull(dplyr::filter(dplyr::arrange(dplyr::tibble(idx = 1:terra::nlyr(r), 
    time = terra::time(r)), time), !duplicated(time)), idx)
debug: r <- terra::subset(r, idx)
debug: stopifnot(terra::crs(r, proj = T) == wgs84)
debug: if (mask_tif) r <- terra::mask(r, sf_zones)
debug: lyrs <- glue("{var}|{terra::time(r)}")
debug: if (length(dims_other) > 0 && !all(length(dims[dims_other]) == 
    1)) stop(glue("Other dimensions not yet supported: {paste(dims_other, collapse = ',')}"))
debug: names(r) <- lyrs
debug: if (!is.null(rast_tif)) {
    if (fs::file_exists(rast_tif)) {
        r_tmp_tif <- tempfile(fileext = ".tif")
        r_tmp <- c(rast(rast_tif), r)
        r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
        terra::writeRaster(r_tmp, r_tmp_tif)
        fs::file_delete(rast_tif)
        fs::file_move(r_tmp_tif, rast_tif)
        rm(r)
        rm(r_tmp)
    }
    else {
        terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
    }
    r <- terra::rast(rast_tif)
}
debug: if (fs::file_exists(rast_tif)) {
    r_tmp_tif <- tempfile(fileext = ".tif")
    r_tmp <- c(rast(rast_tif), r)
    r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
    terra::writeRaster(r_tmp, r_tmp_tif)
    fs::file_delete(rast_tif)
    fs::file_move(r_tmp_tif, rast_tif)
    rm(r)
    rm(r_tmp)
} else {
    terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
}
debug: terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
debug: r <- terra::rast(rast_tif)
debug: d_r <- mutate(tidyr::pivot_longer(sf::st_drop_geometry(sf::st_as_sf(terra::zonal(x = r, 
    z = terra::vect(dplyr::select(sf_zones, dplyr::all_of(fld_zones))), 
    fun = zonal_fun, exact = T, na.rm = T, as.polygons = T))), 
    cols = -dplyr::any_of(fld_zones), names_to = "lyr", values_to = zonal_fun), 
    time = readr::parse_datetime(str_replace(lyr, glue("{var}\\|(.*)"), 
        "\\1")))
debug: if (!is.null(zonal_csv)) write_csv(d_r, zonal_csv)
debug: write_csv(d_r, zonal_csv)
debug: if (!keep_nc) unlink(dir_nc, recursive = T)
debug: unlink(dir_nc, recursive = T)
debug: return(d_r)
Downloading 1 requests, up to 1388 time slices each
Called from: extractr::ed_extract(ed, var = v, sf_zones = ply, bbox = bb, 
    mask_tif = F, rast_tif = glue("{dir_out}/{nms}/{yr}.tif"), 
    zonal_fun = "mean", zonal_csv = glue("{dir_out}/{nms}/{yr}.csv"), 
    dir_nc = glue("{dir_out}/{nms}/{yr}_nc"), keep_nc = F, n_max_vals_per_req = 1e+05, 
    time_min = time_min, time_max = time_max, verbose = T)
debug: while (i_req <= n_reqs) {
    i_t_beg <- (i_req - 1) * n_t_per_req + 1
    i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
    t_req <- times_todo[c(i_t_beg, i_t_end)]
    t_req_str <- format_ISO8601(t_req, usetz = "Z")
    if (verbose) 
        message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
    ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
        ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
        0), nc)
    unlink(ncs0)
    nc_retry <- T
    nc_n_try <- 1
    n_max_retries
    while (nc_retry) {
        res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
            url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
                bbox[["xmax"]]), latitude = c(bbox[["ymin"]], 
                bbox[["ymax"]]), time = t_req_str, fmt = "nc", 
            store = rerddap::disk(path = dir_nc)))
        if (inherits(res, "try-error")) {
            err <- attr(res, "condition")
            msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
            nc_n_try <- nc_n_try + 1
            if (nc_n_try > n_max_retries) {
                stop(msg)
            }
            else {
                message(msg, "\nRETRYing...")
                Sys.sleep(1)
            }
        }
        else {
            nc_retry <- F
        }
    }
    i_req <- i_req + 1
}
debug: i_t_beg <- (i_req - 1) * n_t_per_req + 1
debug: i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
debug: t_req <- times_todo[c(i_t_beg, i_t_end)]
debug: t_req_str <- format_ISO8601(t_req, usetz = "Z")
debug: if (verbose) message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
debug: message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
Fetching request 1 of 1 (1998-01-01 to 1998-12-01) ~ 19:37:45 UTC
debug: ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
    0), nc)
debug: unlink(ncs0)
debug: nc_retry <- T
debug: nc_n_try <- 1
debug: n_max_retries
debug: while (nc_retry) {
    res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
        url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
            bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
        time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
    if (inherits(res, "try-error")) {
        err <- attr(res, "condition")
        msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
        nc_n_try <- nc_n_try + 1
        if (nc_n_try > n_max_retries) {
            stop(msg)
        }
        else {
            message(msg, "\nRETRYing...")
            Sys.sleep(1)
        }
    }
    else {
        nc_retry <- F
    }
}
debug: res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
    url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
        bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
    time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
debug: if (inherits(res, "try-error")) {
    err <- attr(res, "condition")
    msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
    nc_n_try <- nc_n_try + 1
    if (nc_n_try > n_max_retries) {
        stop(msg)
    }
    else {
        message(msg, "\nRETRYing...")
        Sys.sleep(1)
    }
} else {
    nc_retry <- F
}
debug: nc_retry <- F
debug: (while) nc_retry
debug: i_req <- i_req + 1
debug: (while) i_req <= n_reqs
debug: ncs <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size > 
    0), nc)
debug: r <- terra::rast(ncs)
debug: stopifnot(all(class(terra::time(r)) %in% c("POSIXct", "POSIXt")))
debug: idx <- dplyr::pull(dplyr::filter(dplyr::arrange(dplyr::tibble(idx = 1:terra::nlyr(r), 
    time = terra::time(r)), time), !duplicated(time)), idx)
debug: r <- terra::subset(r, idx)
debug: stopifnot(terra::crs(r, proj = T) == wgs84)
debug: if (mask_tif) r <- terra::mask(r, sf_zones)
debug: lyrs <- glue("{var}|{terra::time(r)}")
debug: if (length(dims_other) > 0 && !all(length(dims[dims_other]) == 
    1)) stop(glue("Other dimensions not yet supported: {paste(dims_other, collapse = ',')}"))
debug: names(r) <- lyrs
debug: if (!is.null(rast_tif)) {
    if (fs::file_exists(rast_tif)) {
        r_tmp_tif <- tempfile(fileext = ".tif")
        r_tmp <- c(rast(rast_tif), r)
        r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
        terra::writeRaster(r_tmp, r_tmp_tif)
        fs::file_delete(rast_tif)
        fs::file_move(r_tmp_tif, rast_tif)
        rm(r)
        rm(r_tmp)
    }
    else {
        terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
    }
    r <- terra::rast(rast_tif)
}
debug: if (fs::file_exists(rast_tif)) {
    r_tmp_tif <- tempfile(fileext = ".tif")
    r_tmp <- c(rast(rast_tif), r)
    r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
    terra::writeRaster(r_tmp, r_tmp_tif)
    fs::file_delete(rast_tif)
    fs::file_move(r_tmp_tif, rast_tif)
    rm(r)
    rm(r_tmp)
} else {
    terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
}
debug: terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
debug: r <- terra::rast(rast_tif)
debug: d_r <- mutate(tidyr::pivot_longer(sf::st_drop_geometry(sf::st_as_sf(terra::zonal(x = r, 
    z = terra::vect(dplyr::select(sf_zones, dplyr::all_of(fld_zones))), 
    fun = zonal_fun, exact = T, na.rm = T, as.polygons = T))), 
    cols = -dplyr::any_of(fld_zones), names_to = "lyr", values_to = zonal_fun), 
    time = readr::parse_datetime(str_replace(lyr, glue("{var}\\|(.*)"), 
        "\\1")))
debug: if (!is.null(zonal_csv)) write_csv(d_r, zonal_csv)
debug: write_csv(d_r, zonal_csv)
debug: if (!keep_nc) unlink(dir_nc, recursive = T)
debug: unlink(dir_nc, recursive = T)
debug: return(d_r)
Downloading 1 requests, up to 1388 time slices each
Called from: extractr::ed_extract(ed, var = v, sf_zones = ply, bbox = bb, 
    mask_tif = F, rast_tif = glue("{dir_out}/{nms}/{yr}.tif"), 
    zonal_fun = "mean", zonal_csv = glue("{dir_out}/{nms}/{yr}.csv"), 
    dir_nc = glue("{dir_out}/{nms}/{yr}_nc"), keep_nc = F, n_max_vals_per_req = 1e+05, 
    time_min = time_min, time_max = time_max, verbose = T)
debug: while (i_req <= n_reqs) {
    i_t_beg <- (i_req - 1) * n_t_per_req + 1
    i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
    t_req <- times_todo[c(i_t_beg, i_t_end)]
    t_req_str <- format_ISO8601(t_req, usetz = "Z")
    if (verbose) 
        message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
    ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
        ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
        0), nc)
    unlink(ncs0)
    nc_retry <- T
    nc_n_try <- 1
    n_max_retries
    while (nc_retry) {
        res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
            url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
                bbox[["xmax"]]), latitude = c(bbox[["ymin"]], 
                bbox[["ymax"]]), time = t_req_str, fmt = "nc", 
            store = rerddap::disk(path = dir_nc)))
        if (inherits(res, "try-error")) {
            err <- attr(res, "condition")
            msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
            nc_n_try <- nc_n_try + 1
            if (nc_n_try > n_max_retries) {
                stop(msg)
            }
            else {
                message(msg, "\nRETRYing...")
                Sys.sleep(1)
            }
        }
        else {
            nc_retry <- F
        }
    }
    i_req <- i_req + 1
}
debug: i_t_beg <- (i_req - 1) * n_t_per_req + 1
debug: i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
debug: t_req <- times_todo[c(i_t_beg, i_t_end)]
debug: t_req_str <- format_ISO8601(t_req, usetz = "Z")
debug: if (verbose) message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
debug: message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
Fetching request 1 of 1 (1999-01-01 to 1999-12-01) ~ 19:37:47 UTC
debug: ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
    0), nc)
debug: unlink(ncs0)
debug: nc_retry <- T
debug: nc_n_try <- 1
debug: n_max_retries
debug: while (nc_retry) {
    res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
        url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
            bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
        time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
    if (inherits(res, "try-error")) {
        err <- attr(res, "condition")
        msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
        nc_n_try <- nc_n_try + 1
        if (nc_n_try > n_max_retries) {
            stop(msg)
        }
        else {
            message(msg, "\nRETRYing...")
            Sys.sleep(1)
        }
    }
    else {
        nc_retry <- F
    }
}
debug: res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
    url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
        bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
    time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
debug: if (inherits(res, "try-error")) {
    err <- attr(res, "condition")
    msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
    nc_n_try <- nc_n_try + 1
    if (nc_n_try > n_max_retries) {
        stop(msg)
    }
    else {
        message(msg, "\nRETRYing...")
        Sys.sleep(1)
    }
} else {
    nc_retry <- F
}
debug: nc_retry <- F
debug: (while) nc_retry
debug: i_req <- i_req + 1
debug: (while) i_req <= n_reqs
debug: ncs <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size > 
    0), nc)
debug: r <- terra::rast(ncs)
debug: stopifnot(all(class(terra::time(r)) %in% c("POSIXct", "POSIXt")))
debug: idx <- dplyr::pull(dplyr::filter(dplyr::arrange(dplyr::tibble(idx = 1:terra::nlyr(r), 
    time = terra::time(r)), time), !duplicated(time)), idx)
debug: r <- terra::subset(r, idx)
debug: stopifnot(terra::crs(r, proj = T) == wgs84)
debug: if (mask_tif) r <- terra::mask(r, sf_zones)
debug: lyrs <- glue("{var}|{terra::time(r)}")
debug: if (length(dims_other) > 0 && !all(length(dims[dims_other]) == 
    1)) stop(glue("Other dimensions not yet supported: {paste(dims_other, collapse = ',')}"))
debug: names(r) <- lyrs
debug: if (!is.null(rast_tif)) {
    if (fs::file_exists(rast_tif)) {
        r_tmp_tif <- tempfile(fileext = ".tif")
        r_tmp <- c(rast(rast_tif), r)
        r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
        terra::writeRaster(r_tmp, r_tmp_tif)
        fs::file_delete(rast_tif)
        fs::file_move(r_tmp_tif, rast_tif)
        rm(r)
        rm(r_tmp)
    }
    else {
        terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
    }
    r <- terra::rast(rast_tif)
}
debug: if (fs::file_exists(rast_tif)) {
    r_tmp_tif <- tempfile(fileext = ".tif")
    r_tmp <- c(rast(rast_tif), r)
    r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
    terra::writeRaster(r_tmp, r_tmp_tif)
    fs::file_delete(rast_tif)
    fs::file_move(r_tmp_tif, rast_tif)
    rm(r)
    rm(r_tmp)
} else {
    terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
}
debug: terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
debug: r <- terra::rast(rast_tif)
debug: d_r <- mutate(tidyr::pivot_longer(sf::st_drop_geometry(sf::st_as_sf(terra::zonal(x = r, 
    z = terra::vect(dplyr::select(sf_zones, dplyr::all_of(fld_zones))), 
    fun = zonal_fun, exact = T, na.rm = T, as.polygons = T))), 
    cols = -dplyr::any_of(fld_zones), names_to = "lyr", values_to = zonal_fun), 
    time = readr::parse_datetime(str_replace(lyr, glue("{var}\\|(.*)"), 
        "\\1")))
debug: if (!is.null(zonal_csv)) write_csv(d_r, zonal_csv)
debug: write_csv(d_r, zonal_csv)
debug: if (!keep_nc) unlink(dir_nc, recursive = T)
debug: unlink(dir_nc, recursive = T)
debug: return(d_r)
Downloading 1 requests, up to 1388 time slices each
Called from: extractr::ed_extract(ed, var = v, sf_zones = ply, bbox = bb, 
    mask_tif = F, rast_tif = glue("{dir_out}/{nms}/{yr}.tif"), 
    zonal_fun = "mean", zonal_csv = glue("{dir_out}/{nms}/{yr}.csv"), 
    dir_nc = glue("{dir_out}/{nms}/{yr}_nc"), keep_nc = F, n_max_vals_per_req = 1e+05, 
    time_min = time_min, time_max = time_max, verbose = T)
debug: while (i_req <= n_reqs) {
    i_t_beg <- (i_req - 1) * n_t_per_req + 1
    i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
    t_req <- times_todo[c(i_t_beg, i_t_end)]
    t_req_str <- format_ISO8601(t_req, usetz = "Z")
    if (verbose) 
        message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
    ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
        ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
        0), nc)
    unlink(ncs0)
    nc_retry <- T
    nc_n_try <- 1
    n_max_retries
    while (nc_retry) {
        res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
            url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
                bbox[["xmax"]]), latitude = c(bbox[["ymin"]], 
                bbox[["ymax"]]), time = t_req_str, fmt = "nc", 
            store = rerddap::disk(path = dir_nc)))
        if (inherits(res, "try-error")) {
            err <- attr(res, "condition")
            msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
            nc_n_try <- nc_n_try + 1
            if (nc_n_try > n_max_retries) {
                stop(msg)
            }
            else {
                message(msg, "\nRETRYing...")
                Sys.sleep(1)
            }
        }
        else {
            nc_retry <- F
        }
    }
    i_req <- i_req + 1
}
debug: i_t_beg <- (i_req - 1) * n_t_per_req + 1
debug: i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
debug: t_req <- times_todo[c(i_t_beg, i_t_end)]
debug: t_req_str <- format_ISO8601(t_req, usetz = "Z")
debug: if (verbose) message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
debug: message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
Fetching request 1 of 1 (2000-01-01 to 2000-12-01) ~ 19:37:49 UTC
debug: ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
    0), nc)
debug: unlink(ncs0)
debug: nc_retry <- T
debug: nc_n_try <- 1
debug: n_max_retries
debug: while (nc_retry) {
    res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
        url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
            bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
        time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
    if (inherits(res, "try-error")) {
        err <- attr(res, "condition")
        msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
        nc_n_try <- nc_n_try + 1
        if (nc_n_try > n_max_retries) {
            stop(msg)
        }
        else {
            message(msg, "\nRETRYing...")
            Sys.sleep(1)
        }
    }
    else {
        nc_retry <- F
    }
}
debug: res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
    url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
        bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
    time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
debug: if (inherits(res, "try-error")) {
    err <- attr(res, "condition")
    msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
    nc_n_try <- nc_n_try + 1
    if (nc_n_try > n_max_retries) {
        stop(msg)
    }
    else {
        message(msg, "\nRETRYing...")
        Sys.sleep(1)
    }
} else {
    nc_retry <- F
}
debug: nc_retry <- F
debug: (while) nc_retry
debug: i_req <- i_req + 1
debug: (while) i_req <= n_reqs
debug: ncs <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size > 
    0), nc)
debug: r <- terra::rast(ncs)
debug: stopifnot(all(class(terra::time(r)) %in% c("POSIXct", "POSIXt")))
debug: idx <- dplyr::pull(dplyr::filter(dplyr::arrange(dplyr::tibble(idx = 1:terra::nlyr(r), 
    time = terra::time(r)), time), !duplicated(time)), idx)
debug: r <- terra::subset(r, idx)
debug: stopifnot(terra::crs(r, proj = T) == wgs84)
debug: if (mask_tif) r <- terra::mask(r, sf_zones)
debug: lyrs <- glue("{var}|{terra::time(r)}")
debug: if (length(dims_other) > 0 && !all(length(dims[dims_other]) == 
    1)) stop(glue("Other dimensions not yet supported: {paste(dims_other, collapse = ',')}"))
debug: names(r) <- lyrs
debug: if (!is.null(rast_tif)) {
    if (fs::file_exists(rast_tif)) {
        r_tmp_tif <- tempfile(fileext = ".tif")
        r_tmp <- c(rast(rast_tif), r)
        r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
        terra::writeRaster(r_tmp, r_tmp_tif)
        fs::file_delete(rast_tif)
        fs::file_move(r_tmp_tif, rast_tif)
        rm(r)
        rm(r_tmp)
    }
    else {
        terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
    }
    r <- terra::rast(rast_tif)
}
debug: if (fs::file_exists(rast_tif)) {
    r_tmp_tif <- tempfile(fileext = ".tif")
    r_tmp <- c(rast(rast_tif), r)
    r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
    terra::writeRaster(r_tmp, r_tmp_tif)
    fs::file_delete(rast_tif)
    fs::file_move(r_tmp_tif, rast_tif)
    rm(r)
    rm(r_tmp)
} else {
    terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
}
debug: terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
debug: r <- terra::rast(rast_tif)
debug: d_r <- mutate(tidyr::pivot_longer(sf::st_drop_geometry(sf::st_as_sf(terra::zonal(x = r, 
    z = terra::vect(dplyr::select(sf_zones, dplyr::all_of(fld_zones))), 
    fun = zonal_fun, exact = T, na.rm = T, as.polygons = T))), 
    cols = -dplyr::any_of(fld_zones), names_to = "lyr", values_to = zonal_fun), 
    time = readr::parse_datetime(str_replace(lyr, glue("{var}\\|(.*)"), 
        "\\1")))
debug: if (!is.null(zonal_csv)) write_csv(d_r, zonal_csv)
debug: write_csv(d_r, zonal_csv)
debug: if (!keep_nc) unlink(dir_nc, recursive = T)
debug: unlink(dir_nc, recursive = T)
debug: return(d_r)
Downloading 1 requests, up to 1388 time slices each
Called from: extractr::ed_extract(ed, var = v, sf_zones = ply, bbox = bb, 
    mask_tif = F, rast_tif = glue("{dir_out}/{nms}/{yr}.tif"), 
    zonal_fun = "mean", zonal_csv = glue("{dir_out}/{nms}/{yr}.csv"), 
    dir_nc = glue("{dir_out}/{nms}/{yr}_nc"), keep_nc = F, n_max_vals_per_req = 1e+05, 
    time_min = time_min, time_max = time_max, verbose = T)
debug: while (i_req <= n_reqs) {
    i_t_beg <- (i_req - 1) * n_t_per_req + 1
    i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
    t_req <- times_todo[c(i_t_beg, i_t_end)]
    t_req_str <- format_ISO8601(t_req, usetz = "Z")
    if (verbose) 
        message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
    ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
        ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
        0), nc)
    unlink(ncs0)
    nc_retry <- T
    nc_n_try <- 1
    n_max_retries
    while (nc_retry) {
        res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
            url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
                bbox[["xmax"]]), latitude = c(bbox[["ymin"]], 
                bbox[["ymax"]]), time = t_req_str, fmt = "nc", 
            store = rerddap::disk(path = dir_nc)))
        if (inherits(res, "try-error")) {
            err <- attr(res, "condition")
            msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
            nc_n_try <- nc_n_try + 1
            if (nc_n_try > n_max_retries) {
                stop(msg)
            }
            else {
                message(msg, "\nRETRYing...")
                Sys.sleep(1)
            }
        }
        else {
            nc_retry <- F
        }
    }
    i_req <- i_req + 1
}
debug: i_t_beg <- (i_req - 1) * n_t_per_req + 1
debug: i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
debug: t_req <- times_todo[c(i_t_beg, i_t_end)]
debug: t_req_str <- format_ISO8601(t_req, usetz = "Z")
debug: if (verbose) message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
debug: message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
Fetching request 1 of 1 (2001-01-01 to 2001-12-01) ~ 19:37:51 UTC
debug: ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
    0), nc)
debug: unlink(ncs0)
debug: nc_retry <- T
debug: nc_n_try <- 1
debug: n_max_retries
debug: while (nc_retry) {
    res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
        url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
            bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
        time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
    if (inherits(res, "try-error")) {
        err <- attr(res, "condition")
        msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
        nc_n_try <- nc_n_try + 1
        if (nc_n_try > n_max_retries) {
            stop(msg)
        }
        else {
            message(msg, "\nRETRYing...")
            Sys.sleep(1)
        }
    }
    else {
        nc_retry <- F
    }
}
debug: res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
    url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
        bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
    time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
debug: if (inherits(res, "try-error")) {
    err <- attr(res, "condition")
    msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
    nc_n_try <- nc_n_try + 1
    if (nc_n_try > n_max_retries) {
        stop(msg)
    }
    else {
        message(msg, "\nRETRYing...")
        Sys.sleep(1)
    }
} else {
    nc_retry <- F
}
debug: nc_retry <- F
debug: (while) nc_retry
debug: i_req <- i_req + 1
debug: (while) i_req <= n_reqs
debug: ncs <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size > 
    0), nc)
debug: r <- terra::rast(ncs)
debug: stopifnot(all(class(terra::time(r)) %in% c("POSIXct", "POSIXt")))
debug: idx <- dplyr::pull(dplyr::filter(dplyr::arrange(dplyr::tibble(idx = 1:terra::nlyr(r), 
    time = terra::time(r)), time), !duplicated(time)), idx)
debug: r <- terra::subset(r, idx)
debug: stopifnot(terra::crs(r, proj = T) == wgs84)
debug: if (mask_tif) r <- terra::mask(r, sf_zones)
debug: lyrs <- glue("{var}|{terra::time(r)}")
debug: if (length(dims_other) > 0 && !all(length(dims[dims_other]) == 
    1)) stop(glue("Other dimensions not yet supported: {paste(dims_other, collapse = ',')}"))
debug: names(r) <- lyrs
debug: if (!is.null(rast_tif)) {
    if (fs::file_exists(rast_tif)) {
        r_tmp_tif <- tempfile(fileext = ".tif")
        r_tmp <- c(rast(rast_tif), r)
        r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
        terra::writeRaster(r_tmp, r_tmp_tif)
        fs::file_delete(rast_tif)
        fs::file_move(r_tmp_tif, rast_tif)
        rm(r)
        rm(r_tmp)
    }
    else {
        terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
    }
    r <- terra::rast(rast_tif)
}
debug: if (fs::file_exists(rast_tif)) {
    r_tmp_tif <- tempfile(fileext = ".tif")
    r_tmp <- c(rast(rast_tif), r)
    r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
    terra::writeRaster(r_tmp, r_tmp_tif)
    fs::file_delete(rast_tif)
    fs::file_move(r_tmp_tif, rast_tif)
    rm(r)
    rm(r_tmp)
} else {
    terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
}
debug: terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
debug: r <- terra::rast(rast_tif)
debug: d_r <- mutate(tidyr::pivot_longer(sf::st_drop_geometry(sf::st_as_sf(terra::zonal(x = r, 
    z = terra::vect(dplyr::select(sf_zones, dplyr::all_of(fld_zones))), 
    fun = zonal_fun, exact = T, na.rm = T, as.polygons = T))), 
    cols = -dplyr::any_of(fld_zones), names_to = "lyr", values_to = zonal_fun), 
    time = readr::parse_datetime(str_replace(lyr, glue("{var}\\|(.*)"), 
        "\\1")))
debug: if (!is.null(zonal_csv)) write_csv(d_r, zonal_csv)
debug: write_csv(d_r, zonal_csv)
debug: if (!keep_nc) unlink(dir_nc, recursive = T)
debug: unlink(dir_nc, recursive = T)
debug: return(d_r)
Downloading 1 requests, up to 1388 time slices each
Called from: extractr::ed_extract(ed, var = v, sf_zones = ply, bbox = bb, 
    mask_tif = F, rast_tif = glue("{dir_out}/{nms}/{yr}.tif"), 
    zonal_fun = "mean", zonal_csv = glue("{dir_out}/{nms}/{yr}.csv"), 
    dir_nc = glue("{dir_out}/{nms}/{yr}_nc"), keep_nc = F, n_max_vals_per_req = 1e+05, 
    time_min = time_min, time_max = time_max, verbose = T)
debug: while (i_req <= n_reqs) {
    i_t_beg <- (i_req - 1) * n_t_per_req + 1
    i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
    t_req <- times_todo[c(i_t_beg, i_t_end)]
    t_req_str <- format_ISO8601(t_req, usetz = "Z")
    if (verbose) 
        message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
    ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
        ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
        0), nc)
    unlink(ncs0)
    nc_retry <- T
    nc_n_try <- 1
    n_max_retries
    while (nc_retry) {
        res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
            url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
                bbox[["xmax"]]), latitude = c(bbox[["ymin"]], 
                bbox[["ymax"]]), time = t_req_str, fmt = "nc", 
            store = rerddap::disk(path = dir_nc)))
        if (inherits(res, "try-error")) {
            err <- attr(res, "condition")
            msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
            nc_n_try <- nc_n_try + 1
            if (nc_n_try > n_max_retries) {
                stop(msg)
            }
            else {
                message(msg, "\nRETRYing...")
                Sys.sleep(1)
            }
        }
        else {
            nc_retry <- F
        }
    }
    i_req <- i_req + 1
}
debug: i_t_beg <- (i_req - 1) * n_t_per_req + 1
debug: i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
debug: t_req <- times_todo[c(i_t_beg, i_t_end)]
debug: t_req_str <- format_ISO8601(t_req, usetz = "Z")
debug: if (verbose) message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
debug: message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
Fetching request 1 of 1 (2002-01-01 to 2002-12-01) ~ 19:37:52 UTC
debug: ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
    0), nc)
debug: unlink(ncs0)
debug: nc_retry <- T
debug: nc_n_try <- 1
debug: n_max_retries
debug: while (nc_retry) {
    res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
        url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
            bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
        time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
    if (inherits(res, "try-error")) {
        err <- attr(res, "condition")
        msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
        nc_n_try <- nc_n_try + 1
        if (nc_n_try > n_max_retries) {
            stop(msg)
        }
        else {
            message(msg, "\nRETRYing...")
            Sys.sleep(1)
        }
    }
    else {
        nc_retry <- F
    }
}
debug: res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
    url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
        bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
    time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
debug: if (inherits(res, "try-error")) {
    err <- attr(res, "condition")
    msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
    nc_n_try <- nc_n_try + 1
    if (nc_n_try > n_max_retries) {
        stop(msg)
    }
    else {
        message(msg, "\nRETRYing...")
        Sys.sleep(1)
    }
} else {
    nc_retry <- F
}
debug: nc_retry <- F
debug: (while) nc_retry
debug: i_req <- i_req + 1
debug: (while) i_req <= n_reqs
debug: ncs <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size > 
    0), nc)
debug: r <- terra::rast(ncs)
debug: stopifnot(all(class(terra::time(r)) %in% c("POSIXct", "POSIXt")))
debug: idx <- dplyr::pull(dplyr::filter(dplyr::arrange(dplyr::tibble(idx = 1:terra::nlyr(r), 
    time = terra::time(r)), time), !duplicated(time)), idx)
debug: r <- terra::subset(r, idx)
debug: stopifnot(terra::crs(r, proj = T) == wgs84)
debug: if (mask_tif) r <- terra::mask(r, sf_zones)
debug: lyrs <- glue("{var}|{terra::time(r)}")
debug: if (length(dims_other) > 0 && !all(length(dims[dims_other]) == 
    1)) stop(glue("Other dimensions not yet supported: {paste(dims_other, collapse = ',')}"))
debug: names(r) <- lyrs
debug: if (!is.null(rast_tif)) {
    if (fs::file_exists(rast_tif)) {
        r_tmp_tif <- tempfile(fileext = ".tif")
        r_tmp <- c(rast(rast_tif), r)
        r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
        terra::writeRaster(r_tmp, r_tmp_tif)
        fs::file_delete(rast_tif)
        fs::file_move(r_tmp_tif, rast_tif)
        rm(r)
        rm(r_tmp)
    }
    else {
        terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
    }
    r <- terra::rast(rast_tif)
}
debug: if (fs::file_exists(rast_tif)) {
    r_tmp_tif <- tempfile(fileext = ".tif")
    r_tmp <- c(rast(rast_tif), r)
    r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
    terra::writeRaster(r_tmp, r_tmp_tif)
    fs::file_delete(rast_tif)
    fs::file_move(r_tmp_tif, rast_tif)
    rm(r)
    rm(r_tmp)
} else {
    terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
}
debug: terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
debug: r <- terra::rast(rast_tif)
debug: d_r <- mutate(tidyr::pivot_longer(sf::st_drop_geometry(sf::st_as_sf(terra::zonal(x = r, 
    z = terra::vect(dplyr::select(sf_zones, dplyr::all_of(fld_zones))), 
    fun = zonal_fun, exact = T, na.rm = T, as.polygons = T))), 
    cols = -dplyr::any_of(fld_zones), names_to = "lyr", values_to = zonal_fun), 
    time = readr::parse_datetime(str_replace(lyr, glue("{var}\\|(.*)"), 
        "\\1")))
debug: if (!is.null(zonal_csv)) write_csv(d_r, zonal_csv)
debug: write_csv(d_r, zonal_csv)
debug: if (!keep_nc) unlink(dir_nc, recursive = T)
debug: unlink(dir_nc, recursive = T)
debug: return(d_r)
Downloading 1 requests, up to 1388 time slices each
Called from: extractr::ed_extract(ed, var = v, sf_zones = ply, bbox = bb, 
    mask_tif = F, rast_tif = glue("{dir_out}/{nms}/{yr}.tif"), 
    zonal_fun = "mean", zonal_csv = glue("{dir_out}/{nms}/{yr}.csv"), 
    dir_nc = glue("{dir_out}/{nms}/{yr}_nc"), keep_nc = F, n_max_vals_per_req = 1e+05, 
    time_min = time_min, time_max = time_max, verbose = T)
debug: while (i_req <= n_reqs) {
    i_t_beg <- (i_req - 1) * n_t_per_req + 1
    i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
    t_req <- times_todo[c(i_t_beg, i_t_end)]
    t_req_str <- format_ISO8601(t_req, usetz = "Z")
    if (verbose) 
        message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
    ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
        ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
        0), nc)
    unlink(ncs0)
    nc_retry <- T
    nc_n_try <- 1
    n_max_retries
    while (nc_retry) {
        res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
            url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
                bbox[["xmax"]]), latitude = c(bbox[["ymin"]], 
                bbox[["ymax"]]), time = t_req_str, fmt = "nc", 
            store = rerddap::disk(path = dir_nc)))
        if (inherits(res, "try-error")) {
            err <- attr(res, "condition")
            msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
            nc_n_try <- nc_n_try + 1
            if (nc_n_try > n_max_retries) {
                stop(msg)
            }
            else {
                message(msg, "\nRETRYing...")
                Sys.sleep(1)
            }
        }
        else {
            nc_retry <- F
        }
    }
    i_req <- i_req + 1
}
debug: i_t_beg <- (i_req - 1) * n_t_per_req + 1
debug: i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
debug: t_req <- times_todo[c(i_t_beg, i_t_end)]
debug: t_req_str <- format_ISO8601(t_req, usetz = "Z")
debug: if (verbose) message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
debug: message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
Fetching request 1 of 1 (2003-01-01 to 2003-12-01) ~ 19:37:54 UTC
debug: ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
    0), nc)
debug: unlink(ncs0)
debug: nc_retry <- T
debug: nc_n_try <- 1
debug: n_max_retries
debug: while (nc_retry) {
    res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
        url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
            bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
        time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
    if (inherits(res, "try-error")) {
        err <- attr(res, "condition")
        msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
        nc_n_try <- nc_n_try + 1
        if (nc_n_try > n_max_retries) {
            stop(msg)
        }
        else {
            message(msg, "\nRETRYing...")
            Sys.sleep(1)
        }
    }
    else {
        nc_retry <- F
    }
}
debug: res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
    url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
        bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
    time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
debug: if (inherits(res, "try-error")) {
    err <- attr(res, "condition")
    msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
    nc_n_try <- nc_n_try + 1
    if (nc_n_try > n_max_retries) {
        stop(msg)
    }
    else {
        message(msg, "\nRETRYing...")
        Sys.sleep(1)
    }
} else {
    nc_retry <- F
}
debug: nc_retry <- F
debug: (while) nc_retry
debug: i_req <- i_req + 1
debug: (while) i_req <= n_reqs
debug: ncs <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size > 
    0), nc)
debug: r <- terra::rast(ncs)
debug: stopifnot(all(class(terra::time(r)) %in% c("POSIXct", "POSIXt")))
debug: idx <- dplyr::pull(dplyr::filter(dplyr::arrange(dplyr::tibble(idx = 1:terra::nlyr(r), 
    time = terra::time(r)), time), !duplicated(time)), idx)
debug: r <- terra::subset(r, idx)
debug: stopifnot(terra::crs(r, proj = T) == wgs84)
debug: if (mask_tif) r <- terra::mask(r, sf_zones)
debug: lyrs <- glue("{var}|{terra::time(r)}")
debug: if (length(dims_other) > 0 && !all(length(dims[dims_other]) == 
    1)) stop(glue("Other dimensions not yet supported: {paste(dims_other, collapse = ',')}"))
debug: names(r) <- lyrs
debug: if (!is.null(rast_tif)) {
    if (fs::file_exists(rast_tif)) {
        r_tmp_tif <- tempfile(fileext = ".tif")
        r_tmp <- c(rast(rast_tif), r)
        r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
        terra::writeRaster(r_tmp, r_tmp_tif)
        fs::file_delete(rast_tif)
        fs::file_move(r_tmp_tif, rast_tif)
        rm(r)
        rm(r_tmp)
    }
    else {
        terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
    }
    r <- terra::rast(rast_tif)
}
debug: if (fs::file_exists(rast_tif)) {
    r_tmp_tif <- tempfile(fileext = ".tif")
    r_tmp <- c(rast(rast_tif), r)
    r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
    terra::writeRaster(r_tmp, r_tmp_tif)
    fs::file_delete(rast_tif)
    fs::file_move(r_tmp_tif, rast_tif)
    rm(r)
    rm(r_tmp)
} else {
    terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
}
debug: terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
debug: r <- terra::rast(rast_tif)
debug: d_r <- mutate(tidyr::pivot_longer(sf::st_drop_geometry(sf::st_as_sf(terra::zonal(x = r, 
    z = terra::vect(dplyr::select(sf_zones, dplyr::all_of(fld_zones))), 
    fun = zonal_fun, exact = T, na.rm = T, as.polygons = T))), 
    cols = -dplyr::any_of(fld_zones), names_to = "lyr", values_to = zonal_fun), 
    time = readr::parse_datetime(str_replace(lyr, glue("{var}\\|(.*)"), 
        "\\1")))
debug: if (!is.null(zonal_csv)) write_csv(d_r, zonal_csv)
debug: write_csv(d_r, zonal_csv)
debug: if (!keep_nc) unlink(dir_nc, recursive = T)
debug: unlink(dir_nc, recursive = T)
debug: return(d_r)
Downloading 1 requests, up to 1388 time slices each
Called from: extractr::ed_extract(ed, var = v, sf_zones = ply, bbox = bb, 
    mask_tif = F, rast_tif = glue("{dir_out}/{nms}/{yr}.tif"), 
    zonal_fun = "mean", zonal_csv = glue("{dir_out}/{nms}/{yr}.csv"), 
    dir_nc = glue("{dir_out}/{nms}/{yr}_nc"), keep_nc = F, n_max_vals_per_req = 1e+05, 
    time_min = time_min, time_max = time_max, verbose = T)
debug: while (i_req <= n_reqs) {
    i_t_beg <- (i_req - 1) * n_t_per_req + 1
    i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
    t_req <- times_todo[c(i_t_beg, i_t_end)]
    t_req_str <- format_ISO8601(t_req, usetz = "Z")
    if (verbose) 
        message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
    ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
        ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
        0), nc)
    unlink(ncs0)
    nc_retry <- T
    nc_n_try <- 1
    n_max_retries
    while (nc_retry) {
        res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
            url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
                bbox[["xmax"]]), latitude = c(bbox[["ymin"]], 
                bbox[["ymax"]]), time = t_req_str, fmt = "nc", 
            store = rerddap::disk(path = dir_nc)))
        if (inherits(res, "try-error")) {
            err <- attr(res, "condition")
            msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
            nc_n_try <- nc_n_try + 1
            if (nc_n_try > n_max_retries) {
                stop(msg)
            }
            else {
                message(msg, "\nRETRYing...")
                Sys.sleep(1)
            }
        }
        else {
            nc_retry <- F
        }
    }
    i_req <- i_req + 1
}
debug: i_t_beg <- (i_req - 1) * n_t_per_req + 1
debug: i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
debug: t_req <- times_todo[c(i_t_beg, i_t_end)]
debug: t_req_str <- format_ISO8601(t_req, usetz = "Z")
debug: if (verbose) message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
debug: message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
Fetching request 1 of 1 (2004-01-01 to 2004-12-01) ~ 19:37:56 UTC
debug: ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
    0), nc)
debug: unlink(ncs0)
debug: nc_retry <- T
debug: nc_n_try <- 1
debug: n_max_retries
debug: while (nc_retry) {
    res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
        url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
            bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
        time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
    if (inherits(res, "try-error")) {
        err <- attr(res, "condition")
        msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
        nc_n_try <- nc_n_try + 1
        if (nc_n_try > n_max_retries) {
            stop(msg)
        }
        else {
            message(msg, "\nRETRYing...")
            Sys.sleep(1)
        }
    }
    else {
        nc_retry <- F
    }
}
debug: res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
    url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
        bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
    time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
debug: if (inherits(res, "try-error")) {
    err <- attr(res, "condition")
    msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
    nc_n_try <- nc_n_try + 1
    if (nc_n_try > n_max_retries) {
        stop(msg)
    }
    else {
        message(msg, "\nRETRYing...")
        Sys.sleep(1)
    }
} else {
    nc_retry <- F
}
debug: nc_retry <- F
debug: (while) nc_retry
debug: i_req <- i_req + 1
debug: (while) i_req <= n_reqs
debug: ncs <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size > 
    0), nc)
debug: r <- terra::rast(ncs)
debug: stopifnot(all(class(terra::time(r)) %in% c("POSIXct", "POSIXt")))
debug: idx <- dplyr::pull(dplyr::filter(dplyr::arrange(dplyr::tibble(idx = 1:terra::nlyr(r), 
    time = terra::time(r)), time), !duplicated(time)), idx)
debug: r <- terra::subset(r, idx)
debug: stopifnot(terra::crs(r, proj = T) == wgs84)
debug: if (mask_tif) r <- terra::mask(r, sf_zones)
debug: lyrs <- glue("{var}|{terra::time(r)}")
debug: if (length(dims_other) > 0 && !all(length(dims[dims_other]) == 
    1)) stop(glue("Other dimensions not yet supported: {paste(dims_other, collapse = ',')}"))
debug: names(r) <- lyrs
debug: if (!is.null(rast_tif)) {
    if (fs::file_exists(rast_tif)) {
        r_tmp_tif <- tempfile(fileext = ".tif")
        r_tmp <- c(rast(rast_tif), r)
        r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
        terra::writeRaster(r_tmp, r_tmp_tif)
        fs::file_delete(rast_tif)
        fs::file_move(r_tmp_tif, rast_tif)
        rm(r)
        rm(r_tmp)
    }
    else {
        terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
    }
    r <- terra::rast(rast_tif)
}
debug: if (fs::file_exists(rast_tif)) {
    r_tmp_tif <- tempfile(fileext = ".tif")
    r_tmp <- c(rast(rast_tif), r)
    r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
    terra::writeRaster(r_tmp, r_tmp_tif)
    fs::file_delete(rast_tif)
    fs::file_move(r_tmp_tif, rast_tif)
    rm(r)
    rm(r_tmp)
} else {
    terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
}
debug: terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
debug: r <- terra::rast(rast_tif)
debug: d_r <- mutate(tidyr::pivot_longer(sf::st_drop_geometry(sf::st_as_sf(terra::zonal(x = r, 
    z = terra::vect(dplyr::select(sf_zones, dplyr::all_of(fld_zones))), 
    fun = zonal_fun, exact = T, na.rm = T, as.polygons = T))), 
    cols = -dplyr::any_of(fld_zones), names_to = "lyr", values_to = zonal_fun), 
    time = readr::parse_datetime(str_replace(lyr, glue("{var}\\|(.*)"), 
        "\\1")))
debug: if (!is.null(zonal_csv)) write_csv(d_r, zonal_csv)
debug: write_csv(d_r, zonal_csv)
debug: if (!keep_nc) unlink(dir_nc, recursive = T)
debug: unlink(dir_nc, recursive = T)
debug: return(d_r)
Downloading 1 requests, up to 1388 time slices each
Called from: extractr::ed_extract(ed, var = v, sf_zones = ply, bbox = bb, 
    mask_tif = F, rast_tif = glue("{dir_out}/{nms}/{yr}.tif"), 
    zonal_fun = "mean", zonal_csv = glue("{dir_out}/{nms}/{yr}.csv"), 
    dir_nc = glue("{dir_out}/{nms}/{yr}_nc"), keep_nc = F, n_max_vals_per_req = 1e+05, 
    time_min = time_min, time_max = time_max, verbose = T)
debug: while (i_req <= n_reqs) {
    i_t_beg <- (i_req - 1) * n_t_per_req + 1
    i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
    t_req <- times_todo[c(i_t_beg, i_t_end)]
    t_req_str <- format_ISO8601(t_req, usetz = "Z")
    if (verbose) 
        message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
    ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
        ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
        0), nc)
    unlink(ncs0)
    nc_retry <- T
    nc_n_try <- 1
    n_max_retries
    while (nc_retry) {
        res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
            url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
                bbox[["xmax"]]), latitude = c(bbox[["ymin"]], 
                bbox[["ymax"]]), time = t_req_str, fmt = "nc", 
            store = rerddap::disk(path = dir_nc)))
        if (inherits(res, "try-error")) {
            err <- attr(res, "condition")
            msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
            nc_n_try <- nc_n_try + 1
            if (nc_n_try > n_max_retries) {
                stop(msg)
            }
            else {
                message(msg, "\nRETRYing...")
                Sys.sleep(1)
            }
        }
        else {
            nc_retry <- F
        }
    }
    i_req <- i_req + 1
}
debug: i_t_beg <- (i_req - 1) * n_t_per_req + 1
debug: i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
debug: t_req <- times_todo[c(i_t_beg, i_t_end)]
debug: t_req_str <- format_ISO8601(t_req, usetz = "Z")
debug: if (verbose) message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
debug: message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
Fetching request 1 of 1 (2005-01-01 to 2005-12-01) ~ 19:37:57 UTC
debug: ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
    0), nc)
debug: unlink(ncs0)
debug: nc_retry <- T
debug: nc_n_try <- 1
debug: n_max_retries
debug: while (nc_retry) {
    res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
        url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
            bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
        time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
    if (inherits(res, "try-error")) {
        err <- attr(res, "condition")
        msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
        nc_n_try <- nc_n_try + 1
        if (nc_n_try > n_max_retries) {
            stop(msg)
        }
        else {
            message(msg, "\nRETRYing...")
            Sys.sleep(1)
        }
    }
    else {
        nc_retry <- F
    }
}
debug: res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
    url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
        bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
    time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
debug: if (inherits(res, "try-error")) {
    err <- attr(res, "condition")
    msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
    nc_n_try <- nc_n_try + 1
    if (nc_n_try > n_max_retries) {
        stop(msg)
    }
    else {
        message(msg, "\nRETRYing...")
        Sys.sleep(1)
    }
} else {
    nc_retry <- F
}
debug: nc_retry <- F
debug: (while) nc_retry
debug: i_req <- i_req + 1
debug: (while) i_req <= n_reqs
debug: ncs <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size > 
    0), nc)
debug: r <- terra::rast(ncs)
debug: stopifnot(all(class(terra::time(r)) %in% c("POSIXct", "POSIXt")))
debug: idx <- dplyr::pull(dplyr::filter(dplyr::arrange(dplyr::tibble(idx = 1:terra::nlyr(r), 
    time = terra::time(r)), time), !duplicated(time)), idx)
debug: r <- terra::subset(r, idx)
debug: stopifnot(terra::crs(r, proj = T) == wgs84)
debug: if (mask_tif) r <- terra::mask(r, sf_zones)
debug: lyrs <- glue("{var}|{terra::time(r)}")
debug: if (length(dims_other) > 0 && !all(length(dims[dims_other]) == 
    1)) stop(glue("Other dimensions not yet supported: {paste(dims_other, collapse = ',')}"))
debug: names(r) <- lyrs
debug: if (!is.null(rast_tif)) {
    if (fs::file_exists(rast_tif)) {
        r_tmp_tif <- tempfile(fileext = ".tif")
        r_tmp <- c(rast(rast_tif), r)
        r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
        terra::writeRaster(r_tmp, r_tmp_tif)
        fs::file_delete(rast_tif)
        fs::file_move(r_tmp_tif, rast_tif)
        rm(r)
        rm(r_tmp)
    }
    else {
        terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
    }
    r <- terra::rast(rast_tif)
}
debug: if (fs::file_exists(rast_tif)) {
    r_tmp_tif <- tempfile(fileext = ".tif")
    r_tmp <- c(rast(rast_tif), r)
    r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
    terra::writeRaster(r_tmp, r_tmp_tif)
    fs::file_delete(rast_tif)
    fs::file_move(r_tmp_tif, rast_tif)
    rm(r)
    rm(r_tmp)
} else {
    terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
}
debug: terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
debug: r <- terra::rast(rast_tif)
debug: d_r <- mutate(tidyr::pivot_longer(sf::st_drop_geometry(sf::st_as_sf(terra::zonal(x = r, 
    z = terra::vect(dplyr::select(sf_zones, dplyr::all_of(fld_zones))), 
    fun = zonal_fun, exact = T, na.rm = T, as.polygons = T))), 
    cols = -dplyr::any_of(fld_zones), names_to = "lyr", values_to = zonal_fun), 
    time = readr::parse_datetime(str_replace(lyr, glue("{var}\\|(.*)"), 
        "\\1")))
debug: if (!is.null(zonal_csv)) write_csv(d_r, zonal_csv)
debug: write_csv(d_r, zonal_csv)
debug: if (!keep_nc) unlink(dir_nc, recursive = T)
debug: unlink(dir_nc, recursive = T)
debug: return(d_r)
Downloading 1 requests, up to 1388 time slices each
Called from: extractr::ed_extract(ed, var = v, sf_zones = ply, bbox = bb, 
    mask_tif = F, rast_tif = glue("{dir_out}/{nms}/{yr}.tif"), 
    zonal_fun = "mean", zonal_csv = glue("{dir_out}/{nms}/{yr}.csv"), 
    dir_nc = glue("{dir_out}/{nms}/{yr}_nc"), keep_nc = F, n_max_vals_per_req = 1e+05, 
    time_min = time_min, time_max = time_max, verbose = T)
debug: while (i_req <= n_reqs) {
    i_t_beg <- (i_req - 1) * n_t_per_req + 1
    i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
    t_req <- times_todo[c(i_t_beg, i_t_end)]
    t_req_str <- format_ISO8601(t_req, usetz = "Z")
    if (verbose) 
        message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
    ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
        ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
        0), nc)
    unlink(ncs0)
    nc_retry <- T
    nc_n_try <- 1
    n_max_retries
    while (nc_retry) {
        res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
            url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
                bbox[["xmax"]]), latitude = c(bbox[["ymin"]], 
                bbox[["ymax"]]), time = t_req_str, fmt = "nc", 
            store = rerddap::disk(path = dir_nc)))
        if (inherits(res, "try-error")) {
            err <- attr(res, "condition")
            msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
            nc_n_try <- nc_n_try + 1
            if (nc_n_try > n_max_retries) {
                stop(msg)
            }
            else {
                message(msg, "\nRETRYing...")
                Sys.sleep(1)
            }
        }
        else {
            nc_retry <- F
        }
    }
    i_req <- i_req + 1
}
debug: i_t_beg <- (i_req - 1) * n_t_per_req + 1
debug: i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
debug: t_req <- times_todo[c(i_t_beg, i_t_end)]
debug: t_req_str <- format_ISO8601(t_req, usetz = "Z")
debug: if (verbose) message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
debug: message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
Fetching request 1 of 1 (2006-01-01 to 2006-12-01) ~ 19:37:59 UTC
debug: ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
    0), nc)
debug: unlink(ncs0)
debug: nc_retry <- T
debug: nc_n_try <- 1
debug: n_max_retries
debug: while (nc_retry) {
    res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
        url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
            bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
        time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
    if (inherits(res, "try-error")) {
        err <- attr(res, "condition")
        msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
        nc_n_try <- nc_n_try + 1
        if (nc_n_try > n_max_retries) {
            stop(msg)
        }
        else {
            message(msg, "\nRETRYing...")
            Sys.sleep(1)
        }
    }
    else {
        nc_retry <- F
    }
}
debug: res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
    url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
        bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
    time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
debug: if (inherits(res, "try-error")) {
    err <- attr(res, "condition")
    msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
    nc_n_try <- nc_n_try + 1
    if (nc_n_try > n_max_retries) {
        stop(msg)
    }
    else {
        message(msg, "\nRETRYing...")
        Sys.sleep(1)
    }
} else {
    nc_retry <- F
}
debug: nc_retry <- F
debug: (while) nc_retry
debug: i_req <- i_req + 1
debug: (while) i_req <= n_reqs
debug: ncs <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size > 
    0), nc)
debug: r <- terra::rast(ncs)
debug: stopifnot(all(class(terra::time(r)) %in% c("POSIXct", "POSIXt")))
debug: idx <- dplyr::pull(dplyr::filter(dplyr::arrange(dplyr::tibble(idx = 1:terra::nlyr(r), 
    time = terra::time(r)), time), !duplicated(time)), idx)
debug: r <- terra::subset(r, idx)
debug: stopifnot(terra::crs(r, proj = T) == wgs84)
debug: if (mask_tif) r <- terra::mask(r, sf_zones)
debug: lyrs <- glue("{var}|{terra::time(r)}")
debug: if (length(dims_other) > 0 && !all(length(dims[dims_other]) == 
    1)) stop(glue("Other dimensions not yet supported: {paste(dims_other, collapse = ',')}"))
debug: names(r) <- lyrs
debug: if (!is.null(rast_tif)) {
    if (fs::file_exists(rast_tif)) {
        r_tmp_tif <- tempfile(fileext = ".tif")
        r_tmp <- c(rast(rast_tif), r)
        r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
        terra::writeRaster(r_tmp, r_tmp_tif)
        fs::file_delete(rast_tif)
        fs::file_move(r_tmp_tif, rast_tif)
        rm(r)
        rm(r_tmp)
    }
    else {
        terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
    }
    r <- terra::rast(rast_tif)
}
debug: if (fs::file_exists(rast_tif)) {
    r_tmp_tif <- tempfile(fileext = ".tif")
    r_tmp <- c(rast(rast_tif), r)
    r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
    terra::writeRaster(r_tmp, r_tmp_tif)
    fs::file_delete(rast_tif)
    fs::file_move(r_tmp_tif, rast_tif)
    rm(r)
    rm(r_tmp)
} else {
    terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
}
debug: terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
debug: r <- terra::rast(rast_tif)
debug: d_r <- mutate(tidyr::pivot_longer(sf::st_drop_geometry(sf::st_as_sf(terra::zonal(x = r, 
    z = terra::vect(dplyr::select(sf_zones, dplyr::all_of(fld_zones))), 
    fun = zonal_fun, exact = T, na.rm = T, as.polygons = T))), 
    cols = -dplyr::any_of(fld_zones), names_to = "lyr", values_to = zonal_fun), 
    time = readr::parse_datetime(str_replace(lyr, glue("{var}\\|(.*)"), 
        "\\1")))
debug: if (!is.null(zonal_csv)) write_csv(d_r, zonal_csv)
debug: write_csv(d_r, zonal_csv)
debug: if (!keep_nc) unlink(dir_nc, recursive = T)
debug: unlink(dir_nc, recursive = T)
debug: return(d_r)
Downloading 1 requests, up to 1388 time slices each
Called from: extractr::ed_extract(ed, var = v, sf_zones = ply, bbox = bb, 
    mask_tif = F, rast_tif = glue("{dir_out}/{nms}/{yr}.tif"), 
    zonal_fun = "mean", zonal_csv = glue("{dir_out}/{nms}/{yr}.csv"), 
    dir_nc = glue("{dir_out}/{nms}/{yr}_nc"), keep_nc = F, n_max_vals_per_req = 1e+05, 
    time_min = time_min, time_max = time_max, verbose = T)
debug: while (i_req <= n_reqs) {
    i_t_beg <- (i_req - 1) * n_t_per_req + 1
    i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
    t_req <- times_todo[c(i_t_beg, i_t_end)]
    t_req_str <- format_ISO8601(t_req, usetz = "Z")
    if (verbose) 
        message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
    ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
        ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
        0), nc)
    unlink(ncs0)
    nc_retry <- T
    nc_n_try <- 1
    n_max_retries
    while (nc_retry) {
        res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
            url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
                bbox[["xmax"]]), latitude = c(bbox[["ymin"]], 
                bbox[["ymax"]]), time = t_req_str, fmt = "nc", 
            store = rerddap::disk(path = dir_nc)))
        if (inherits(res, "try-error")) {
            err <- attr(res, "condition")
            msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
            nc_n_try <- nc_n_try + 1
            if (nc_n_try > n_max_retries) {
                stop(msg)
            }
            else {
                message(msg, "\nRETRYing...")
                Sys.sleep(1)
            }
        }
        else {
            nc_retry <- F
        }
    }
    i_req <- i_req + 1
}
debug: i_t_beg <- (i_req - 1) * n_t_per_req + 1
debug: i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
debug: t_req <- times_todo[c(i_t_beg, i_t_end)]
debug: t_req_str <- format_ISO8601(t_req, usetz = "Z")
debug: if (verbose) message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
debug: message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
Fetching request 1 of 1 (2007-01-01 to 2007-12-01) ~ 19:38:01 UTC
debug: ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
    0), nc)
debug: unlink(ncs0)
debug: nc_retry <- T
debug: nc_n_try <- 1
debug: n_max_retries
debug: while (nc_retry) {
    res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
        url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
            bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
        time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
    if (inherits(res, "try-error")) {
        err <- attr(res, "condition")
        msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
        nc_n_try <- nc_n_try + 1
        if (nc_n_try > n_max_retries) {
            stop(msg)
        }
        else {
            message(msg, "\nRETRYing...")
            Sys.sleep(1)
        }
    }
    else {
        nc_retry <- F
    }
}
debug: res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
    url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
        bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
    time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
debug: if (inherits(res, "try-error")) {
    err <- attr(res, "condition")
    msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
    nc_n_try <- nc_n_try + 1
    if (nc_n_try > n_max_retries) {
        stop(msg)
    }
    else {
        message(msg, "\nRETRYing...")
        Sys.sleep(1)
    }
} else {
    nc_retry <- F
}
debug: nc_retry <- F
debug: (while) nc_retry
debug: i_req <- i_req + 1
debug: (while) i_req <= n_reqs
debug: ncs <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size > 
    0), nc)
debug: r <- terra::rast(ncs)
debug: stopifnot(all(class(terra::time(r)) %in% c("POSIXct", "POSIXt")))
debug: idx <- dplyr::pull(dplyr::filter(dplyr::arrange(dplyr::tibble(idx = 1:terra::nlyr(r), 
    time = terra::time(r)), time), !duplicated(time)), idx)
debug: r <- terra::subset(r, idx)
debug: stopifnot(terra::crs(r, proj = T) == wgs84)
debug: if (mask_tif) r <- terra::mask(r, sf_zones)
debug: lyrs <- glue("{var}|{terra::time(r)}")
debug: if (length(dims_other) > 0 && !all(length(dims[dims_other]) == 
    1)) stop(glue("Other dimensions not yet supported: {paste(dims_other, collapse = ',')}"))
debug: names(r) <- lyrs
debug: if (!is.null(rast_tif)) {
    if (fs::file_exists(rast_tif)) {
        r_tmp_tif <- tempfile(fileext = ".tif")
        r_tmp <- c(rast(rast_tif), r)
        r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
        terra::writeRaster(r_tmp, r_tmp_tif)
        fs::file_delete(rast_tif)
        fs::file_move(r_tmp_tif, rast_tif)
        rm(r)
        rm(r_tmp)
    }
    else {
        terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
    }
    r <- terra::rast(rast_tif)
}
debug: if (fs::file_exists(rast_tif)) {
    r_tmp_tif <- tempfile(fileext = ".tif")
    r_tmp <- c(rast(rast_tif), r)
    r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
    terra::writeRaster(r_tmp, r_tmp_tif)
    fs::file_delete(rast_tif)
    fs::file_move(r_tmp_tif, rast_tif)
    rm(r)
    rm(r_tmp)
} else {
    terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
}
debug: terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
debug: r <- terra::rast(rast_tif)
debug: d_r <- mutate(tidyr::pivot_longer(sf::st_drop_geometry(sf::st_as_sf(terra::zonal(x = r, 
    z = terra::vect(dplyr::select(sf_zones, dplyr::all_of(fld_zones))), 
    fun = zonal_fun, exact = T, na.rm = T, as.polygons = T))), 
    cols = -dplyr::any_of(fld_zones), names_to = "lyr", values_to = zonal_fun), 
    time = readr::parse_datetime(str_replace(lyr, glue("{var}\\|(.*)"), 
        "\\1")))
debug: if (!is.null(zonal_csv)) write_csv(d_r, zonal_csv)
debug: write_csv(d_r, zonal_csv)
debug: if (!keep_nc) unlink(dir_nc, recursive = T)
debug: unlink(dir_nc, recursive = T)
debug: return(d_r)
Downloading 1 requests, up to 1388 time slices each
Called from: extractr::ed_extract(ed, var = v, sf_zones = ply, bbox = bb, 
    mask_tif = F, rast_tif = glue("{dir_out}/{nms}/{yr}.tif"), 
    zonal_fun = "mean", zonal_csv = glue("{dir_out}/{nms}/{yr}.csv"), 
    dir_nc = glue("{dir_out}/{nms}/{yr}_nc"), keep_nc = F, n_max_vals_per_req = 1e+05, 
    time_min = time_min, time_max = time_max, verbose = T)
debug: while (i_req <= n_reqs) {
    i_t_beg <- (i_req - 1) * n_t_per_req + 1
    i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
    t_req <- times_todo[c(i_t_beg, i_t_end)]
    t_req_str <- format_ISO8601(t_req, usetz = "Z")
    if (verbose) 
        message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
    ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
        ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
        0), nc)
    unlink(ncs0)
    nc_retry <- T
    nc_n_try <- 1
    n_max_retries
    while (nc_retry) {
        res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
            url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
                bbox[["xmax"]]), latitude = c(bbox[["ymin"]], 
                bbox[["ymax"]]), time = t_req_str, fmt = "nc", 
            store = rerddap::disk(path = dir_nc)))
        if (inherits(res, "try-error")) {
            err <- attr(res, "condition")
            msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
            nc_n_try <- nc_n_try + 1
            if (nc_n_try > n_max_retries) {
                stop(msg)
            }
            else {
                message(msg, "\nRETRYing...")
                Sys.sleep(1)
            }
        }
        else {
            nc_retry <- F
        }
    }
    i_req <- i_req + 1
}
debug: i_t_beg <- (i_req - 1) * n_t_per_req + 1
debug: i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
debug: t_req <- times_todo[c(i_t_beg, i_t_end)]
debug: t_req_str <- format_ISO8601(t_req, usetz = "Z")
debug: if (verbose) message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
debug: message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
Fetching request 1 of 1 (2008-01-01 to 2008-12-01) ~ 19:38:03 UTC
debug: ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
    0), nc)
debug: unlink(ncs0)
debug: nc_retry <- T
debug: nc_n_try <- 1
debug: n_max_retries
debug: while (nc_retry) {
    res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
        url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
            bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
        time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
    if (inherits(res, "try-error")) {
        err <- attr(res, "condition")
        msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
        nc_n_try <- nc_n_try + 1
        if (nc_n_try > n_max_retries) {
            stop(msg)
        }
        else {
            message(msg, "\nRETRYing...")
            Sys.sleep(1)
        }
    }
    else {
        nc_retry <- F
    }
}
debug: res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
    url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
        bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
    time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
debug: if (inherits(res, "try-error")) {
    err <- attr(res, "condition")
    msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
    nc_n_try <- nc_n_try + 1
    if (nc_n_try > n_max_retries) {
        stop(msg)
    }
    else {
        message(msg, "\nRETRYing...")
        Sys.sleep(1)
    }
} else {
    nc_retry <- F
}
debug: nc_retry <- F
debug: (while) nc_retry
debug: i_req <- i_req + 1
debug: (while) i_req <= n_reqs
debug: ncs <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size > 
    0), nc)
debug: r <- terra::rast(ncs)
debug: stopifnot(all(class(terra::time(r)) %in% c("POSIXct", "POSIXt")))
debug: idx <- dplyr::pull(dplyr::filter(dplyr::arrange(dplyr::tibble(idx = 1:terra::nlyr(r), 
    time = terra::time(r)), time), !duplicated(time)), idx)
debug: r <- terra::subset(r, idx)
debug: stopifnot(terra::crs(r, proj = T) == wgs84)
debug: if (mask_tif) r <- terra::mask(r, sf_zones)
debug: lyrs <- glue("{var}|{terra::time(r)}")
debug: if (length(dims_other) > 0 && !all(length(dims[dims_other]) == 
    1)) stop(glue("Other dimensions not yet supported: {paste(dims_other, collapse = ',')}"))
debug: names(r) <- lyrs
debug: if (!is.null(rast_tif)) {
    if (fs::file_exists(rast_tif)) {
        r_tmp_tif <- tempfile(fileext = ".tif")
        r_tmp <- c(rast(rast_tif), r)
        r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
        terra::writeRaster(r_tmp, r_tmp_tif)
        fs::file_delete(rast_tif)
        fs::file_move(r_tmp_tif, rast_tif)
        rm(r)
        rm(r_tmp)
    }
    else {
        terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
    }
    r <- terra::rast(rast_tif)
}
debug: if (fs::file_exists(rast_tif)) {
    r_tmp_tif <- tempfile(fileext = ".tif")
    r_tmp <- c(rast(rast_tif), r)
    r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
    terra::writeRaster(r_tmp, r_tmp_tif)
    fs::file_delete(rast_tif)
    fs::file_move(r_tmp_tif, rast_tif)
    rm(r)
    rm(r_tmp)
} else {
    terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
}
debug: terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
debug: r <- terra::rast(rast_tif)
debug: d_r <- mutate(tidyr::pivot_longer(sf::st_drop_geometry(sf::st_as_sf(terra::zonal(x = r, 
    z = terra::vect(dplyr::select(sf_zones, dplyr::all_of(fld_zones))), 
    fun = zonal_fun, exact = T, na.rm = T, as.polygons = T))), 
    cols = -dplyr::any_of(fld_zones), names_to = "lyr", values_to = zonal_fun), 
    time = readr::parse_datetime(str_replace(lyr, glue("{var}\\|(.*)"), 
        "\\1")))
debug: if (!is.null(zonal_csv)) write_csv(d_r, zonal_csv)
debug: write_csv(d_r, zonal_csv)
debug: if (!keep_nc) unlink(dir_nc, recursive = T)
debug: unlink(dir_nc, recursive = T)
debug: return(d_r)
Downloading 1 requests, up to 1388 time slices each
Called from: extractr::ed_extract(ed, var = v, sf_zones = ply, bbox = bb, 
    mask_tif = F, rast_tif = glue("{dir_out}/{nms}/{yr}.tif"), 
    zonal_fun = "mean", zonal_csv = glue("{dir_out}/{nms}/{yr}.csv"), 
    dir_nc = glue("{dir_out}/{nms}/{yr}_nc"), keep_nc = F, n_max_vals_per_req = 1e+05, 
    time_min = time_min, time_max = time_max, verbose = T)
debug: while (i_req <= n_reqs) {
    i_t_beg <- (i_req - 1) * n_t_per_req + 1
    i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
    t_req <- times_todo[c(i_t_beg, i_t_end)]
    t_req_str <- format_ISO8601(t_req, usetz = "Z")
    if (verbose) 
        message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
    ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
        ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
        0), nc)
    unlink(ncs0)
    nc_retry <- T
    nc_n_try <- 1
    n_max_retries
    while (nc_retry) {
        res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
            url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
                bbox[["xmax"]]), latitude = c(bbox[["ymin"]], 
                bbox[["ymax"]]), time = t_req_str, fmt = "nc", 
            store = rerddap::disk(path = dir_nc)))
        if (inherits(res, "try-error")) {
            err <- attr(res, "condition")
            msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
            nc_n_try <- nc_n_try + 1
            if (nc_n_try > n_max_retries) {
                stop(msg)
            }
            else {
                message(msg, "\nRETRYing...")
                Sys.sleep(1)
            }
        }
        else {
            nc_retry <- F
        }
    }
    i_req <- i_req + 1
}
debug: i_t_beg <- (i_req - 1) * n_t_per_req + 1
debug: i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
debug: t_req <- times_todo[c(i_t_beg, i_t_end)]
debug: t_req_str <- format_ISO8601(t_req, usetz = "Z")
debug: if (verbose) message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
debug: message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
Fetching request 1 of 1 (2009-01-01 to 2009-12-01) ~ 19:38:05 UTC
debug: ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
    0), nc)
debug: unlink(ncs0)
debug: nc_retry <- T
debug: nc_n_try <- 1
debug: n_max_retries
debug: while (nc_retry) {
    res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
        url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
            bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
        time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
    if (inherits(res, "try-error")) {
        err <- attr(res, "condition")
        msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
        nc_n_try <- nc_n_try + 1
        if (nc_n_try > n_max_retries) {
            stop(msg)
        }
        else {
            message(msg, "\nRETRYing...")
            Sys.sleep(1)
        }
    }
    else {
        nc_retry <- F
    }
}
debug: res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
    url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
        bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
    time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
debug: if (inherits(res, "try-error")) {
    err <- attr(res, "condition")
    msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
    nc_n_try <- nc_n_try + 1
    if (nc_n_try > n_max_retries) {
        stop(msg)
    }
    else {
        message(msg, "\nRETRYing...")
        Sys.sleep(1)
    }
} else {
    nc_retry <- F
}
debug: nc_retry <- F
debug: (while) nc_retry
debug: i_req <- i_req + 1
debug: (while) i_req <= n_reqs
debug: ncs <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size > 
    0), nc)
debug: r <- terra::rast(ncs)
debug: stopifnot(all(class(terra::time(r)) %in% c("POSIXct", "POSIXt")))
debug: idx <- dplyr::pull(dplyr::filter(dplyr::arrange(dplyr::tibble(idx = 1:terra::nlyr(r), 
    time = terra::time(r)), time), !duplicated(time)), idx)
debug: r <- terra::subset(r, idx)
debug: stopifnot(terra::crs(r, proj = T) == wgs84)
debug: if (mask_tif) r <- terra::mask(r, sf_zones)
debug: lyrs <- glue("{var}|{terra::time(r)}")
debug: if (length(dims_other) > 0 && !all(length(dims[dims_other]) == 
    1)) stop(glue("Other dimensions not yet supported: {paste(dims_other, collapse = ',')}"))
debug: names(r) <- lyrs
debug: if (!is.null(rast_tif)) {
    if (fs::file_exists(rast_tif)) {
        r_tmp_tif <- tempfile(fileext = ".tif")
        r_tmp <- c(rast(rast_tif), r)
        r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
        terra::writeRaster(r_tmp, r_tmp_tif)
        fs::file_delete(rast_tif)
        fs::file_move(r_tmp_tif, rast_tif)
        rm(r)
        rm(r_tmp)
    }
    else {
        terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
    }
    r <- terra::rast(rast_tif)
}
debug: if (fs::file_exists(rast_tif)) {
    r_tmp_tif <- tempfile(fileext = ".tif")
    r_tmp <- c(rast(rast_tif), r)
    r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
    terra::writeRaster(r_tmp, r_tmp_tif)
    fs::file_delete(rast_tif)
    fs::file_move(r_tmp_tif, rast_tif)
    rm(r)
    rm(r_tmp)
} else {
    terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
}
debug: terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
debug: r <- terra::rast(rast_tif)
debug: d_r <- mutate(tidyr::pivot_longer(sf::st_drop_geometry(sf::st_as_sf(terra::zonal(x = r, 
    z = terra::vect(dplyr::select(sf_zones, dplyr::all_of(fld_zones))), 
    fun = zonal_fun, exact = T, na.rm = T, as.polygons = T))), 
    cols = -dplyr::any_of(fld_zones), names_to = "lyr", values_to = zonal_fun), 
    time = readr::parse_datetime(str_replace(lyr, glue("{var}\\|(.*)"), 
        "\\1")))
debug: if (!is.null(zonal_csv)) write_csv(d_r, zonal_csv)
debug: write_csv(d_r, zonal_csv)
debug: if (!keep_nc) unlink(dir_nc, recursive = T)
debug: unlink(dir_nc, recursive = T)
debug: return(d_r)
Downloading 1 requests, up to 1388 time slices each
Called from: extractr::ed_extract(ed, var = v, sf_zones = ply, bbox = bb, 
    mask_tif = F, rast_tif = glue("{dir_out}/{nms}/{yr}.tif"), 
    zonal_fun = "mean", zonal_csv = glue("{dir_out}/{nms}/{yr}.csv"), 
    dir_nc = glue("{dir_out}/{nms}/{yr}_nc"), keep_nc = F, n_max_vals_per_req = 1e+05, 
    time_min = time_min, time_max = time_max, verbose = T)
debug: while (i_req <= n_reqs) {
    i_t_beg <- (i_req - 1) * n_t_per_req + 1
    i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
    t_req <- times_todo[c(i_t_beg, i_t_end)]
    t_req_str <- format_ISO8601(t_req, usetz = "Z")
    if (verbose) 
        message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
    ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
        ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
        0), nc)
    unlink(ncs0)
    nc_retry <- T
    nc_n_try <- 1
    n_max_retries
    while (nc_retry) {
        res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
            url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
                bbox[["xmax"]]), latitude = c(bbox[["ymin"]], 
                bbox[["ymax"]]), time = t_req_str, fmt = "nc", 
            store = rerddap::disk(path = dir_nc)))
        if (inherits(res, "try-error")) {
            err <- attr(res, "condition")
            msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
            nc_n_try <- nc_n_try + 1
            if (nc_n_try > n_max_retries) {
                stop(msg)
            }
            else {
                message(msg, "\nRETRYing...")
                Sys.sleep(1)
            }
        }
        else {
            nc_retry <- F
        }
    }
    i_req <- i_req + 1
}
debug: i_t_beg <- (i_req - 1) * n_t_per_req + 1
debug: i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
debug: t_req <- times_todo[c(i_t_beg, i_t_end)]
debug: t_req_str <- format_ISO8601(t_req, usetz = "Z")
debug: if (verbose) message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
debug: message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
Fetching request 1 of 1 (2010-01-01 to 2010-12-01) ~ 19:38:06 UTC
debug: ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
    0), nc)
debug: unlink(ncs0)
debug: nc_retry <- T
debug: nc_n_try <- 1
debug: n_max_retries
debug: while (nc_retry) {
    res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
        url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
            bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
        time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
    if (inherits(res, "try-error")) {
        err <- attr(res, "condition")
        msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
        nc_n_try <- nc_n_try + 1
        if (nc_n_try > n_max_retries) {
            stop(msg)
        }
        else {
            message(msg, "\nRETRYing...")
            Sys.sleep(1)
        }
    }
    else {
        nc_retry <- F
    }
}
debug: res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
    url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
        bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
    time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
debug: if (inherits(res, "try-error")) {
    err <- attr(res, "condition")
    msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
    nc_n_try <- nc_n_try + 1
    if (nc_n_try > n_max_retries) {
        stop(msg)
    }
    else {
        message(msg, "\nRETRYing...")
        Sys.sleep(1)
    }
} else {
    nc_retry <- F
}
debug: nc_retry <- F
debug: (while) nc_retry
debug: i_req <- i_req + 1
debug: (while) i_req <= n_reqs
debug: ncs <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size > 
    0), nc)
debug: r <- terra::rast(ncs)
debug: stopifnot(all(class(terra::time(r)) %in% c("POSIXct", "POSIXt")))
debug: idx <- dplyr::pull(dplyr::filter(dplyr::arrange(dplyr::tibble(idx = 1:terra::nlyr(r), 
    time = terra::time(r)), time), !duplicated(time)), idx)
debug: r <- terra::subset(r, idx)
debug: stopifnot(terra::crs(r, proj = T) == wgs84)
debug: if (mask_tif) r <- terra::mask(r, sf_zones)
debug: lyrs <- glue("{var}|{terra::time(r)}")
debug: if (length(dims_other) > 0 && !all(length(dims[dims_other]) == 
    1)) stop(glue("Other dimensions not yet supported: {paste(dims_other, collapse = ',')}"))
debug: names(r) <- lyrs
debug: if (!is.null(rast_tif)) {
    if (fs::file_exists(rast_tif)) {
        r_tmp_tif <- tempfile(fileext = ".tif")
        r_tmp <- c(rast(rast_tif), r)
        r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
        terra::writeRaster(r_tmp, r_tmp_tif)
        fs::file_delete(rast_tif)
        fs::file_move(r_tmp_tif, rast_tif)
        rm(r)
        rm(r_tmp)
    }
    else {
        terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
    }
    r <- terra::rast(rast_tif)
}
debug: if (fs::file_exists(rast_tif)) {
    r_tmp_tif <- tempfile(fileext = ".tif")
    r_tmp <- c(rast(rast_tif), r)
    r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
    terra::writeRaster(r_tmp, r_tmp_tif)
    fs::file_delete(rast_tif)
    fs::file_move(r_tmp_tif, rast_tif)
    rm(r)
    rm(r_tmp)
} else {
    terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
}
debug: terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
debug: r <- terra::rast(rast_tif)
debug: d_r <- mutate(tidyr::pivot_longer(sf::st_drop_geometry(sf::st_as_sf(terra::zonal(x = r, 
    z = terra::vect(dplyr::select(sf_zones, dplyr::all_of(fld_zones))), 
    fun = zonal_fun, exact = T, na.rm = T, as.polygons = T))), 
    cols = -dplyr::any_of(fld_zones), names_to = "lyr", values_to = zonal_fun), 
    time = readr::parse_datetime(str_replace(lyr, glue("{var}\\|(.*)"), 
        "\\1")))
debug: if (!is.null(zonal_csv)) write_csv(d_r, zonal_csv)
debug: write_csv(d_r, zonal_csv)
debug: if (!keep_nc) unlink(dir_nc, recursive = T)
debug: unlink(dir_nc, recursive = T)
debug: return(d_r)
Downloading 1 requests, up to 1388 time slices each
Called from: extractr::ed_extract(ed, var = v, sf_zones = ply, bbox = bb, 
    mask_tif = F, rast_tif = glue("{dir_out}/{nms}/{yr}.tif"), 
    zonal_fun = "mean", zonal_csv = glue("{dir_out}/{nms}/{yr}.csv"), 
    dir_nc = glue("{dir_out}/{nms}/{yr}_nc"), keep_nc = F, n_max_vals_per_req = 1e+05, 
    time_min = time_min, time_max = time_max, verbose = T)
debug: while (i_req <= n_reqs) {
    i_t_beg <- (i_req - 1) * n_t_per_req + 1
    i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
    t_req <- times_todo[c(i_t_beg, i_t_end)]
    t_req_str <- format_ISO8601(t_req, usetz = "Z")
    if (verbose) 
        message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
    ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
        ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
        0), nc)
    unlink(ncs0)
    nc_retry <- T
    nc_n_try <- 1
    n_max_retries
    while (nc_retry) {
        res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
            url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
                bbox[["xmax"]]), latitude = c(bbox[["ymin"]], 
                bbox[["ymax"]]), time = t_req_str, fmt = "nc", 
            store = rerddap::disk(path = dir_nc)))
        if (inherits(res, "try-error")) {
            err <- attr(res, "condition")
            msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
            nc_n_try <- nc_n_try + 1
            if (nc_n_try > n_max_retries) {
                stop(msg)
            }
            else {
                message(msg, "\nRETRYing...")
                Sys.sleep(1)
            }
        }
        else {
            nc_retry <- F
        }
    }
    i_req <- i_req + 1
}
debug: i_t_beg <- (i_req - 1) * n_t_per_req + 1
debug: i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
debug: t_req <- times_todo[c(i_t_beg, i_t_end)]
debug: t_req_str <- format_ISO8601(t_req, usetz = "Z")
debug: if (verbose) message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
debug: message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
Fetching request 1 of 1 (2011-01-01 to 2011-12-01) ~ 19:38:08 UTC
debug: ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
    0), nc)
debug: unlink(ncs0)
debug: nc_retry <- T
debug: nc_n_try <- 1
debug: n_max_retries
debug: while (nc_retry) {
    res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
        url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
            bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
        time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
    if (inherits(res, "try-error")) {
        err <- attr(res, "condition")
        msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
        nc_n_try <- nc_n_try + 1
        if (nc_n_try > n_max_retries) {
            stop(msg)
        }
        else {
            message(msg, "\nRETRYing...")
            Sys.sleep(1)
        }
    }
    else {
        nc_retry <- F
    }
}
debug: res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
    url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
        bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
    time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
debug: if (inherits(res, "try-error")) {
    err <- attr(res, "condition")
    msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
    nc_n_try <- nc_n_try + 1
    if (nc_n_try > n_max_retries) {
        stop(msg)
    }
    else {
        message(msg, "\nRETRYing...")
        Sys.sleep(1)
    }
} else {
    nc_retry <- F
}
debug: nc_retry <- F
debug: (while) nc_retry
debug: i_req <- i_req + 1
debug: (while) i_req <= n_reqs
debug: ncs <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size > 
    0), nc)
debug: r <- terra::rast(ncs)
debug: stopifnot(all(class(terra::time(r)) %in% c("POSIXct", "POSIXt")))
debug: idx <- dplyr::pull(dplyr::filter(dplyr::arrange(dplyr::tibble(idx = 1:terra::nlyr(r), 
    time = terra::time(r)), time), !duplicated(time)), idx)
debug: r <- terra::subset(r, idx)
debug: stopifnot(terra::crs(r, proj = T) == wgs84)
debug: if (mask_tif) r <- terra::mask(r, sf_zones)
debug: lyrs <- glue("{var}|{terra::time(r)}")
debug: if (length(dims_other) > 0 && !all(length(dims[dims_other]) == 
    1)) stop(glue("Other dimensions not yet supported: {paste(dims_other, collapse = ',')}"))
debug: names(r) <- lyrs
debug: if (!is.null(rast_tif)) {
    if (fs::file_exists(rast_tif)) {
        r_tmp_tif <- tempfile(fileext = ".tif")
        r_tmp <- c(rast(rast_tif), r)
        r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
        terra::writeRaster(r_tmp, r_tmp_tif)
        fs::file_delete(rast_tif)
        fs::file_move(r_tmp_tif, rast_tif)
        rm(r)
        rm(r_tmp)
    }
    else {
        terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
    }
    r <- terra::rast(rast_tif)
}
debug: if (fs::file_exists(rast_tif)) {
    r_tmp_tif <- tempfile(fileext = ".tif")
    r_tmp <- c(rast(rast_tif), r)
    r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
    terra::writeRaster(r_tmp, r_tmp_tif)
    fs::file_delete(rast_tif)
    fs::file_move(r_tmp_tif, rast_tif)
    rm(r)
    rm(r_tmp)
} else {
    terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
}
debug: terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
debug: r <- terra::rast(rast_tif)
debug: d_r <- mutate(tidyr::pivot_longer(sf::st_drop_geometry(sf::st_as_sf(terra::zonal(x = r, 
    z = terra::vect(dplyr::select(sf_zones, dplyr::all_of(fld_zones))), 
    fun = zonal_fun, exact = T, na.rm = T, as.polygons = T))), 
    cols = -dplyr::any_of(fld_zones), names_to = "lyr", values_to = zonal_fun), 
    time = readr::parse_datetime(str_replace(lyr, glue("{var}\\|(.*)"), 
        "\\1")))
debug: if (!is.null(zonal_csv)) write_csv(d_r, zonal_csv)
debug: write_csv(d_r, zonal_csv)
debug: if (!keep_nc) unlink(dir_nc, recursive = T)
debug: unlink(dir_nc, recursive = T)
debug: return(d_r)
Downloading 1 requests, up to 1388 time slices each
Called from: extractr::ed_extract(ed, var = v, sf_zones = ply, bbox = bb, 
    mask_tif = F, rast_tif = glue("{dir_out}/{nms}/{yr}.tif"), 
    zonal_fun = "mean", zonal_csv = glue("{dir_out}/{nms}/{yr}.csv"), 
    dir_nc = glue("{dir_out}/{nms}/{yr}_nc"), keep_nc = F, n_max_vals_per_req = 1e+05, 
    time_min = time_min, time_max = time_max, verbose = T)
debug: while (i_req <= n_reqs) {
    i_t_beg <- (i_req - 1) * n_t_per_req + 1
    i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
    t_req <- times_todo[c(i_t_beg, i_t_end)]
    t_req_str <- format_ISO8601(t_req, usetz = "Z")
    if (verbose) 
        message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
    ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
        ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
        0), nc)
    unlink(ncs0)
    nc_retry <- T
    nc_n_try <- 1
    n_max_retries
    while (nc_retry) {
        res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
            url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
                bbox[["xmax"]]), latitude = c(bbox[["ymin"]], 
                bbox[["ymax"]]), time = t_req_str, fmt = "nc", 
            store = rerddap::disk(path = dir_nc)))
        if (inherits(res, "try-error")) {
            err <- attr(res, "condition")
            msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
            nc_n_try <- nc_n_try + 1
            if (nc_n_try > n_max_retries) {
                stop(msg)
            }
            else {
                message(msg, "\nRETRYing...")
                Sys.sleep(1)
            }
        }
        else {
            nc_retry <- F
        }
    }
    i_req <- i_req + 1
}
debug: i_t_beg <- (i_req - 1) * n_t_per_req + 1
debug: i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
debug: t_req <- times_todo[c(i_t_beg, i_t_end)]
debug: t_req_str <- format_ISO8601(t_req, usetz = "Z")
debug: if (verbose) message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
debug: message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
Fetching request 1 of 1 (2012-01-01 to 2012-12-01) ~ 19:38:10 UTC
debug: ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
    0), nc)
debug: unlink(ncs0)
debug: nc_retry <- T
debug: nc_n_try <- 1
debug: n_max_retries
debug: while (nc_retry) {
    res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
        url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
            bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
        time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
    if (inherits(res, "try-error")) {
        err <- attr(res, "condition")
        msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
        nc_n_try <- nc_n_try + 1
        if (nc_n_try > n_max_retries) {
            stop(msg)
        }
        else {
            message(msg, "\nRETRYing...")
            Sys.sleep(1)
        }
    }
    else {
        nc_retry <- F
    }
}
debug: res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
    url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
        bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
    time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
debug: if (inherits(res, "try-error")) {
    err <- attr(res, "condition")
    msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
    nc_n_try <- nc_n_try + 1
    if (nc_n_try > n_max_retries) {
        stop(msg)
    }
    else {
        message(msg, "\nRETRYing...")
        Sys.sleep(1)
    }
} else {
    nc_retry <- F
}
debug: nc_retry <- F
debug: (while) nc_retry
debug: i_req <- i_req + 1
debug: (while) i_req <= n_reqs
debug: ncs <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size > 
    0), nc)
debug: r <- terra::rast(ncs)
debug: stopifnot(all(class(terra::time(r)) %in% c("POSIXct", "POSIXt")))
debug: idx <- dplyr::pull(dplyr::filter(dplyr::arrange(dplyr::tibble(idx = 1:terra::nlyr(r), 
    time = terra::time(r)), time), !duplicated(time)), idx)
debug: r <- terra::subset(r, idx)
debug: stopifnot(terra::crs(r, proj = T) == wgs84)
debug: if (mask_tif) r <- terra::mask(r, sf_zones)
debug: lyrs <- glue("{var}|{terra::time(r)}")
debug: if (length(dims_other) > 0 && !all(length(dims[dims_other]) == 
    1)) stop(glue("Other dimensions not yet supported: {paste(dims_other, collapse = ',')}"))
debug: names(r) <- lyrs
debug: if (!is.null(rast_tif)) {
    if (fs::file_exists(rast_tif)) {
        r_tmp_tif <- tempfile(fileext = ".tif")
        r_tmp <- c(rast(rast_tif), r)
        r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
        terra::writeRaster(r_tmp, r_tmp_tif)
        fs::file_delete(rast_tif)
        fs::file_move(r_tmp_tif, rast_tif)
        rm(r)
        rm(r_tmp)
    }
    else {
        terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
    }
    r <- terra::rast(rast_tif)
}
debug: if (fs::file_exists(rast_tif)) {
    r_tmp_tif <- tempfile(fileext = ".tif")
    r_tmp <- c(rast(rast_tif), r)
    r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
    terra::writeRaster(r_tmp, r_tmp_tif)
    fs::file_delete(rast_tif)
    fs::file_move(r_tmp_tif, rast_tif)
    rm(r)
    rm(r_tmp)
} else {
    terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
}
debug: terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
debug: r <- terra::rast(rast_tif)
debug: d_r <- mutate(tidyr::pivot_longer(sf::st_drop_geometry(sf::st_as_sf(terra::zonal(x = r, 
    z = terra::vect(dplyr::select(sf_zones, dplyr::all_of(fld_zones))), 
    fun = zonal_fun, exact = T, na.rm = T, as.polygons = T))), 
    cols = -dplyr::any_of(fld_zones), names_to = "lyr", values_to = zonal_fun), 
    time = readr::parse_datetime(str_replace(lyr, glue("{var}\\|(.*)"), 
        "\\1")))
debug: if (!is.null(zonal_csv)) write_csv(d_r, zonal_csv)
debug: write_csv(d_r, zonal_csv)
debug: if (!keep_nc) unlink(dir_nc, recursive = T)
debug: unlink(dir_nc, recursive = T)
debug: return(d_r)
Downloading 1 requests, up to 1388 time slices each
Called from: extractr::ed_extract(ed, var = v, sf_zones = ply, bbox = bb, 
    mask_tif = F, rast_tif = glue("{dir_out}/{nms}/{yr}.tif"), 
    zonal_fun = "mean", zonal_csv = glue("{dir_out}/{nms}/{yr}.csv"), 
    dir_nc = glue("{dir_out}/{nms}/{yr}_nc"), keep_nc = F, n_max_vals_per_req = 1e+05, 
    time_min = time_min, time_max = time_max, verbose = T)
debug: while (i_req <= n_reqs) {
    i_t_beg <- (i_req - 1) * n_t_per_req + 1
    i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
    t_req <- times_todo[c(i_t_beg, i_t_end)]
    t_req_str <- format_ISO8601(t_req, usetz = "Z")
    if (verbose) 
        message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
    ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
        ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
        0), nc)
    unlink(ncs0)
    nc_retry <- T
    nc_n_try <- 1
    n_max_retries
    while (nc_retry) {
        res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
            url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
                bbox[["xmax"]]), latitude = c(bbox[["ymin"]], 
                bbox[["ymax"]]), time = t_req_str, fmt = "nc", 
            store = rerddap::disk(path = dir_nc)))
        if (inherits(res, "try-error")) {
            err <- attr(res, "condition")
            msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
            nc_n_try <- nc_n_try + 1
            if (nc_n_try > n_max_retries) {
                stop(msg)
            }
            else {
                message(msg, "\nRETRYing...")
                Sys.sleep(1)
            }
        }
        else {
            nc_retry <- F
        }
    }
    i_req <- i_req + 1
}
debug: i_t_beg <- (i_req - 1) * n_t_per_req + 1
debug: i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
debug: t_req <- times_todo[c(i_t_beg, i_t_end)]
debug: t_req_str <- format_ISO8601(t_req, usetz = "Z")
debug: if (verbose) message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
debug: message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
Fetching request 1 of 1 (2013-01-01 to 2013-12-01) ~ 19:38:11 UTC
debug: ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
    0), nc)
debug: unlink(ncs0)
debug: nc_retry <- T
debug: nc_n_try <- 1
debug: n_max_retries
debug: while (nc_retry) {
    res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
        url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
            bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
        time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
    if (inherits(res, "try-error")) {
        err <- attr(res, "condition")
        msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
        nc_n_try <- nc_n_try + 1
        if (nc_n_try > n_max_retries) {
            stop(msg)
        }
        else {
            message(msg, "\nRETRYing...")
            Sys.sleep(1)
        }
    }
    else {
        nc_retry <- F
    }
}
debug: res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
    url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
        bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
    time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
debug: if (inherits(res, "try-error")) {
    err <- attr(res, "condition")
    msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
    nc_n_try <- nc_n_try + 1
    if (nc_n_try > n_max_retries) {
        stop(msg)
    }
    else {
        message(msg, "\nRETRYing...")
        Sys.sleep(1)
    }
} else {
    nc_retry <- F
}
debug: nc_retry <- F
debug: (while) nc_retry
debug: i_req <- i_req + 1
debug: (while) i_req <= n_reqs
debug: ncs <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size > 
    0), nc)
debug: r <- terra::rast(ncs)
debug: stopifnot(all(class(terra::time(r)) %in% c("POSIXct", "POSIXt")))
debug: idx <- dplyr::pull(dplyr::filter(dplyr::arrange(dplyr::tibble(idx = 1:terra::nlyr(r), 
    time = terra::time(r)), time), !duplicated(time)), idx)
debug: r <- terra::subset(r, idx)
debug: stopifnot(terra::crs(r, proj = T) == wgs84)
debug: if (mask_tif) r <- terra::mask(r, sf_zones)
debug: lyrs <- glue("{var}|{terra::time(r)}")
debug: if (length(dims_other) > 0 && !all(length(dims[dims_other]) == 
    1)) stop(glue("Other dimensions not yet supported: {paste(dims_other, collapse = ',')}"))
debug: names(r) <- lyrs
debug: if (!is.null(rast_tif)) {
    if (fs::file_exists(rast_tif)) {
        r_tmp_tif <- tempfile(fileext = ".tif")
        r_tmp <- c(rast(rast_tif), r)
        r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
        terra::writeRaster(r_tmp, r_tmp_tif)
        fs::file_delete(rast_tif)
        fs::file_move(r_tmp_tif, rast_tif)
        rm(r)
        rm(r_tmp)
    }
    else {
        terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
    }
    r <- terra::rast(rast_tif)
}
debug: if (fs::file_exists(rast_tif)) {
    r_tmp_tif <- tempfile(fileext = ".tif")
    r_tmp <- c(rast(rast_tif), r)
    r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
    terra::writeRaster(r_tmp, r_tmp_tif)
    fs::file_delete(rast_tif)
    fs::file_move(r_tmp_tif, rast_tif)
    rm(r)
    rm(r_tmp)
} else {
    terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
}
debug: terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
debug: r <- terra::rast(rast_tif)
debug: d_r <- mutate(tidyr::pivot_longer(sf::st_drop_geometry(sf::st_as_sf(terra::zonal(x = r, 
    z = terra::vect(dplyr::select(sf_zones, dplyr::all_of(fld_zones))), 
    fun = zonal_fun, exact = T, na.rm = T, as.polygons = T))), 
    cols = -dplyr::any_of(fld_zones), names_to = "lyr", values_to = zonal_fun), 
    time = readr::parse_datetime(str_replace(lyr, glue("{var}\\|(.*)"), 
        "\\1")))
debug: if (!is.null(zonal_csv)) write_csv(d_r, zonal_csv)
debug: write_csv(d_r, zonal_csv)
debug: if (!keep_nc) unlink(dir_nc, recursive = T)
debug: unlink(dir_nc, recursive = T)
debug: return(d_r)
Downloading 1 requests, up to 1388 time slices each
Called from: extractr::ed_extract(ed, var = v, sf_zones = ply, bbox = bb, 
    mask_tif = F, rast_tif = glue("{dir_out}/{nms}/{yr}.tif"), 
    zonal_fun = "mean", zonal_csv = glue("{dir_out}/{nms}/{yr}.csv"), 
    dir_nc = glue("{dir_out}/{nms}/{yr}_nc"), keep_nc = F, n_max_vals_per_req = 1e+05, 
    time_min = time_min, time_max = time_max, verbose = T)
debug: while (i_req <= n_reqs) {
    i_t_beg <- (i_req - 1) * n_t_per_req + 1
    i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
    t_req <- times_todo[c(i_t_beg, i_t_end)]
    t_req_str <- format_ISO8601(t_req, usetz = "Z")
    if (verbose) 
        message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
    ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
        ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
        0), nc)
    unlink(ncs0)
    nc_retry <- T
    nc_n_try <- 1
    n_max_retries
    while (nc_retry) {
        res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
            url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
                bbox[["xmax"]]), latitude = c(bbox[["ymin"]], 
                bbox[["ymax"]]), time = t_req_str, fmt = "nc", 
            store = rerddap::disk(path = dir_nc)))
        if (inherits(res, "try-error")) {
            err <- attr(res, "condition")
            msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
            nc_n_try <- nc_n_try + 1
            if (nc_n_try > n_max_retries) {
                stop(msg)
            }
            else {
                message(msg, "\nRETRYing...")
                Sys.sleep(1)
            }
        }
        else {
            nc_retry <- F
        }
    }
    i_req <- i_req + 1
}
debug: i_t_beg <- (i_req - 1) * n_t_per_req + 1
debug: i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
debug: t_req <- times_todo[c(i_t_beg, i_t_end)]
debug: t_req_str <- format_ISO8601(t_req, usetz = "Z")
debug: if (verbose) message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
debug: message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
Fetching request 1 of 1 (2014-01-01 to 2014-12-01) ~ 19:38:13 UTC
debug: ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
    0), nc)
debug: unlink(ncs0)
debug: nc_retry <- T
debug: nc_n_try <- 1
debug: n_max_retries
debug: while (nc_retry) {
    res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
        url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
            bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
        time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
    if (inherits(res, "try-error")) {
        err <- attr(res, "condition")
        msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
        nc_n_try <- nc_n_try + 1
        if (nc_n_try > n_max_retries) {
            stop(msg)
        }
        else {
            message(msg, "\nRETRYing...")
            Sys.sleep(1)
        }
    }
    else {
        nc_retry <- F
    }
}
debug: res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
    url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
        bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
    time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
debug: if (inherits(res, "try-error")) {
    err <- attr(res, "condition")
    msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
    nc_n_try <- nc_n_try + 1
    if (nc_n_try > n_max_retries) {
        stop(msg)
    }
    else {
        message(msg, "\nRETRYing...")
        Sys.sleep(1)
    }
} else {
    nc_retry <- F
}
debug: nc_retry <- F
debug: (while) nc_retry
debug: i_req <- i_req + 1
debug: (while) i_req <= n_reqs
debug: ncs <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size > 
    0), nc)
debug: r <- terra::rast(ncs)
debug: stopifnot(all(class(terra::time(r)) %in% c("POSIXct", "POSIXt")))
debug: idx <- dplyr::pull(dplyr::filter(dplyr::arrange(dplyr::tibble(idx = 1:terra::nlyr(r), 
    time = terra::time(r)), time), !duplicated(time)), idx)
debug: r <- terra::subset(r, idx)
debug: stopifnot(terra::crs(r, proj = T) == wgs84)
debug: if (mask_tif) r <- terra::mask(r, sf_zones)
debug: lyrs <- glue("{var}|{terra::time(r)}")
debug: if (length(dims_other) > 0 && !all(length(dims[dims_other]) == 
    1)) stop(glue("Other dimensions not yet supported: {paste(dims_other, collapse = ',')}"))
debug: names(r) <- lyrs
debug: if (!is.null(rast_tif)) {
    if (fs::file_exists(rast_tif)) {
        r_tmp_tif <- tempfile(fileext = ".tif")
        r_tmp <- c(rast(rast_tif), r)
        r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
        terra::writeRaster(r_tmp, r_tmp_tif)
        fs::file_delete(rast_tif)
        fs::file_move(r_tmp_tif, rast_tif)
        rm(r)
        rm(r_tmp)
    }
    else {
        terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
    }
    r <- terra::rast(rast_tif)
}
debug: if (fs::file_exists(rast_tif)) {
    r_tmp_tif <- tempfile(fileext = ".tif")
    r_tmp <- c(rast(rast_tif), r)
    r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
    terra::writeRaster(r_tmp, r_tmp_tif)
    fs::file_delete(rast_tif)
    fs::file_move(r_tmp_tif, rast_tif)
    rm(r)
    rm(r_tmp)
} else {
    terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
}
debug: terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
debug: r <- terra::rast(rast_tif)
debug: d_r <- mutate(tidyr::pivot_longer(sf::st_drop_geometry(sf::st_as_sf(terra::zonal(x = r, 
    z = terra::vect(dplyr::select(sf_zones, dplyr::all_of(fld_zones))), 
    fun = zonal_fun, exact = T, na.rm = T, as.polygons = T))), 
    cols = -dplyr::any_of(fld_zones), names_to = "lyr", values_to = zonal_fun), 
    time = readr::parse_datetime(str_replace(lyr, glue("{var}\\|(.*)"), 
        "\\1")))
debug: if (!is.null(zonal_csv)) write_csv(d_r, zonal_csv)
debug: write_csv(d_r, zonal_csv)
debug: if (!keep_nc) unlink(dir_nc, recursive = T)
debug: unlink(dir_nc, recursive = T)
debug: return(d_r)
Downloading 1 requests, up to 1388 time slices each
Called from: extractr::ed_extract(ed, var = v, sf_zones = ply, bbox = bb, 
    mask_tif = F, rast_tif = glue("{dir_out}/{nms}/{yr}.tif"), 
    zonal_fun = "mean", zonal_csv = glue("{dir_out}/{nms}/{yr}.csv"), 
    dir_nc = glue("{dir_out}/{nms}/{yr}_nc"), keep_nc = F, n_max_vals_per_req = 1e+05, 
    time_min = time_min, time_max = time_max, verbose = T)
debug: while (i_req <= n_reqs) {
    i_t_beg <- (i_req - 1) * n_t_per_req + 1
    i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
    t_req <- times_todo[c(i_t_beg, i_t_end)]
    t_req_str <- format_ISO8601(t_req, usetz = "Z")
    if (verbose) 
        message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
    ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
        ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
        0), nc)
    unlink(ncs0)
    nc_retry <- T
    nc_n_try <- 1
    n_max_retries
    while (nc_retry) {
        res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
            url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
                bbox[["xmax"]]), latitude = c(bbox[["ymin"]], 
                bbox[["ymax"]]), time = t_req_str, fmt = "nc", 
            store = rerddap::disk(path = dir_nc)))
        if (inherits(res, "try-error")) {
            err <- attr(res, "condition")
            msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
            nc_n_try <- nc_n_try + 1
            if (nc_n_try > n_max_retries) {
                stop(msg)
            }
            else {
                message(msg, "\nRETRYing...")
                Sys.sleep(1)
            }
        }
        else {
            nc_retry <- F
        }
    }
    i_req <- i_req + 1
}
debug: i_t_beg <- (i_req - 1) * n_t_per_req + 1
debug: i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
debug: t_req <- times_todo[c(i_t_beg, i_t_end)]
debug: t_req_str <- format_ISO8601(t_req, usetz = "Z")
debug: if (verbose) message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
debug: message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
Fetching request 1 of 1 (2015-01-01 to 2015-12-01) ~ 19:38:14 UTC
debug: ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
    0), nc)
debug: unlink(ncs0)
debug: nc_retry <- T
debug: nc_n_try <- 1
debug: n_max_retries
debug: while (nc_retry) {
    res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
        url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
            bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
        time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
    if (inherits(res, "try-error")) {
        err <- attr(res, "condition")
        msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
        nc_n_try <- nc_n_try + 1
        if (nc_n_try > n_max_retries) {
            stop(msg)
        }
        else {
            message(msg, "\nRETRYing...")
            Sys.sleep(1)
        }
    }
    else {
        nc_retry <- F
    }
}
debug: res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
    url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
        bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
    time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
debug: if (inherits(res, "try-error")) {
    err <- attr(res, "condition")
    msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
    nc_n_try <- nc_n_try + 1
    if (nc_n_try > n_max_retries) {
        stop(msg)
    }
    else {
        message(msg, "\nRETRYing...")
        Sys.sleep(1)
    }
} else {
    nc_retry <- F
}
debug: nc_retry <- F
debug: (while) nc_retry
debug: i_req <- i_req + 1
debug: (while) i_req <= n_reqs
debug: ncs <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size > 
    0), nc)
debug: r <- terra::rast(ncs)
debug: stopifnot(all(class(terra::time(r)) %in% c("POSIXct", "POSIXt")))
debug: idx <- dplyr::pull(dplyr::filter(dplyr::arrange(dplyr::tibble(idx = 1:terra::nlyr(r), 
    time = terra::time(r)), time), !duplicated(time)), idx)
debug: r <- terra::subset(r, idx)
debug: stopifnot(terra::crs(r, proj = T) == wgs84)
debug: if (mask_tif) r <- terra::mask(r, sf_zones)
debug: lyrs <- glue("{var}|{terra::time(r)}")
debug: if (length(dims_other) > 0 && !all(length(dims[dims_other]) == 
    1)) stop(glue("Other dimensions not yet supported: {paste(dims_other, collapse = ',')}"))
debug: names(r) <- lyrs
debug: if (!is.null(rast_tif)) {
    if (fs::file_exists(rast_tif)) {
        r_tmp_tif <- tempfile(fileext = ".tif")
        r_tmp <- c(rast(rast_tif), r)
        r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
        terra::writeRaster(r_tmp, r_tmp_tif)
        fs::file_delete(rast_tif)
        fs::file_move(r_tmp_tif, rast_tif)
        rm(r)
        rm(r_tmp)
    }
    else {
        terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
    }
    r <- terra::rast(rast_tif)
}
debug: if (fs::file_exists(rast_tif)) {
    r_tmp_tif <- tempfile(fileext = ".tif")
    r_tmp <- c(rast(rast_tif), r)
    r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
    terra::writeRaster(r_tmp, r_tmp_tif)
    fs::file_delete(rast_tif)
    fs::file_move(r_tmp_tif, rast_tif)
    rm(r)
    rm(r_tmp)
} else {
    terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
}
debug: terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
debug: r <- terra::rast(rast_tif)
debug: d_r <- mutate(tidyr::pivot_longer(sf::st_drop_geometry(sf::st_as_sf(terra::zonal(x = r, 
    z = terra::vect(dplyr::select(sf_zones, dplyr::all_of(fld_zones))), 
    fun = zonal_fun, exact = T, na.rm = T, as.polygons = T))), 
    cols = -dplyr::any_of(fld_zones), names_to = "lyr", values_to = zonal_fun), 
    time = readr::parse_datetime(str_replace(lyr, glue("{var}\\|(.*)"), 
        "\\1")))
debug: if (!is.null(zonal_csv)) write_csv(d_r, zonal_csv)
debug: write_csv(d_r, zonal_csv)
debug: if (!keep_nc) unlink(dir_nc, recursive = T)
debug: unlink(dir_nc, recursive = T)
debug: return(d_r)
Downloading 1 requests, up to 1388 time slices each
Called from: extractr::ed_extract(ed, var = v, sf_zones = ply, bbox = bb, 
    mask_tif = F, rast_tif = glue("{dir_out}/{nms}/{yr}.tif"), 
    zonal_fun = "mean", zonal_csv = glue("{dir_out}/{nms}/{yr}.csv"), 
    dir_nc = glue("{dir_out}/{nms}/{yr}_nc"), keep_nc = F, n_max_vals_per_req = 1e+05, 
    time_min = time_min, time_max = time_max, verbose = T)
debug: while (i_req <= n_reqs) {
    i_t_beg <- (i_req - 1) * n_t_per_req + 1
    i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
    t_req <- times_todo[c(i_t_beg, i_t_end)]
    t_req_str <- format_ISO8601(t_req, usetz = "Z")
    if (verbose) 
        message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
    ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
        ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
        0), nc)
    unlink(ncs0)
    nc_retry <- T
    nc_n_try <- 1
    n_max_retries
    while (nc_retry) {
        res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
            url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
                bbox[["xmax"]]), latitude = c(bbox[["ymin"]], 
                bbox[["ymax"]]), time = t_req_str, fmt = "nc", 
            store = rerddap::disk(path = dir_nc)))
        if (inherits(res, "try-error")) {
            err <- attr(res, "condition")
            msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
            nc_n_try <- nc_n_try + 1
            if (nc_n_try > n_max_retries) {
                stop(msg)
            }
            else {
                message(msg, "\nRETRYing...")
                Sys.sleep(1)
            }
        }
        else {
            nc_retry <- F
        }
    }
    i_req <- i_req + 1
}
debug: i_t_beg <- (i_req - 1) * n_t_per_req + 1
debug: i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
debug: t_req <- times_todo[c(i_t_beg, i_t_end)]
debug: t_req_str <- format_ISO8601(t_req, usetz = "Z")
debug: if (verbose) message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
debug: message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
Fetching request 1 of 1 (2016-01-01 to 2016-12-01) ~ 19:38:16 UTC
debug: ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
    0), nc)
debug: unlink(ncs0)
debug: nc_retry <- T
debug: nc_n_try <- 1
debug: n_max_retries
debug: while (nc_retry) {
    res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
        url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
            bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
        time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
    if (inherits(res, "try-error")) {
        err <- attr(res, "condition")
        msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
        nc_n_try <- nc_n_try + 1
        if (nc_n_try > n_max_retries) {
            stop(msg)
        }
        else {
            message(msg, "\nRETRYing...")
            Sys.sleep(1)
        }
    }
    else {
        nc_retry <- F
    }
}
debug: res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
    url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
        bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
    time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
debug: if (inherits(res, "try-error")) {
    err <- attr(res, "condition")
    msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
    nc_n_try <- nc_n_try + 1
    if (nc_n_try > n_max_retries) {
        stop(msg)
    }
    else {
        message(msg, "\nRETRYing...")
        Sys.sleep(1)
    }
} else {
    nc_retry <- F
}
debug: nc_retry <- F
debug: (while) nc_retry
debug: i_req <- i_req + 1
debug: (while) i_req <= n_reqs
debug: ncs <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size > 
    0), nc)
debug: r <- terra::rast(ncs)
debug: stopifnot(all(class(terra::time(r)) %in% c("POSIXct", "POSIXt")))
debug: idx <- dplyr::pull(dplyr::filter(dplyr::arrange(dplyr::tibble(idx = 1:terra::nlyr(r), 
    time = terra::time(r)), time), !duplicated(time)), idx)
debug: r <- terra::subset(r, idx)
debug: stopifnot(terra::crs(r, proj = T) == wgs84)
debug: if (mask_tif) r <- terra::mask(r, sf_zones)
debug: lyrs <- glue("{var}|{terra::time(r)}")
debug: if (length(dims_other) > 0 && !all(length(dims[dims_other]) == 
    1)) stop(glue("Other dimensions not yet supported: {paste(dims_other, collapse = ',')}"))
debug: names(r) <- lyrs
debug: if (!is.null(rast_tif)) {
    if (fs::file_exists(rast_tif)) {
        r_tmp_tif <- tempfile(fileext = ".tif")
        r_tmp <- c(rast(rast_tif), r)
        r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
        terra::writeRaster(r_tmp, r_tmp_tif)
        fs::file_delete(rast_tif)
        fs::file_move(r_tmp_tif, rast_tif)
        rm(r)
        rm(r_tmp)
    }
    else {
        terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
    }
    r <- terra::rast(rast_tif)
}
debug: if (fs::file_exists(rast_tif)) {
    r_tmp_tif <- tempfile(fileext = ".tif")
    r_tmp <- c(rast(rast_tif), r)
    r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
    terra::writeRaster(r_tmp, r_tmp_tif)
    fs::file_delete(rast_tif)
    fs::file_move(r_tmp_tif, rast_tif)
    rm(r)
    rm(r_tmp)
} else {
    terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
}
debug: terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
debug: r <- terra::rast(rast_tif)
debug: d_r <- mutate(tidyr::pivot_longer(sf::st_drop_geometry(sf::st_as_sf(terra::zonal(x = r, 
    z = terra::vect(dplyr::select(sf_zones, dplyr::all_of(fld_zones))), 
    fun = zonal_fun, exact = T, na.rm = T, as.polygons = T))), 
    cols = -dplyr::any_of(fld_zones), names_to = "lyr", values_to = zonal_fun), 
    time = readr::parse_datetime(str_replace(lyr, glue("{var}\\|(.*)"), 
        "\\1")))
debug: if (!is.null(zonal_csv)) write_csv(d_r, zonal_csv)
debug: write_csv(d_r, zonal_csv)
debug: if (!keep_nc) unlink(dir_nc, recursive = T)
debug: unlink(dir_nc, recursive = T)
debug: return(d_r)
Downloading 1 requests, up to 1388 time slices each
Called from: extractr::ed_extract(ed, var = v, sf_zones = ply, bbox = bb, 
    mask_tif = F, rast_tif = glue("{dir_out}/{nms}/{yr}.tif"), 
    zonal_fun = "mean", zonal_csv = glue("{dir_out}/{nms}/{yr}.csv"), 
    dir_nc = glue("{dir_out}/{nms}/{yr}_nc"), keep_nc = F, n_max_vals_per_req = 1e+05, 
    time_min = time_min, time_max = time_max, verbose = T)
debug: while (i_req <= n_reqs) {
    i_t_beg <- (i_req - 1) * n_t_per_req + 1
    i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
    t_req <- times_todo[c(i_t_beg, i_t_end)]
    t_req_str <- format_ISO8601(t_req, usetz = "Z")
    if (verbose) 
        message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
    ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
        ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
        0), nc)
    unlink(ncs0)
    nc_retry <- T
    nc_n_try <- 1
    n_max_retries
    while (nc_retry) {
        res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
            url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
                bbox[["xmax"]]), latitude = c(bbox[["ymin"]], 
                bbox[["ymax"]]), time = t_req_str, fmt = "nc", 
            store = rerddap::disk(path = dir_nc)))
        if (inherits(res, "try-error")) {
            err <- attr(res, "condition")
            msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
            nc_n_try <- nc_n_try + 1
            if (nc_n_try > n_max_retries) {
                stop(msg)
            }
            else {
                message(msg, "\nRETRYing...")
                Sys.sleep(1)
            }
        }
        else {
            nc_retry <- F
        }
    }
    i_req <- i_req + 1
}
debug: i_t_beg <- (i_req - 1) * n_t_per_req + 1
debug: i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
debug: t_req <- times_todo[c(i_t_beg, i_t_end)]
debug: t_req_str <- format_ISO8601(t_req, usetz = "Z")
debug: if (verbose) message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
debug: message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
Fetching request 1 of 1 (2017-01-01 to 2017-12-01) ~ 19:38:18 UTC
debug: ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
    0), nc)
debug: unlink(ncs0)
debug: nc_retry <- T
debug: nc_n_try <- 1
debug: n_max_retries
debug: while (nc_retry) {
    res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
        url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
            bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
        time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
    if (inherits(res, "try-error")) {
        err <- attr(res, "condition")
        msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
        nc_n_try <- nc_n_try + 1
        if (nc_n_try > n_max_retries) {
            stop(msg)
        }
        else {
            message(msg, "\nRETRYing...")
            Sys.sleep(1)
        }
    }
    else {
        nc_retry <- F
    }
}
debug: res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
    url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
        bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
    time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
debug: if (inherits(res, "try-error")) {
    err <- attr(res, "condition")
    msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
    nc_n_try <- nc_n_try + 1
    if (nc_n_try > n_max_retries) {
        stop(msg)
    }
    else {
        message(msg, "\nRETRYing...")
        Sys.sleep(1)
    }
} else {
    nc_retry <- F
}
debug: nc_retry <- F
debug: (while) nc_retry
debug: i_req <- i_req + 1
debug: (while) i_req <= n_reqs
debug: ncs <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size > 
    0), nc)
debug: r <- terra::rast(ncs)
debug: stopifnot(all(class(terra::time(r)) %in% c("POSIXct", "POSIXt")))
debug: idx <- dplyr::pull(dplyr::filter(dplyr::arrange(dplyr::tibble(idx = 1:terra::nlyr(r), 
    time = terra::time(r)), time), !duplicated(time)), idx)
debug: r <- terra::subset(r, idx)
debug: stopifnot(terra::crs(r, proj = T) == wgs84)
debug: if (mask_tif) r <- terra::mask(r, sf_zones)
debug: lyrs <- glue("{var}|{terra::time(r)}")
debug: if (length(dims_other) > 0 && !all(length(dims[dims_other]) == 
    1)) stop(glue("Other dimensions not yet supported: {paste(dims_other, collapse = ',')}"))
debug: names(r) <- lyrs
debug: if (!is.null(rast_tif)) {
    if (fs::file_exists(rast_tif)) {
        r_tmp_tif <- tempfile(fileext = ".tif")
        r_tmp <- c(rast(rast_tif), r)
        r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
        terra::writeRaster(r_tmp, r_tmp_tif)
        fs::file_delete(rast_tif)
        fs::file_move(r_tmp_tif, rast_tif)
        rm(r)
        rm(r_tmp)
    }
    else {
        terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
    }
    r <- terra::rast(rast_tif)
}
debug: if (fs::file_exists(rast_tif)) {
    r_tmp_tif <- tempfile(fileext = ".tif")
    r_tmp <- c(rast(rast_tif), r)
    r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
    terra::writeRaster(r_tmp, r_tmp_tif)
    fs::file_delete(rast_tif)
    fs::file_move(r_tmp_tif, rast_tif)
    rm(r)
    rm(r_tmp)
} else {
    terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
}
debug: terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
debug: r <- terra::rast(rast_tif)
debug: d_r <- mutate(tidyr::pivot_longer(sf::st_drop_geometry(sf::st_as_sf(terra::zonal(x = r, 
    z = terra::vect(dplyr::select(sf_zones, dplyr::all_of(fld_zones))), 
    fun = zonal_fun, exact = T, na.rm = T, as.polygons = T))), 
    cols = -dplyr::any_of(fld_zones), names_to = "lyr", values_to = zonal_fun), 
    time = readr::parse_datetime(str_replace(lyr, glue("{var}\\|(.*)"), 
        "\\1")))
debug: if (!is.null(zonal_csv)) write_csv(d_r, zonal_csv)
debug: write_csv(d_r, zonal_csv)
debug: if (!keep_nc) unlink(dir_nc, recursive = T)
debug: unlink(dir_nc, recursive = T)
debug: return(d_r)
Downloading 1 requests, up to 1388 time slices each
Called from: extractr::ed_extract(ed, var = v, sf_zones = ply, bbox = bb, 
    mask_tif = F, rast_tif = glue("{dir_out}/{nms}/{yr}.tif"), 
    zonal_fun = "mean", zonal_csv = glue("{dir_out}/{nms}/{yr}.csv"), 
    dir_nc = glue("{dir_out}/{nms}/{yr}_nc"), keep_nc = F, n_max_vals_per_req = 1e+05, 
    time_min = time_min, time_max = time_max, verbose = T)
debug: while (i_req <= n_reqs) {
    i_t_beg <- (i_req - 1) * n_t_per_req + 1
    i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
    t_req <- times_todo[c(i_t_beg, i_t_end)]
    t_req_str <- format_ISO8601(t_req, usetz = "Z")
    if (verbose) 
        message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
    ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
        ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
        0), nc)
    unlink(ncs0)
    nc_retry <- T
    nc_n_try <- 1
    n_max_retries
    while (nc_retry) {
        res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
            url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
                bbox[["xmax"]]), latitude = c(bbox[["ymin"]], 
                bbox[["ymax"]]), time = t_req_str, fmt = "nc", 
            store = rerddap::disk(path = dir_nc)))
        if (inherits(res, "try-error")) {
            err <- attr(res, "condition")
            msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
            nc_n_try <- nc_n_try + 1
            if (nc_n_try > n_max_retries) {
                stop(msg)
            }
            else {
                message(msg, "\nRETRYing...")
                Sys.sleep(1)
            }
        }
        else {
            nc_retry <- F
        }
    }
    i_req <- i_req + 1
}
debug: i_t_beg <- (i_req - 1) * n_t_per_req + 1
debug: i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
debug: t_req <- times_todo[c(i_t_beg, i_t_end)]
debug: t_req_str <- format_ISO8601(t_req, usetz = "Z")
debug: if (verbose) message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
debug: message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
Fetching request 1 of 1 (2018-01-01 to 2018-12-01) ~ 19:38:19 UTC
debug: ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
    0), nc)
debug: unlink(ncs0)
debug: nc_retry <- T
debug: nc_n_try <- 1
debug: n_max_retries
debug: while (nc_retry) {
    res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
        url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
            bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
        time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
    if (inherits(res, "try-error")) {
        err <- attr(res, "condition")
        msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
        nc_n_try <- nc_n_try + 1
        if (nc_n_try > n_max_retries) {
            stop(msg)
        }
        else {
            message(msg, "\nRETRYing...")
            Sys.sleep(1)
        }
    }
    else {
        nc_retry <- F
    }
}
debug: res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
    url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
        bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
    time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
debug: if (inherits(res, "try-error")) {
    err <- attr(res, "condition")
    msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
    nc_n_try <- nc_n_try + 1
    if (nc_n_try > n_max_retries) {
        stop(msg)
    }
    else {
        message(msg, "\nRETRYing...")
        Sys.sleep(1)
    }
} else {
    nc_retry <- F
}
debug: nc_retry <- F
debug: (while) nc_retry
debug: i_req <- i_req + 1
debug: (while) i_req <= n_reqs
debug: ncs <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size > 
    0), nc)
debug: r <- terra::rast(ncs)
debug: stopifnot(all(class(terra::time(r)) %in% c("POSIXct", "POSIXt")))
debug: idx <- dplyr::pull(dplyr::filter(dplyr::arrange(dplyr::tibble(idx = 1:terra::nlyr(r), 
    time = terra::time(r)), time), !duplicated(time)), idx)
debug: r <- terra::subset(r, idx)
debug: stopifnot(terra::crs(r, proj = T) == wgs84)
debug: if (mask_tif) r <- terra::mask(r, sf_zones)
debug: lyrs <- glue("{var}|{terra::time(r)}")
debug: if (length(dims_other) > 0 && !all(length(dims[dims_other]) == 
    1)) stop(glue("Other dimensions not yet supported: {paste(dims_other, collapse = ',')}"))
debug: names(r) <- lyrs
debug: if (!is.null(rast_tif)) {
    if (fs::file_exists(rast_tif)) {
        r_tmp_tif <- tempfile(fileext = ".tif")
        r_tmp <- c(rast(rast_tif), r)
        r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
        terra::writeRaster(r_tmp, r_tmp_tif)
        fs::file_delete(rast_tif)
        fs::file_move(r_tmp_tif, rast_tif)
        rm(r)
        rm(r_tmp)
    }
    else {
        terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
    }
    r <- terra::rast(rast_tif)
}
debug: if (fs::file_exists(rast_tif)) {
    r_tmp_tif <- tempfile(fileext = ".tif")
    r_tmp <- c(rast(rast_tif), r)
    r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
    terra::writeRaster(r_tmp, r_tmp_tif)
    fs::file_delete(rast_tif)
    fs::file_move(r_tmp_tif, rast_tif)
    rm(r)
    rm(r_tmp)
} else {
    terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
}
debug: terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
debug: r <- terra::rast(rast_tif)
debug: d_r <- mutate(tidyr::pivot_longer(sf::st_drop_geometry(sf::st_as_sf(terra::zonal(x = r, 
    z = terra::vect(dplyr::select(sf_zones, dplyr::all_of(fld_zones))), 
    fun = zonal_fun, exact = T, na.rm = T, as.polygons = T))), 
    cols = -dplyr::any_of(fld_zones), names_to = "lyr", values_to = zonal_fun), 
    time = readr::parse_datetime(str_replace(lyr, glue("{var}\\|(.*)"), 
        "\\1")))
debug: if (!is.null(zonal_csv)) write_csv(d_r, zonal_csv)
debug: write_csv(d_r, zonal_csv)
debug: if (!keep_nc) unlink(dir_nc, recursive = T)
debug: unlink(dir_nc, recursive = T)
debug: return(d_r)
Downloading 1 requests, up to 1388 time slices each
Called from: extractr::ed_extract(ed, var = v, sf_zones = ply, bbox = bb, 
    mask_tif = F, rast_tif = glue("{dir_out}/{nms}/{yr}.tif"), 
    zonal_fun = "mean", zonal_csv = glue("{dir_out}/{nms}/{yr}.csv"), 
    dir_nc = glue("{dir_out}/{nms}/{yr}_nc"), keep_nc = F, n_max_vals_per_req = 1e+05, 
    time_min = time_min, time_max = time_max, verbose = T)
debug: while (i_req <= n_reqs) {
    i_t_beg <- (i_req - 1) * n_t_per_req + 1
    i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
    t_req <- times_todo[c(i_t_beg, i_t_end)]
    t_req_str <- format_ISO8601(t_req, usetz = "Z")
    if (verbose) 
        message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
    ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
        ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
        0), nc)
    unlink(ncs0)
    nc_retry <- T
    nc_n_try <- 1
    n_max_retries
    while (nc_retry) {
        res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
            url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
                bbox[["xmax"]]), latitude = c(bbox[["ymin"]], 
                bbox[["ymax"]]), time = t_req_str, fmt = "nc", 
            store = rerddap::disk(path = dir_nc)))
        if (inherits(res, "try-error")) {
            err <- attr(res, "condition")
            msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
            nc_n_try <- nc_n_try + 1
            if (nc_n_try > n_max_retries) {
                stop(msg)
            }
            else {
                message(msg, "\nRETRYing...")
                Sys.sleep(1)
            }
        }
        else {
            nc_retry <- F
        }
    }
    i_req <- i_req + 1
}
debug: i_t_beg <- (i_req - 1) * n_t_per_req + 1
debug: i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
debug: t_req <- times_todo[c(i_t_beg, i_t_end)]
debug: t_req_str <- format_ISO8601(t_req, usetz = "Z")
debug: if (verbose) message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
debug: message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
Fetching request 1 of 1 (2019-01-01 to 2019-12-01) ~ 19:38:21 UTC
debug: ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
    0), nc)
debug: unlink(ncs0)
debug: nc_retry <- T
debug: nc_n_try <- 1
debug: n_max_retries
debug: while (nc_retry) {
    res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
        url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
            bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
        time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
    if (inherits(res, "try-error")) {
        err <- attr(res, "condition")
        msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
        nc_n_try <- nc_n_try + 1
        if (nc_n_try > n_max_retries) {
            stop(msg)
        }
        else {
            message(msg, "\nRETRYing...")
            Sys.sleep(1)
        }
    }
    else {
        nc_retry <- F
    }
}
debug: res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
    url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
        bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
    time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
debug: if (inherits(res, "try-error")) {
    err <- attr(res, "condition")
    msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
    nc_n_try <- nc_n_try + 1
    if (nc_n_try > n_max_retries) {
        stop(msg)
    }
    else {
        message(msg, "\nRETRYing...")
        Sys.sleep(1)
    }
} else {
    nc_retry <- F
}
debug: nc_retry <- F
debug: (while) nc_retry
debug: i_req <- i_req + 1
debug: (while) i_req <= n_reqs
debug: ncs <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size > 
    0), nc)
debug: r <- terra::rast(ncs)
debug: stopifnot(all(class(terra::time(r)) %in% c("POSIXct", "POSIXt")))
debug: idx <- dplyr::pull(dplyr::filter(dplyr::arrange(dplyr::tibble(idx = 1:terra::nlyr(r), 
    time = terra::time(r)), time), !duplicated(time)), idx)
debug: r <- terra::subset(r, idx)
debug: stopifnot(terra::crs(r, proj = T) == wgs84)
debug: if (mask_tif) r <- terra::mask(r, sf_zones)
debug: lyrs <- glue("{var}|{terra::time(r)}")
debug: if (length(dims_other) > 0 && !all(length(dims[dims_other]) == 
    1)) stop(glue("Other dimensions not yet supported: {paste(dims_other, collapse = ',')}"))
debug: names(r) <- lyrs
debug: if (!is.null(rast_tif)) {
    if (fs::file_exists(rast_tif)) {
        r_tmp_tif <- tempfile(fileext = ".tif")
        r_tmp <- c(rast(rast_tif), r)
        r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
        terra::writeRaster(r_tmp, r_tmp_tif)
        fs::file_delete(rast_tif)
        fs::file_move(r_tmp_tif, rast_tif)
        rm(r)
        rm(r_tmp)
    }
    else {
        terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
    }
    r <- terra::rast(rast_tif)
}
debug: if (fs::file_exists(rast_tif)) {
    r_tmp_tif <- tempfile(fileext = ".tif")
    r_tmp <- c(rast(rast_tif), r)
    r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
    terra::writeRaster(r_tmp, r_tmp_tif)
    fs::file_delete(rast_tif)
    fs::file_move(r_tmp_tif, rast_tif)
    rm(r)
    rm(r_tmp)
} else {
    terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
}
debug: terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
debug: r <- terra::rast(rast_tif)
debug: d_r <- mutate(tidyr::pivot_longer(sf::st_drop_geometry(sf::st_as_sf(terra::zonal(x = r, 
    z = terra::vect(dplyr::select(sf_zones, dplyr::all_of(fld_zones))), 
    fun = zonal_fun, exact = T, na.rm = T, as.polygons = T))), 
    cols = -dplyr::any_of(fld_zones), names_to = "lyr", values_to = zonal_fun), 
    time = readr::parse_datetime(str_replace(lyr, glue("{var}\\|(.*)"), 
        "\\1")))
debug: if (!is.null(zonal_csv)) write_csv(d_r, zonal_csv)
debug: write_csv(d_r, zonal_csv)
debug: if (!keep_nc) unlink(dir_nc, recursive = T)
debug: unlink(dir_nc, recursive = T)
debug: return(d_r)
Downloading 1 requests, up to 1388 time slices each
Called from: extractr::ed_extract(ed, var = v, sf_zones = ply, bbox = bb, 
    mask_tif = F, rast_tif = glue("{dir_out}/{nms}/{yr}.tif"), 
    zonal_fun = "mean", zonal_csv = glue("{dir_out}/{nms}/{yr}.csv"), 
    dir_nc = glue("{dir_out}/{nms}/{yr}_nc"), keep_nc = F, n_max_vals_per_req = 1e+05, 
    time_min = time_min, time_max = time_max, verbose = T)
debug: while (i_req <= n_reqs) {
    i_t_beg <- (i_req - 1) * n_t_per_req + 1
    i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
    t_req <- times_todo[c(i_t_beg, i_t_end)]
    t_req_str <- format_ISO8601(t_req, usetz = "Z")
    if (verbose) 
        message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
    ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
        ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
        0), nc)
    unlink(ncs0)
    nc_retry <- T
    nc_n_try <- 1
    n_max_retries
    while (nc_retry) {
        res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
            url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
                bbox[["xmax"]]), latitude = c(bbox[["ymin"]], 
                bbox[["ymax"]]), time = t_req_str, fmt = "nc", 
            store = rerddap::disk(path = dir_nc)))
        if (inherits(res, "try-error")) {
            err <- attr(res, "condition")
            msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
            nc_n_try <- nc_n_try + 1
            if (nc_n_try > n_max_retries) {
                stop(msg)
            }
            else {
                message(msg, "\nRETRYing...")
                Sys.sleep(1)
            }
        }
        else {
            nc_retry <- F
        }
    }
    i_req <- i_req + 1
}
debug: i_t_beg <- (i_req - 1) * n_t_per_req + 1
debug: i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
debug: t_req <- times_todo[c(i_t_beg, i_t_end)]
debug: t_req_str <- format_ISO8601(t_req, usetz = "Z")
debug: if (verbose) message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
debug: message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
Fetching request 1 of 1 (2020-01-01 to 2020-12-01) ~ 19:38:22 UTC
debug: ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
    0), nc)
debug: unlink(ncs0)
debug: nc_retry <- T
debug: nc_n_try <- 1
debug: n_max_retries
debug: while (nc_retry) {
    res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
        url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
            bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
        time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
    if (inherits(res, "try-error")) {
        err <- attr(res, "condition")
        msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
        nc_n_try <- nc_n_try + 1
        if (nc_n_try > n_max_retries) {
            stop(msg)
        }
        else {
            message(msg, "\nRETRYing...")
            Sys.sleep(1)
        }
    }
    else {
        nc_retry <- F
    }
}
debug: res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
    url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
        bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
    time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
debug: if (inherits(res, "try-error")) {
    err <- attr(res, "condition")
    msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
    nc_n_try <- nc_n_try + 1
    if (nc_n_try > n_max_retries) {
        stop(msg)
    }
    else {
        message(msg, "\nRETRYing...")
        Sys.sleep(1)
    }
} else {
    nc_retry <- F
}
debug: nc_retry <- F
debug: (while) nc_retry
debug: i_req <- i_req + 1
debug: (while) i_req <= n_reqs
debug: ncs <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size > 
    0), nc)
debug: r <- terra::rast(ncs)
debug: stopifnot(all(class(terra::time(r)) %in% c("POSIXct", "POSIXt")))
debug: idx <- dplyr::pull(dplyr::filter(dplyr::arrange(dplyr::tibble(idx = 1:terra::nlyr(r), 
    time = terra::time(r)), time), !duplicated(time)), idx)
debug: r <- terra::subset(r, idx)
debug: stopifnot(terra::crs(r, proj = T) == wgs84)
debug: if (mask_tif) r <- terra::mask(r, sf_zones)
debug: lyrs <- glue("{var}|{terra::time(r)}")
debug: if (length(dims_other) > 0 && !all(length(dims[dims_other]) == 
    1)) stop(glue("Other dimensions not yet supported: {paste(dims_other, collapse = ',')}"))
debug: names(r) <- lyrs
debug: if (!is.null(rast_tif)) {
    if (fs::file_exists(rast_tif)) {
        r_tmp_tif <- tempfile(fileext = ".tif")
        r_tmp <- c(rast(rast_tif), r)
        r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
        terra::writeRaster(r_tmp, r_tmp_tif)
        fs::file_delete(rast_tif)
        fs::file_move(r_tmp_tif, rast_tif)
        rm(r)
        rm(r_tmp)
    }
    else {
        terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
    }
    r <- terra::rast(rast_tif)
}
debug: if (fs::file_exists(rast_tif)) {
    r_tmp_tif <- tempfile(fileext = ".tif")
    r_tmp <- c(rast(rast_tif), r)
    r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
    terra::writeRaster(r_tmp, r_tmp_tif)
    fs::file_delete(rast_tif)
    fs::file_move(r_tmp_tif, rast_tif)
    rm(r)
    rm(r_tmp)
} else {
    terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
}
debug: terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
debug: r <- terra::rast(rast_tif)
debug: d_r <- mutate(tidyr::pivot_longer(sf::st_drop_geometry(sf::st_as_sf(terra::zonal(x = r, 
    z = terra::vect(dplyr::select(sf_zones, dplyr::all_of(fld_zones))), 
    fun = zonal_fun, exact = T, na.rm = T, as.polygons = T))), 
    cols = -dplyr::any_of(fld_zones), names_to = "lyr", values_to = zonal_fun), 
    time = readr::parse_datetime(str_replace(lyr, glue("{var}\\|(.*)"), 
        "\\1")))
debug: if (!is.null(zonal_csv)) write_csv(d_r, zonal_csv)
debug: write_csv(d_r, zonal_csv)
debug: if (!keep_nc) unlink(dir_nc, recursive = T)
debug: unlink(dir_nc, recursive = T)
debug: return(d_r)
Downloading 1 requests, up to 1388 time slices each
Called from: extractr::ed_extract(ed, var = v, sf_zones = ply, bbox = bb, 
    mask_tif = F, rast_tif = glue("{dir_out}/{nms}/{yr}.tif"), 
    zonal_fun = "mean", zonal_csv = glue("{dir_out}/{nms}/{yr}.csv"), 
    dir_nc = glue("{dir_out}/{nms}/{yr}_nc"), keep_nc = F, n_max_vals_per_req = 1e+05, 
    time_min = time_min, time_max = time_max, verbose = T)
debug: while (i_req <= n_reqs) {
    i_t_beg <- (i_req - 1) * n_t_per_req + 1
    i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
    t_req <- times_todo[c(i_t_beg, i_t_end)]
    t_req_str <- format_ISO8601(t_req, usetz = "Z")
    if (verbose) 
        message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
    ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
        ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
        0), nc)
    unlink(ncs0)
    nc_retry <- T
    nc_n_try <- 1
    n_max_retries
    while (nc_retry) {
        res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
            url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
                bbox[["xmax"]]), latitude = c(bbox[["ymin"]], 
                bbox[["ymax"]]), time = t_req_str, fmt = "nc", 
            store = rerddap::disk(path = dir_nc)))
        if (inherits(res, "try-error")) {
            err <- attr(res, "condition")
            msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
            nc_n_try <- nc_n_try + 1
            if (nc_n_try > n_max_retries) {
                stop(msg)
            }
            else {
                message(msg, "\nRETRYing...")
                Sys.sleep(1)
            }
        }
        else {
            nc_retry <- F
        }
    }
    i_req <- i_req + 1
}
debug: i_t_beg <- (i_req - 1) * n_t_per_req + 1
debug: i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
debug: t_req <- times_todo[c(i_t_beg, i_t_end)]
debug: t_req_str <- format_ISO8601(t_req, usetz = "Z")
debug: if (verbose) message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
debug: message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
Fetching request 1 of 1 (2021-01-01 to 2021-12-01) ~ 19:38:24 UTC
debug: ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
    0), nc)
debug: unlink(ncs0)
debug: nc_retry <- T
debug: nc_n_try <- 1
debug: n_max_retries
debug: while (nc_retry) {
    res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
        url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
            bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
        time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
    if (inherits(res, "try-error")) {
        err <- attr(res, "condition")
        msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
        nc_n_try <- nc_n_try + 1
        if (nc_n_try > n_max_retries) {
            stop(msg)
        }
        else {
            message(msg, "\nRETRYing...")
            Sys.sleep(1)
        }
    }
    else {
        nc_retry <- F
    }
}
debug: res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
    url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
        bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
    time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
debug: if (inherits(res, "try-error")) {
    err <- attr(res, "condition")
    msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
    nc_n_try <- nc_n_try + 1
    if (nc_n_try > n_max_retries) {
        stop(msg)
    }
    else {
        message(msg, "\nRETRYing...")
        Sys.sleep(1)
    }
} else {
    nc_retry <- F
}
debug: nc_retry <- F
debug: (while) nc_retry
debug: i_req <- i_req + 1
debug: (while) i_req <= n_reqs
debug: ncs <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size > 
    0), nc)
debug: r <- terra::rast(ncs)
debug: stopifnot(all(class(terra::time(r)) %in% c("POSIXct", "POSIXt")))
debug: idx <- dplyr::pull(dplyr::filter(dplyr::arrange(dplyr::tibble(idx = 1:terra::nlyr(r), 
    time = terra::time(r)), time), !duplicated(time)), idx)
debug: r <- terra::subset(r, idx)
debug: stopifnot(terra::crs(r, proj = T) == wgs84)
debug: if (mask_tif) r <- terra::mask(r, sf_zones)
debug: lyrs <- glue("{var}|{terra::time(r)}")
debug: if (length(dims_other) > 0 && !all(length(dims[dims_other]) == 
    1)) stop(glue("Other dimensions not yet supported: {paste(dims_other, collapse = ',')}"))
debug: names(r) <- lyrs
debug: if (!is.null(rast_tif)) {
    if (fs::file_exists(rast_tif)) {
        r_tmp_tif <- tempfile(fileext = ".tif")
        r_tmp <- c(rast(rast_tif), r)
        r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
        terra::writeRaster(r_tmp, r_tmp_tif)
        fs::file_delete(rast_tif)
        fs::file_move(r_tmp_tif, rast_tif)
        rm(r)
        rm(r_tmp)
    }
    else {
        terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
    }
    r <- terra::rast(rast_tif)
}
debug: if (fs::file_exists(rast_tif)) {
    r_tmp_tif <- tempfile(fileext = ".tif")
    r_tmp <- c(rast(rast_tif), r)
    r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
    terra::writeRaster(r_tmp, r_tmp_tif)
    fs::file_delete(rast_tif)
    fs::file_move(r_tmp_tif, rast_tif)
    rm(r)
    rm(r_tmp)
} else {
    terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
}
debug: terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
debug: r <- terra::rast(rast_tif)
debug: d_r <- mutate(tidyr::pivot_longer(sf::st_drop_geometry(sf::st_as_sf(terra::zonal(x = r, 
    z = terra::vect(dplyr::select(sf_zones, dplyr::all_of(fld_zones))), 
    fun = zonal_fun, exact = T, na.rm = T, as.polygons = T))), 
    cols = -dplyr::any_of(fld_zones), names_to = "lyr", values_to = zonal_fun), 
    time = readr::parse_datetime(str_replace(lyr, glue("{var}\\|(.*)"), 
        "\\1")))
debug: if (!is.null(zonal_csv)) write_csv(d_r, zonal_csv)
debug: write_csv(d_r, zonal_csv)
debug: if (!keep_nc) unlink(dir_nc, recursive = T)
debug: unlink(dir_nc, recursive = T)
debug: return(d_r)
Downloading 1 requests, up to 1388 time slices each
Called from: extractr::ed_extract(ed, var = v, sf_zones = ply, bbox = bb, 
    mask_tif = F, rast_tif = glue("{dir_out}/{nms}/{yr}.tif"), 
    zonal_fun = "mean", zonal_csv = glue("{dir_out}/{nms}/{yr}.csv"), 
    dir_nc = glue("{dir_out}/{nms}/{yr}_nc"), keep_nc = F, n_max_vals_per_req = 1e+05, 
    time_min = time_min, time_max = time_max, verbose = T)
debug: while (i_req <= n_reqs) {
    i_t_beg <- (i_req - 1) * n_t_per_req + 1
    i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
    t_req <- times_todo[c(i_t_beg, i_t_end)]
    t_req_str <- format_ISO8601(t_req, usetz = "Z")
    if (verbose) 
        message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
    ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
        ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
        0), nc)
    unlink(ncs0)
    nc_retry <- T
    nc_n_try <- 1
    n_max_retries
    while (nc_retry) {
        res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
            url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
                bbox[["xmax"]]), latitude = c(bbox[["ymin"]], 
                bbox[["ymax"]]), time = t_req_str, fmt = "nc", 
            store = rerddap::disk(path = dir_nc)))
        if (inherits(res, "try-error")) {
            err <- attr(res, "condition")
            msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
            nc_n_try <- nc_n_try + 1
            if (nc_n_try > n_max_retries) {
                stop(msg)
            }
            else {
                message(msg, "\nRETRYing...")
                Sys.sleep(1)
            }
        }
        else {
            nc_retry <- F
        }
    }
    i_req <- i_req + 1
}
debug: i_t_beg <- (i_req - 1) * n_t_per_req + 1
debug: i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
debug: t_req <- times_todo[c(i_t_beg, i_t_end)]
debug: t_req_str <- format_ISO8601(t_req, usetz = "Z")
debug: if (verbose) message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
debug: message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
Fetching request 1 of 1 (2022-01-01 to 2022-12-01) ~ 19:38:26 UTC
debug: ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
    0), nc)
debug: unlink(ncs0)
debug: nc_retry <- T
debug: nc_n_try <- 1
debug: n_max_retries
debug: while (nc_retry) {
    res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
        url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
            bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
        time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
    if (inherits(res, "try-error")) {
        err <- attr(res, "condition")
        msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
        nc_n_try <- nc_n_try + 1
        if (nc_n_try > n_max_retries) {
            stop(msg)
        }
        else {
            message(msg, "\nRETRYing...")
            Sys.sleep(1)
        }
    }
    else {
        nc_retry <- F
    }
}
debug: res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
    url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
        bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
    time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
debug: if (inherits(res, "try-error")) {
    err <- attr(res, "condition")
    msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
    nc_n_try <- nc_n_try + 1
    if (nc_n_try > n_max_retries) {
        stop(msg)
    }
    else {
        message(msg, "\nRETRYing...")
        Sys.sleep(1)
    }
} else {
    nc_retry <- F
}
debug: nc_retry <- F
debug: (while) nc_retry
debug: i_req <- i_req + 1
debug: (while) i_req <= n_reqs
debug: ncs <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size > 
    0), nc)
debug: r <- terra::rast(ncs)
debug: stopifnot(all(class(terra::time(r)) %in% c("POSIXct", "POSIXt")))
debug: idx <- dplyr::pull(dplyr::filter(dplyr::arrange(dplyr::tibble(idx = 1:terra::nlyr(r), 
    time = terra::time(r)), time), !duplicated(time)), idx)
debug: r <- terra::subset(r, idx)
debug: stopifnot(terra::crs(r, proj = T) == wgs84)
debug: if (mask_tif) r <- terra::mask(r, sf_zones)
debug: lyrs <- glue("{var}|{terra::time(r)}")
debug: if (length(dims_other) > 0 && !all(length(dims[dims_other]) == 
    1)) stop(glue("Other dimensions not yet supported: {paste(dims_other, collapse = ',')}"))
debug: names(r) <- lyrs
debug: if (!is.null(rast_tif)) {
    if (fs::file_exists(rast_tif)) {
        r_tmp_tif <- tempfile(fileext = ".tif")
        r_tmp <- c(rast(rast_tif), r)
        r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
        terra::writeRaster(r_tmp, r_tmp_tif)
        fs::file_delete(rast_tif)
        fs::file_move(r_tmp_tif, rast_tif)
        rm(r)
        rm(r_tmp)
    }
    else {
        terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
    }
    r <- terra::rast(rast_tif)
}
debug: if (fs::file_exists(rast_tif)) {
    r_tmp_tif <- tempfile(fileext = ".tif")
    r_tmp <- c(rast(rast_tif), r)
    r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
    terra::writeRaster(r_tmp, r_tmp_tif)
    fs::file_delete(rast_tif)
    fs::file_move(r_tmp_tif, rast_tif)
    rm(r)
    rm(r_tmp)
} else {
    terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
}
debug: terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
debug: r <- terra::rast(rast_tif)
debug: d_r <- mutate(tidyr::pivot_longer(sf::st_drop_geometry(sf::st_as_sf(terra::zonal(x = r, 
    z = terra::vect(dplyr::select(sf_zones, dplyr::all_of(fld_zones))), 
    fun = zonal_fun, exact = T, na.rm = T, as.polygons = T))), 
    cols = -dplyr::any_of(fld_zones), names_to = "lyr", values_to = zonal_fun), 
    time = readr::parse_datetime(str_replace(lyr, glue("{var}\\|(.*)"), 
        "\\1")))
debug: if (!is.null(zonal_csv)) write_csv(d_r, zonal_csv)
debug: write_csv(d_r, zonal_csv)
debug: if (!keep_nc) unlink(dir_nc, recursive = T)
debug: unlink(dir_nc, recursive = T)
debug: return(d_r)
Downloading 1 requests, up to 1388 time slices each
Called from: extractr::ed_extract(ed, var = v, sf_zones = ply, bbox = bb, 
    mask_tif = F, rast_tif = glue("{dir_out}/{nms}/{yr}.tif"), 
    zonal_fun = "mean", zonal_csv = glue("{dir_out}/{nms}/{yr}.csv"), 
    dir_nc = glue("{dir_out}/{nms}/{yr}_nc"), keep_nc = F, n_max_vals_per_req = 1e+05, 
    time_min = time_min, time_max = time_max, verbose = T)
debug: while (i_req <= n_reqs) {
    i_t_beg <- (i_req - 1) * n_t_per_req + 1
    i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
    t_req <- times_todo[c(i_t_beg, i_t_end)]
    t_req_str <- format_ISO8601(t_req, usetz = "Z")
    if (verbose) 
        message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
    ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
        ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
        0), nc)
    unlink(ncs0)
    nc_retry <- T
    nc_n_try <- 1
    n_max_retries
    while (nc_retry) {
        res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
            url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
                bbox[["xmax"]]), latitude = c(bbox[["ymin"]], 
                bbox[["ymax"]]), time = t_req_str, fmt = "nc", 
            store = rerddap::disk(path = dir_nc)))
        if (inherits(res, "try-error")) {
            err <- attr(res, "condition")
            msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
            nc_n_try <- nc_n_try + 1
            if (nc_n_try > n_max_retries) {
                stop(msg)
            }
            else {
                message(msg, "\nRETRYing...")
                Sys.sleep(1)
            }
        }
        else {
            nc_retry <- F
        }
    }
    i_req <- i_req + 1
}
debug: i_t_beg <- (i_req - 1) * n_t_per_req + 1
debug: i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
debug: t_req <- times_todo[c(i_t_beg, i_t_end)]
debug: t_req_str <- format_ISO8601(t_req, usetz = "Z")
debug: if (verbose) message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
debug: message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
Fetching request 1 of 1 (2023-01-01 to 2023-12-01) ~ 19:38:27 UTC
debug: ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
    0), nc)
debug: unlink(ncs0)
debug: nc_retry <- T
debug: nc_n_try <- 1
debug: n_max_retries
debug: while (nc_retry) {
    res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
        url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
            bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
        time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
    if (inherits(res, "try-error")) {
        err <- attr(res, "condition")
        msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
        nc_n_try <- nc_n_try + 1
        if (nc_n_try > n_max_retries) {
            stop(msg)
        }
        else {
            message(msg, "\nRETRYing...")
            Sys.sleep(1)
        }
    }
    else {
        nc_retry <- F
    }
}
debug: res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
    url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
        bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
    time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
debug: if (inherits(res, "try-error")) {
    err <- attr(res, "condition")
    msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
    nc_n_try <- nc_n_try + 1
    if (nc_n_try > n_max_retries) {
        stop(msg)
    }
    else {
        message(msg, "\nRETRYing...")
        Sys.sleep(1)
    }
} else {
    nc_retry <- F
}
debug: nc_retry <- F
debug: (while) nc_retry
debug: i_req <- i_req + 1
debug: (while) i_req <= n_reqs
debug: ncs <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size > 
    0), nc)
debug: r <- terra::rast(ncs)
debug: stopifnot(all(class(terra::time(r)) %in% c("POSIXct", "POSIXt")))
debug: idx <- dplyr::pull(dplyr::filter(dplyr::arrange(dplyr::tibble(idx = 1:terra::nlyr(r), 
    time = terra::time(r)), time), !duplicated(time)), idx)
debug: r <- terra::subset(r, idx)
debug: stopifnot(terra::crs(r, proj = T) == wgs84)
debug: if (mask_tif) r <- terra::mask(r, sf_zones)
debug: lyrs <- glue("{var}|{terra::time(r)}")
debug: if (length(dims_other) > 0 && !all(length(dims[dims_other]) == 
    1)) stop(glue("Other dimensions not yet supported: {paste(dims_other, collapse = ',')}"))
debug: names(r) <- lyrs
debug: if (!is.null(rast_tif)) {
    if (fs::file_exists(rast_tif)) {
        r_tmp_tif <- tempfile(fileext = ".tif")
        r_tmp <- c(rast(rast_tif), r)
        r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
        terra::writeRaster(r_tmp, r_tmp_tif)
        fs::file_delete(rast_tif)
        fs::file_move(r_tmp_tif, rast_tif)
        rm(r)
        rm(r_tmp)
    }
    else {
        terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
    }
    r <- terra::rast(rast_tif)
}
debug: if (fs::file_exists(rast_tif)) {
    r_tmp_tif <- tempfile(fileext = ".tif")
    r_tmp <- c(rast(rast_tif), r)
    r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
    terra::writeRaster(r_tmp, r_tmp_tif)
    fs::file_delete(rast_tif)
    fs::file_move(r_tmp_tif, rast_tif)
    rm(r)
    rm(r_tmp)
} else {
    terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
}
debug: terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
debug: r <- terra::rast(rast_tif)
debug: d_r <- mutate(tidyr::pivot_longer(sf::st_drop_geometry(sf::st_as_sf(terra::zonal(x = r, 
    z = terra::vect(dplyr::select(sf_zones, dplyr::all_of(fld_zones))), 
    fun = zonal_fun, exact = T, na.rm = T, as.polygons = T))), 
    cols = -dplyr::any_of(fld_zones), names_to = "lyr", values_to = zonal_fun), 
    time = readr::parse_datetime(str_replace(lyr, glue("{var}\\|(.*)"), 
        "\\1")))
debug: if (!is.null(zonal_csv)) write_csv(d_r, zonal_csv)
debug: write_csv(d_r, zonal_csv)
debug: if (!keep_nc) unlink(dir_nc, recursive = T)
debug: unlink(dir_nc, recursive = T)
debug: return(d_r)
Downloading 1 requests, up to 1388 time slices each
Called from: extractr::ed_extract(ed, var = v, sf_zones = ply, bbox = bb, 
    mask_tif = F, rast_tif = glue("{dir_out}/{nms}/{yr}.tif"), 
    zonal_fun = "mean", zonal_csv = glue("{dir_out}/{nms}/{yr}.csv"), 
    dir_nc = glue("{dir_out}/{nms}/{yr}_nc"), keep_nc = F, n_max_vals_per_req = 1e+05, 
    time_min = time_min, time_max = time_max, verbose = T)
debug: while (i_req <= n_reqs) {
    i_t_beg <- (i_req - 1) * n_t_per_req + 1
    i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
    t_req <- times_todo[c(i_t_beg, i_t_end)]
    t_req_str <- format_ISO8601(t_req, usetz = "Z")
    if (verbose) 
        message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
    ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
        ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
        0), nc)
    unlink(ncs0)
    nc_retry <- T
    nc_n_try <- 1
    n_max_retries
    while (nc_retry) {
        res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
            url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
                bbox[["xmax"]]), latitude = c(bbox[["ymin"]], 
                bbox[["ymax"]]), time = t_req_str, fmt = "nc", 
            store = rerddap::disk(path = dir_nc)))
        if (inherits(res, "try-error")) {
            err <- attr(res, "condition")
            msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
            nc_n_try <- nc_n_try + 1
            if (nc_n_try > n_max_retries) {
                stop(msg)
            }
            else {
                message(msg, "\nRETRYing...")
                Sys.sleep(1)
            }
        }
        else {
            nc_retry <- F
        }
    }
    i_req <- i_req + 1
}
debug: i_t_beg <- (i_req - 1) * n_t_per_req + 1
debug: i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
debug: t_req <- times_todo[c(i_t_beg, i_t_end)]
debug: t_req_str <- format_ISO8601(t_req, usetz = "Z")
debug: if (verbose) message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
debug: message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
Fetching request 1 of 1 (2024-01-01 to 2024-12-01) ~ 19:38:29 UTC
debug: ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
    0), nc)
debug: unlink(ncs0)
debug: nc_retry <- T
debug: nc_n_try <- 1
debug: n_max_retries
debug: while (nc_retry) {
    res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
        url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
            bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
        time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
    if (inherits(res, "try-error")) {
        err <- attr(res, "condition")
        msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
        nc_n_try <- nc_n_try + 1
        if (nc_n_try > n_max_retries) {
            stop(msg)
        }
        else {
            message(msg, "\nRETRYing...")
            Sys.sleep(1)
        }
    }
    else {
        nc_retry <- F
    }
}
debug: res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
    url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
        bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
    time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
debug: if (inherits(res, "try-error")) {
    err <- attr(res, "condition")
    msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
    nc_n_try <- nc_n_try + 1
    if (nc_n_try > n_max_retries) {
        stop(msg)
    }
    else {
        message(msg, "\nRETRYing...")
        Sys.sleep(1)
    }
} else {
    nc_retry <- F
}
debug: nc_retry <- F
debug: (while) nc_retry
debug: i_req <- i_req + 1
debug: (while) i_req <= n_reqs
debug: ncs <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size > 
    0), nc)
debug: r <- terra::rast(ncs)
debug: stopifnot(all(class(terra::time(r)) %in% c("POSIXct", "POSIXt")))
debug: idx <- dplyr::pull(dplyr::filter(dplyr::arrange(dplyr::tibble(idx = 1:terra::nlyr(r), 
    time = terra::time(r)), time), !duplicated(time)), idx)
debug: r <- terra::subset(r, idx)
debug: stopifnot(terra::crs(r, proj = T) == wgs84)
debug: if (mask_tif) r <- terra::mask(r, sf_zones)
debug: lyrs <- glue("{var}|{terra::time(r)}")
debug: if (length(dims_other) > 0 && !all(length(dims[dims_other]) == 
    1)) stop(glue("Other dimensions not yet supported: {paste(dims_other, collapse = ',')}"))
debug: names(r) <- lyrs
debug: if (!is.null(rast_tif)) {
    if (fs::file_exists(rast_tif)) {
        r_tmp_tif <- tempfile(fileext = ".tif")
        r_tmp <- c(rast(rast_tif), r)
        r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
        terra::writeRaster(r_tmp, r_tmp_tif)
        fs::file_delete(rast_tif)
        fs::file_move(r_tmp_tif, rast_tif)
        rm(r)
        rm(r_tmp)
    }
    else {
        terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
    }
    r <- terra::rast(rast_tif)
}
debug: if (fs::file_exists(rast_tif)) {
    r_tmp_tif <- tempfile(fileext = ".tif")
    r_tmp <- c(rast(rast_tif), r)
    r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
    terra::writeRaster(r_tmp, r_tmp_tif)
    fs::file_delete(rast_tif)
    fs::file_move(r_tmp_tif, rast_tif)
    rm(r)
    rm(r_tmp)
} else {
    terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
}
debug: terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
debug: r <- terra::rast(rast_tif)
debug: d_r <- mutate(tidyr::pivot_longer(sf::st_drop_geometry(sf::st_as_sf(terra::zonal(x = r, 
    z = terra::vect(dplyr::select(sf_zones, dplyr::all_of(fld_zones))), 
    fun = zonal_fun, exact = T, na.rm = T, as.polygons = T))), 
    cols = -dplyr::any_of(fld_zones), names_to = "lyr", values_to = zonal_fun), 
    time = readr::parse_datetime(str_replace(lyr, glue("{var}\\|(.*)"), 
        "\\1")))
debug: if (!is.null(zonal_csv)) write_csv(d_r, zonal_csv)
debug: write_csv(d_r, zonal_csv)
debug: if (!keep_nc) unlink(dir_nc, recursive = T)
debug: unlink(dir_nc, recursive = T)
debug: return(d_r)
Downloading 1 requests, up to 1388 time slices each
Called from: extractr::ed_extract(ed, var = v, sf_zones = ply, bbox = bb, 
    mask_tif = F, rast_tif = glue("{dir_out}/{nms}/{yr}.tif"), 
    zonal_fun = "mean", zonal_csv = glue("{dir_out}/{nms}/{yr}.csv"), 
    dir_nc = glue("{dir_out}/{nms}/{yr}_nc"), keep_nc = F, n_max_vals_per_req = 1e+05, 
    time_min = time_min, time_max = time_max, verbose = T)
debug: while (i_req <= n_reqs) {
    i_t_beg <- (i_req - 1) * n_t_per_req + 1
    i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
    t_req <- times_todo[c(i_t_beg, i_t_end)]
    t_req_str <- format_ISO8601(t_req, usetz = "Z")
    if (verbose) 
        message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
    ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
        ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
        0), nc)
    unlink(ncs0)
    nc_retry <- T
    nc_n_try <- 1
    n_max_retries
    while (nc_retry) {
        res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
            url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
                bbox[["xmax"]]), latitude = c(bbox[["ymin"]], 
                bbox[["ymax"]]), time = t_req_str, fmt = "nc", 
            store = rerddap::disk(path = dir_nc)))
        if (inherits(res, "try-error")) {
            err <- attr(res, "condition")
            msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
            nc_n_try <- nc_n_try + 1
            if (nc_n_try > n_max_retries) {
                stop(msg)
            }
            else {
                message(msg, "\nRETRYing...")
                Sys.sleep(1)
            }
        }
        else {
            nc_retry <- F
        }
    }
    i_req <- i_req + 1
}
debug: i_t_beg <- (i_req - 1) * n_t_per_req + 1
debug: i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
debug: t_req <- times_todo[c(i_t_beg, i_t_end)]
debug: t_req_str <- format_ISO8601(t_req, usetz = "Z")
debug: if (verbose) message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
debug: message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
Fetching request 1 of 1 (2025-01-01 to 2025-07-01) ~ 19:38:30 UTC
debug: ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
    0), nc)
debug: unlink(ncs0)
debug: nc_retry <- T
debug: nc_n_try <- 1
debug: n_max_retries
debug: while (nc_retry) {
    res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
        url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
            bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
        time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
    if (inherits(res, "try-error")) {
        err <- attr(res, "condition")
        msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
        nc_n_try <- nc_n_try + 1
        if (nc_n_try > n_max_retries) {
            stop(msg)
        }
        else {
            message(msg, "\nRETRYing...")
            Sys.sleep(1)
        }
    }
    else {
        nc_retry <- F
    }
}
debug: res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
    url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
        bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
    time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
debug: if (inherits(res, "try-error")) {
    err <- attr(res, "condition")
    msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
    nc_n_try <- nc_n_try + 1
    if (nc_n_try > n_max_retries) {
        stop(msg)
    }
    else {
        message(msg, "\nRETRYing...")
        Sys.sleep(1)
    }
} else {
    nc_retry <- F
}
debug: nc_retry <- F
debug: (while) nc_retry
debug: i_req <- i_req + 1
debug: (while) i_req <= n_reqs
debug: ncs <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size > 
    0), nc)
debug: r <- terra::rast(ncs)
debug: stopifnot(all(class(terra::time(r)) %in% c("POSIXct", "POSIXt")))
debug: idx <- dplyr::pull(dplyr::filter(dplyr::arrange(dplyr::tibble(idx = 1:terra::nlyr(r), 
    time = terra::time(r)), time), !duplicated(time)), idx)
debug: r <- terra::subset(r, idx)
debug: stopifnot(terra::crs(r, proj = T) == wgs84)
debug: if (mask_tif) r <- terra::mask(r, sf_zones)
debug: lyrs <- glue("{var}|{terra::time(r)}")
debug: if (length(dims_other) > 0 && !all(length(dims[dims_other]) == 
    1)) stop(glue("Other dimensions not yet supported: {paste(dims_other, collapse = ',')}"))
debug: names(r) <- lyrs
debug: if (!is.null(rast_tif)) {
    if (fs::file_exists(rast_tif)) {
        r_tmp_tif <- tempfile(fileext = ".tif")
        r_tmp <- c(rast(rast_tif), r)
        r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
        terra::writeRaster(r_tmp, r_tmp_tif)
        fs::file_delete(rast_tif)
        fs::file_move(r_tmp_tif, rast_tif)
        rm(r)
        rm(r_tmp)
    }
    else {
        terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
    }
    r <- terra::rast(rast_tif)
}
debug: if (fs::file_exists(rast_tif)) {
    r_tmp_tif <- tempfile(fileext = ".tif")
    r_tmp <- c(rast(rast_tif), r)
    r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
    terra::writeRaster(r_tmp, r_tmp_tif)
    fs::file_delete(rast_tif)
    fs::file_move(r_tmp_tif, rast_tif)
    rm(r)
    rm(r_tmp)
} else {
    terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
}
debug: terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
debug: r <- terra::rast(rast_tif)
debug: d_r <- mutate(tidyr::pivot_longer(sf::st_drop_geometry(sf::st_as_sf(terra::zonal(x = r, 
    z = terra::vect(dplyr::select(sf_zones, dplyr::all_of(fld_zones))), 
    fun = zonal_fun, exact = T, na.rm = T, as.polygons = T))), 
    cols = -dplyr::any_of(fld_zones), names_to = "lyr", values_to = zonal_fun), 
    time = readr::parse_datetime(str_replace(lyr, glue("{var}\\|(.*)"), 
        "\\1")))
debug: if (!is.null(zonal_csv)) write_csv(d_r, zonal_csv)
debug: write_csv(d_r, zonal_csv)
debug: if (!keep_nc) unlink(dir_nc, recursive = T)
debug: unlink(dir_nc, recursive = T)
debug: return(d_r)
Downloading 1 requests, up to 67 time slices each
Called from: extractr::ed_extract(ed, var = v, sf_zones = ply, bbox = bb, 
    mask_tif = F, rast_tif = glue("{dir_out}/{nms}/{yr}.tif"), 
    zonal_fun = "mean", zonal_csv = glue("{dir_out}/{nms}/{yr}.csv"), 
    dir_nc = glue("{dir_out}/{nms}/{yr}_nc"), keep_nc = F, n_max_vals_per_req = 1e+05, 
    time_min = time_min, time_max = time_max, verbose = T)
debug: while (i_req <= n_reqs) {
    i_t_beg <- (i_req - 1) * n_t_per_req + 1
    i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
    t_req <- times_todo[c(i_t_beg, i_t_end)]
    t_req_str <- format_ISO8601(t_req, usetz = "Z")
    if (verbose) 
        message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
    ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
        ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
        0), nc)
    unlink(ncs0)
    nc_retry <- T
    nc_n_try <- 1
    n_max_retries
    while (nc_retry) {
        res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
            url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
                bbox[["xmax"]]), latitude = c(bbox[["ymin"]], 
                bbox[["ymax"]]), time = t_req_str, fmt = "nc", 
            store = rerddap::disk(path = dir_nc)))
        if (inherits(res, "try-error")) {
            err <- attr(res, "condition")
            msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
            nc_n_try <- nc_n_try + 1
            if (nc_n_try > n_max_retries) {
                stop(msg)
            }
            else {
                message(msg, "\nRETRYing...")
                Sys.sleep(1)
            }
        }
        else {
            nc_retry <- F
        }
    }
    i_req <- i_req + 1
}
debug: i_t_beg <- (i_req - 1) * n_t_per_req + 1
debug: i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
debug: t_req <- times_todo[c(i_t_beg, i_t_end)]
debug: t_req_str <- format_ISO8601(t_req, usetz = "Z")
debug: if (verbose) message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
debug: message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
Fetching request 1 of 1 (1998-01-01 to 1998-12-01) ~ 19:38:32 UTC
debug: ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
    0), nc)
debug: unlink(ncs0)
debug: nc_retry <- T
debug: nc_n_try <- 1
debug: n_max_retries
debug: while (nc_retry) {
    res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
        url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
            bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
        time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
    if (inherits(res, "try-error")) {
        err <- attr(res, "condition")
        msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
        nc_n_try <- nc_n_try + 1
        if (nc_n_try > n_max_retries) {
            stop(msg)
        }
        else {
            message(msg, "\nRETRYing...")
            Sys.sleep(1)
        }
    }
    else {
        nc_retry <- F
    }
}
debug: res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
    url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
        bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
    time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
debug: if (inherits(res, "try-error")) {
    err <- attr(res, "condition")
    msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
    nc_n_try <- nc_n_try + 1
    if (nc_n_try > n_max_retries) {
        stop(msg)
    }
    else {
        message(msg, "\nRETRYing...")
        Sys.sleep(1)
    }
} else {
    nc_retry <- F
}
debug: nc_retry <- F
debug: (while) nc_retry
debug: i_req <- i_req + 1
debug: (while) i_req <= n_reqs
debug: ncs <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size > 
    0), nc)
debug: r <- terra::rast(ncs)
debug: stopifnot(all(class(terra::time(r)) %in% c("POSIXct", "POSIXt")))
debug: idx <- dplyr::pull(dplyr::filter(dplyr::arrange(dplyr::tibble(idx = 1:terra::nlyr(r), 
    time = terra::time(r)), time), !duplicated(time)), idx)
debug: r <- terra::subset(r, idx)
debug: stopifnot(terra::crs(r, proj = T) == wgs84)
debug: if (mask_tif) r <- terra::mask(r, sf_zones)
debug: lyrs <- glue("{var}|{terra::time(r)}")
debug: if (length(dims_other) > 0 && !all(length(dims[dims_other]) == 
    1)) stop(glue("Other dimensions not yet supported: {paste(dims_other, collapse = ',')}"))
debug: names(r) <- lyrs
debug: if (!is.null(rast_tif)) {
    if (fs::file_exists(rast_tif)) {
        r_tmp_tif <- tempfile(fileext = ".tif")
        r_tmp <- c(rast(rast_tif), r)
        r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
        terra::writeRaster(r_tmp, r_tmp_tif)
        fs::file_delete(rast_tif)
        fs::file_move(r_tmp_tif, rast_tif)
        rm(r)
        rm(r_tmp)
    }
    else {
        terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
    }
    r <- terra::rast(rast_tif)
}
debug: if (fs::file_exists(rast_tif)) {
    r_tmp_tif <- tempfile(fileext = ".tif")
    r_tmp <- c(rast(rast_tif), r)
    r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
    terra::writeRaster(r_tmp, r_tmp_tif)
    fs::file_delete(rast_tif)
    fs::file_move(r_tmp_tif, rast_tif)
    rm(r)
    rm(r_tmp)
} else {
    terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
}
debug: terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
debug: r <- terra::rast(rast_tif)
debug: d_r <- mutate(tidyr::pivot_longer(sf::st_drop_geometry(sf::st_as_sf(terra::zonal(x = r, 
    z = terra::vect(dplyr::select(sf_zones, dplyr::all_of(fld_zones))), 
    fun = zonal_fun, exact = T, na.rm = T, as.polygons = T))), 
    cols = -dplyr::any_of(fld_zones), names_to = "lyr", values_to = zonal_fun), 
    time = readr::parse_datetime(str_replace(lyr, glue("{var}\\|(.*)"), 
        "\\1")))
debug: if (!is.null(zonal_csv)) write_csv(d_r, zonal_csv)
debug: write_csv(d_r, zonal_csv)
debug: if (!keep_nc) unlink(dir_nc, recursive = T)
debug: unlink(dir_nc, recursive = T)
debug: return(d_r)
Downloading 1 requests, up to 67 time slices each
Called from: extractr::ed_extract(ed, var = v, sf_zones = ply, bbox = bb, 
    mask_tif = F, rast_tif = glue("{dir_out}/{nms}/{yr}.tif"), 
    zonal_fun = "mean", zonal_csv = glue("{dir_out}/{nms}/{yr}.csv"), 
    dir_nc = glue("{dir_out}/{nms}/{yr}_nc"), keep_nc = F, n_max_vals_per_req = 1e+05, 
    time_min = time_min, time_max = time_max, verbose = T)
debug: while (i_req <= n_reqs) {
    i_t_beg <- (i_req - 1) * n_t_per_req + 1
    i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
    t_req <- times_todo[c(i_t_beg, i_t_end)]
    t_req_str <- format_ISO8601(t_req, usetz = "Z")
    if (verbose) 
        message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
    ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
        ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
        0), nc)
    unlink(ncs0)
    nc_retry <- T
    nc_n_try <- 1
    n_max_retries
    while (nc_retry) {
        res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
            url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
                bbox[["xmax"]]), latitude = c(bbox[["ymin"]], 
                bbox[["ymax"]]), time = t_req_str, fmt = "nc", 
            store = rerddap::disk(path = dir_nc)))
        if (inherits(res, "try-error")) {
            err <- attr(res, "condition")
            msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
            nc_n_try <- nc_n_try + 1
            if (nc_n_try > n_max_retries) {
                stop(msg)
            }
            else {
                message(msg, "\nRETRYing...")
                Sys.sleep(1)
            }
        }
        else {
            nc_retry <- F
        }
    }
    i_req <- i_req + 1
}
debug: i_t_beg <- (i_req - 1) * n_t_per_req + 1
debug: i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
debug: t_req <- times_todo[c(i_t_beg, i_t_end)]
debug: t_req_str <- format_ISO8601(t_req, usetz = "Z")
debug: if (verbose) message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
debug: message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
Fetching request 1 of 1 (1999-01-01 to 1999-12-01) ~ 19:38:34 UTC
debug: ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
    0), nc)
debug: unlink(ncs0)
debug: nc_retry <- T
debug: nc_n_try <- 1
debug: n_max_retries
debug: while (nc_retry) {
    res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
        url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
            bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
        time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
    if (inherits(res, "try-error")) {
        err <- attr(res, "condition")
        msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
        nc_n_try <- nc_n_try + 1
        if (nc_n_try > n_max_retries) {
            stop(msg)
        }
        else {
            message(msg, "\nRETRYing...")
            Sys.sleep(1)
        }
    }
    else {
        nc_retry <- F
    }
}
debug: res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
    url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
        bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
    time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
debug: if (inherits(res, "try-error")) {
    err <- attr(res, "condition")
    msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
    nc_n_try <- nc_n_try + 1
    if (nc_n_try > n_max_retries) {
        stop(msg)
    }
    else {
        message(msg, "\nRETRYing...")
        Sys.sleep(1)
    }
} else {
    nc_retry <- F
}
debug: nc_retry <- F
debug: (while) nc_retry
debug: i_req <- i_req + 1
debug: (while) i_req <= n_reqs
debug: ncs <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size > 
    0), nc)
debug: r <- terra::rast(ncs)
debug: stopifnot(all(class(terra::time(r)) %in% c("POSIXct", "POSIXt")))
debug: idx <- dplyr::pull(dplyr::filter(dplyr::arrange(dplyr::tibble(idx = 1:terra::nlyr(r), 
    time = terra::time(r)), time), !duplicated(time)), idx)
debug: r <- terra::subset(r, idx)
debug: stopifnot(terra::crs(r, proj = T) == wgs84)
debug: if (mask_tif) r <- terra::mask(r, sf_zones)
debug: lyrs <- glue("{var}|{terra::time(r)}")
debug: if (length(dims_other) > 0 && !all(length(dims[dims_other]) == 
    1)) stop(glue("Other dimensions not yet supported: {paste(dims_other, collapse = ',')}"))
debug: names(r) <- lyrs
debug: if (!is.null(rast_tif)) {
    if (fs::file_exists(rast_tif)) {
        r_tmp_tif <- tempfile(fileext = ".tif")
        r_tmp <- c(rast(rast_tif), r)
        r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
        terra::writeRaster(r_tmp, r_tmp_tif)
        fs::file_delete(rast_tif)
        fs::file_move(r_tmp_tif, rast_tif)
        rm(r)
        rm(r_tmp)
    }
    else {
        terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
    }
    r <- terra::rast(rast_tif)
}
debug: if (fs::file_exists(rast_tif)) {
    r_tmp_tif <- tempfile(fileext = ".tif")
    r_tmp <- c(rast(rast_tif), r)
    r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
    terra::writeRaster(r_tmp, r_tmp_tif)
    fs::file_delete(rast_tif)
    fs::file_move(r_tmp_tif, rast_tif)
    rm(r)
    rm(r_tmp)
} else {
    terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
}
debug: terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
debug: r <- terra::rast(rast_tif)
debug: d_r <- mutate(tidyr::pivot_longer(sf::st_drop_geometry(sf::st_as_sf(terra::zonal(x = r, 
    z = terra::vect(dplyr::select(sf_zones, dplyr::all_of(fld_zones))), 
    fun = zonal_fun, exact = T, na.rm = T, as.polygons = T))), 
    cols = -dplyr::any_of(fld_zones), names_to = "lyr", values_to = zonal_fun), 
    time = readr::parse_datetime(str_replace(lyr, glue("{var}\\|(.*)"), 
        "\\1")))
debug: if (!is.null(zonal_csv)) write_csv(d_r, zonal_csv)
debug: write_csv(d_r, zonal_csv)
debug: if (!keep_nc) unlink(dir_nc, recursive = T)
debug: unlink(dir_nc, recursive = T)
debug: return(d_r)
Downloading 1 requests, up to 67 time slices each
Called from: extractr::ed_extract(ed, var = v, sf_zones = ply, bbox = bb, 
    mask_tif = F, rast_tif = glue("{dir_out}/{nms}/{yr}.tif"), 
    zonal_fun = "mean", zonal_csv = glue("{dir_out}/{nms}/{yr}.csv"), 
    dir_nc = glue("{dir_out}/{nms}/{yr}_nc"), keep_nc = F, n_max_vals_per_req = 1e+05, 
    time_min = time_min, time_max = time_max, verbose = T)
debug: while (i_req <= n_reqs) {
    i_t_beg <- (i_req - 1) * n_t_per_req + 1
    i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
    t_req <- times_todo[c(i_t_beg, i_t_end)]
    t_req_str <- format_ISO8601(t_req, usetz = "Z")
    if (verbose) 
        message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
    ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
        ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
        0), nc)
    unlink(ncs0)
    nc_retry <- T
    nc_n_try <- 1
    n_max_retries
    while (nc_retry) {
        res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
            url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
                bbox[["xmax"]]), latitude = c(bbox[["ymin"]], 
                bbox[["ymax"]]), time = t_req_str, fmt = "nc", 
            store = rerddap::disk(path = dir_nc)))
        if (inherits(res, "try-error")) {
            err <- attr(res, "condition")
            msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
            nc_n_try <- nc_n_try + 1
            if (nc_n_try > n_max_retries) {
                stop(msg)
            }
            else {
                message(msg, "\nRETRYing...")
                Sys.sleep(1)
            }
        }
        else {
            nc_retry <- F
        }
    }
    i_req <- i_req + 1
}
debug: i_t_beg <- (i_req - 1) * n_t_per_req + 1
debug: i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
debug: t_req <- times_todo[c(i_t_beg, i_t_end)]
debug: t_req_str <- format_ISO8601(t_req, usetz = "Z")
debug: if (verbose) message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
debug: message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
Fetching request 1 of 1 (2000-01-01 to 2000-12-01) ~ 19:38:37 UTC
debug: ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
    0), nc)
debug: unlink(ncs0)
debug: nc_retry <- T
debug: nc_n_try <- 1
debug: n_max_retries
debug: while (nc_retry) {
    res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
        url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
            bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
        time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
    if (inherits(res, "try-error")) {
        err <- attr(res, "condition")
        msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
        nc_n_try <- nc_n_try + 1
        if (nc_n_try > n_max_retries) {
            stop(msg)
        }
        else {
            message(msg, "\nRETRYing...")
            Sys.sleep(1)
        }
    }
    else {
        nc_retry <- F
    }
}
debug: res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
    url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
        bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
    time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
debug: if (inherits(res, "try-error")) {
    err <- attr(res, "condition")
    msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
    nc_n_try <- nc_n_try + 1
    if (nc_n_try > n_max_retries) {
        stop(msg)
    }
    else {
        message(msg, "\nRETRYing...")
        Sys.sleep(1)
    }
} else {
    nc_retry <- F
}
debug: nc_retry <- F
debug: (while) nc_retry
debug: i_req <- i_req + 1
debug: (while) i_req <= n_reqs
debug: ncs <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size > 
    0), nc)
debug: r <- terra::rast(ncs)
debug: stopifnot(all(class(terra::time(r)) %in% c("POSIXct", "POSIXt")))
debug: idx <- dplyr::pull(dplyr::filter(dplyr::arrange(dplyr::tibble(idx = 1:terra::nlyr(r), 
    time = terra::time(r)), time), !duplicated(time)), idx)
debug: r <- terra::subset(r, idx)
debug: stopifnot(terra::crs(r, proj = T) == wgs84)
debug: if (mask_tif) r <- terra::mask(r, sf_zones)
debug: lyrs <- glue("{var}|{terra::time(r)}")
debug: if (length(dims_other) > 0 && !all(length(dims[dims_other]) == 
    1)) stop(glue("Other dimensions not yet supported: {paste(dims_other, collapse = ',')}"))
debug: names(r) <- lyrs
debug: if (!is.null(rast_tif)) {
    if (fs::file_exists(rast_tif)) {
        r_tmp_tif <- tempfile(fileext = ".tif")
        r_tmp <- c(rast(rast_tif), r)
        r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
        terra::writeRaster(r_tmp, r_tmp_tif)
        fs::file_delete(rast_tif)
        fs::file_move(r_tmp_tif, rast_tif)
        rm(r)
        rm(r_tmp)
    }
    else {
        terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
    }
    r <- terra::rast(rast_tif)
}
debug: if (fs::file_exists(rast_tif)) {
    r_tmp_tif <- tempfile(fileext = ".tif")
    r_tmp <- c(rast(rast_tif), r)
    r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
    terra::writeRaster(r_tmp, r_tmp_tif)
    fs::file_delete(rast_tif)
    fs::file_move(r_tmp_tif, rast_tif)
    rm(r)
    rm(r_tmp)
} else {
    terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
}
debug: terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
debug: r <- terra::rast(rast_tif)
debug: d_r <- mutate(tidyr::pivot_longer(sf::st_drop_geometry(sf::st_as_sf(terra::zonal(x = r, 
    z = terra::vect(dplyr::select(sf_zones, dplyr::all_of(fld_zones))), 
    fun = zonal_fun, exact = T, na.rm = T, as.polygons = T))), 
    cols = -dplyr::any_of(fld_zones), names_to = "lyr", values_to = zonal_fun), 
    time = readr::parse_datetime(str_replace(lyr, glue("{var}\\|(.*)"), 
        "\\1")))
debug: if (!is.null(zonal_csv)) write_csv(d_r, zonal_csv)
debug: write_csv(d_r, zonal_csv)
debug: if (!keep_nc) unlink(dir_nc, recursive = T)
debug: unlink(dir_nc, recursive = T)
debug: return(d_r)
Downloading 1 requests, up to 67 time slices each
Called from: extractr::ed_extract(ed, var = v, sf_zones = ply, bbox = bb, 
    mask_tif = F, rast_tif = glue("{dir_out}/{nms}/{yr}.tif"), 
    zonal_fun = "mean", zonal_csv = glue("{dir_out}/{nms}/{yr}.csv"), 
    dir_nc = glue("{dir_out}/{nms}/{yr}_nc"), keep_nc = F, n_max_vals_per_req = 1e+05, 
    time_min = time_min, time_max = time_max, verbose = T)
debug: while (i_req <= n_reqs) {
    i_t_beg <- (i_req - 1) * n_t_per_req + 1
    i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
    t_req <- times_todo[c(i_t_beg, i_t_end)]
    t_req_str <- format_ISO8601(t_req, usetz = "Z")
    if (verbose) 
        message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
    ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
        ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
        0), nc)
    unlink(ncs0)
    nc_retry <- T
    nc_n_try <- 1
    n_max_retries
    while (nc_retry) {
        res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
            url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
                bbox[["xmax"]]), latitude = c(bbox[["ymin"]], 
                bbox[["ymax"]]), time = t_req_str, fmt = "nc", 
            store = rerddap::disk(path = dir_nc)))
        if (inherits(res, "try-error")) {
            err <- attr(res, "condition")
            msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
            nc_n_try <- nc_n_try + 1
            if (nc_n_try > n_max_retries) {
                stop(msg)
            }
            else {
                message(msg, "\nRETRYing...")
                Sys.sleep(1)
            }
        }
        else {
            nc_retry <- F
        }
    }
    i_req <- i_req + 1
}
debug: i_t_beg <- (i_req - 1) * n_t_per_req + 1
debug: i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
debug: t_req <- times_todo[c(i_t_beg, i_t_end)]
debug: t_req_str <- format_ISO8601(t_req, usetz = "Z")
debug: if (verbose) message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
debug: message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
Fetching request 1 of 1 (2001-01-01 to 2001-12-01) ~ 19:38:39 UTC
debug: ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
    0), nc)
debug: unlink(ncs0)
debug: nc_retry <- T
debug: nc_n_try <- 1
debug: n_max_retries
debug: while (nc_retry) {
    res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
        url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
            bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
        time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
    if (inherits(res, "try-error")) {
        err <- attr(res, "condition")
        msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
        nc_n_try <- nc_n_try + 1
        if (nc_n_try > n_max_retries) {
            stop(msg)
        }
        else {
            message(msg, "\nRETRYing...")
            Sys.sleep(1)
        }
    }
    else {
        nc_retry <- F
    }
}
debug: res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
    url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
        bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
    time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
debug: if (inherits(res, "try-error")) {
    err <- attr(res, "condition")
    msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
    nc_n_try <- nc_n_try + 1
    if (nc_n_try > n_max_retries) {
        stop(msg)
    }
    else {
        message(msg, "\nRETRYing...")
        Sys.sleep(1)
    }
} else {
    nc_retry <- F
}
debug: nc_retry <- F
debug: (while) nc_retry
debug: i_req <- i_req + 1
debug: (while) i_req <= n_reqs
debug: ncs <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size > 
    0), nc)
debug: r <- terra::rast(ncs)
debug: stopifnot(all(class(terra::time(r)) %in% c("POSIXct", "POSIXt")))
debug: idx <- dplyr::pull(dplyr::filter(dplyr::arrange(dplyr::tibble(idx = 1:terra::nlyr(r), 
    time = terra::time(r)), time), !duplicated(time)), idx)
debug: r <- terra::subset(r, idx)
debug: stopifnot(terra::crs(r, proj = T) == wgs84)
debug: if (mask_tif) r <- terra::mask(r, sf_zones)
debug: lyrs <- glue("{var}|{terra::time(r)}")
debug: if (length(dims_other) > 0 && !all(length(dims[dims_other]) == 
    1)) stop(glue("Other dimensions not yet supported: {paste(dims_other, collapse = ',')}"))
debug: names(r) <- lyrs
debug: if (!is.null(rast_tif)) {
    if (fs::file_exists(rast_tif)) {
        r_tmp_tif <- tempfile(fileext = ".tif")
        r_tmp <- c(rast(rast_tif), r)
        r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
        terra::writeRaster(r_tmp, r_tmp_tif)
        fs::file_delete(rast_tif)
        fs::file_move(r_tmp_tif, rast_tif)
        rm(r)
        rm(r_tmp)
    }
    else {
        terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
    }
    r <- terra::rast(rast_tif)
}
debug: if (fs::file_exists(rast_tif)) {
    r_tmp_tif <- tempfile(fileext = ".tif")
    r_tmp <- c(rast(rast_tif), r)
    r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
    terra::writeRaster(r_tmp, r_tmp_tif)
    fs::file_delete(rast_tif)
    fs::file_move(r_tmp_tif, rast_tif)
    rm(r)
    rm(r_tmp)
} else {
    terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
}
debug: terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
debug: r <- terra::rast(rast_tif)
debug: d_r <- mutate(tidyr::pivot_longer(sf::st_drop_geometry(sf::st_as_sf(terra::zonal(x = r, 
    z = terra::vect(dplyr::select(sf_zones, dplyr::all_of(fld_zones))), 
    fun = zonal_fun, exact = T, na.rm = T, as.polygons = T))), 
    cols = -dplyr::any_of(fld_zones), names_to = "lyr", values_to = zonal_fun), 
    time = readr::parse_datetime(str_replace(lyr, glue("{var}\\|(.*)"), 
        "\\1")))
debug: if (!is.null(zonal_csv)) write_csv(d_r, zonal_csv)
debug: write_csv(d_r, zonal_csv)
debug: if (!keep_nc) unlink(dir_nc, recursive = T)
debug: unlink(dir_nc, recursive = T)
debug: return(d_r)
Downloading 1 requests, up to 67 time slices each
Called from: extractr::ed_extract(ed, var = v, sf_zones = ply, bbox = bb, 
    mask_tif = F, rast_tif = glue("{dir_out}/{nms}/{yr}.tif"), 
    zonal_fun = "mean", zonal_csv = glue("{dir_out}/{nms}/{yr}.csv"), 
    dir_nc = glue("{dir_out}/{nms}/{yr}_nc"), keep_nc = F, n_max_vals_per_req = 1e+05, 
    time_min = time_min, time_max = time_max, verbose = T)
debug: while (i_req <= n_reqs) {
    i_t_beg <- (i_req - 1) * n_t_per_req + 1
    i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
    t_req <- times_todo[c(i_t_beg, i_t_end)]
    t_req_str <- format_ISO8601(t_req, usetz = "Z")
    if (verbose) 
        message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
    ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
        ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
        0), nc)
    unlink(ncs0)
    nc_retry <- T
    nc_n_try <- 1
    n_max_retries
    while (nc_retry) {
        res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
            url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
                bbox[["xmax"]]), latitude = c(bbox[["ymin"]], 
                bbox[["ymax"]]), time = t_req_str, fmt = "nc", 
            store = rerddap::disk(path = dir_nc)))
        if (inherits(res, "try-error")) {
            err <- attr(res, "condition")
            msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
            nc_n_try <- nc_n_try + 1
            if (nc_n_try > n_max_retries) {
                stop(msg)
            }
            else {
                message(msg, "\nRETRYing...")
                Sys.sleep(1)
            }
        }
        else {
            nc_retry <- F
        }
    }
    i_req <- i_req + 1
}
debug: i_t_beg <- (i_req - 1) * n_t_per_req + 1
debug: i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
debug: t_req <- times_todo[c(i_t_beg, i_t_end)]
debug: t_req_str <- format_ISO8601(t_req, usetz = "Z")
debug: if (verbose) message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
debug: message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
Fetching request 1 of 1 (2002-01-01 to 2002-12-01) ~ 19:38:41 UTC
debug: ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
    0), nc)
debug: unlink(ncs0)
debug: nc_retry <- T
debug: nc_n_try <- 1
debug: n_max_retries
debug: while (nc_retry) {
    res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
        url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
            bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
        time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
    if (inherits(res, "try-error")) {
        err <- attr(res, "condition")
        msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
        nc_n_try <- nc_n_try + 1
        if (nc_n_try > n_max_retries) {
            stop(msg)
        }
        else {
            message(msg, "\nRETRYing...")
            Sys.sleep(1)
        }
    }
    else {
        nc_retry <- F
    }
}
debug: res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
    url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
        bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
    time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
debug: if (inherits(res, "try-error")) {
    err <- attr(res, "condition")
    msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
    nc_n_try <- nc_n_try + 1
    if (nc_n_try > n_max_retries) {
        stop(msg)
    }
    else {
        message(msg, "\nRETRYing...")
        Sys.sleep(1)
    }
} else {
    nc_retry <- F
}
debug: nc_retry <- F
debug: (while) nc_retry
debug: i_req <- i_req + 1
debug: (while) i_req <= n_reqs
debug: ncs <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size > 
    0), nc)
debug: r <- terra::rast(ncs)
debug: stopifnot(all(class(terra::time(r)) %in% c("POSIXct", "POSIXt")))
debug: idx <- dplyr::pull(dplyr::filter(dplyr::arrange(dplyr::tibble(idx = 1:terra::nlyr(r), 
    time = terra::time(r)), time), !duplicated(time)), idx)
debug: r <- terra::subset(r, idx)
debug: stopifnot(terra::crs(r, proj = T) == wgs84)
debug: if (mask_tif) r <- terra::mask(r, sf_zones)
debug: lyrs <- glue("{var}|{terra::time(r)}")
debug: if (length(dims_other) > 0 && !all(length(dims[dims_other]) == 
    1)) stop(glue("Other dimensions not yet supported: {paste(dims_other, collapse = ',')}"))
debug: names(r) <- lyrs
debug: if (!is.null(rast_tif)) {
    if (fs::file_exists(rast_tif)) {
        r_tmp_tif <- tempfile(fileext = ".tif")
        r_tmp <- c(rast(rast_tif), r)
        r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
        terra::writeRaster(r_tmp, r_tmp_tif)
        fs::file_delete(rast_tif)
        fs::file_move(r_tmp_tif, rast_tif)
        rm(r)
        rm(r_tmp)
    }
    else {
        terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
    }
    r <- terra::rast(rast_tif)
}
debug: if (fs::file_exists(rast_tif)) {
    r_tmp_tif <- tempfile(fileext = ".tif")
    r_tmp <- c(rast(rast_tif), r)
    r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
    terra::writeRaster(r_tmp, r_tmp_tif)
    fs::file_delete(rast_tif)
    fs::file_move(r_tmp_tif, rast_tif)
    rm(r)
    rm(r_tmp)
} else {
    terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
}
debug: terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
debug: r <- terra::rast(rast_tif)
debug: d_r <- mutate(tidyr::pivot_longer(sf::st_drop_geometry(sf::st_as_sf(terra::zonal(x = r, 
    z = terra::vect(dplyr::select(sf_zones, dplyr::all_of(fld_zones))), 
    fun = zonal_fun, exact = T, na.rm = T, as.polygons = T))), 
    cols = -dplyr::any_of(fld_zones), names_to = "lyr", values_to = zonal_fun), 
    time = readr::parse_datetime(str_replace(lyr, glue("{var}\\|(.*)"), 
        "\\1")))
debug: if (!is.null(zonal_csv)) write_csv(d_r, zonal_csv)
debug: write_csv(d_r, zonal_csv)
debug: if (!keep_nc) unlink(dir_nc, recursive = T)
debug: unlink(dir_nc, recursive = T)
debug: return(d_r)
Downloading 1 requests, up to 67 time slices each
Called from: extractr::ed_extract(ed, var = v, sf_zones = ply, bbox = bb, 
    mask_tif = F, rast_tif = glue("{dir_out}/{nms}/{yr}.tif"), 
    zonal_fun = "mean", zonal_csv = glue("{dir_out}/{nms}/{yr}.csv"), 
    dir_nc = glue("{dir_out}/{nms}/{yr}_nc"), keep_nc = F, n_max_vals_per_req = 1e+05, 
    time_min = time_min, time_max = time_max, verbose = T)
debug: while (i_req <= n_reqs) {
    i_t_beg <- (i_req - 1) * n_t_per_req + 1
    i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
    t_req <- times_todo[c(i_t_beg, i_t_end)]
    t_req_str <- format_ISO8601(t_req, usetz = "Z")
    if (verbose) 
        message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
    ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
        ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
        0), nc)
    unlink(ncs0)
    nc_retry <- T
    nc_n_try <- 1
    n_max_retries
    while (nc_retry) {
        res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
            url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
                bbox[["xmax"]]), latitude = c(bbox[["ymin"]], 
                bbox[["ymax"]]), time = t_req_str, fmt = "nc", 
            store = rerddap::disk(path = dir_nc)))
        if (inherits(res, "try-error")) {
            err <- attr(res, "condition")
            msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
            nc_n_try <- nc_n_try + 1
            if (nc_n_try > n_max_retries) {
                stop(msg)
            }
            else {
                message(msg, "\nRETRYing...")
                Sys.sleep(1)
            }
        }
        else {
            nc_retry <- F
        }
    }
    i_req <- i_req + 1
}
debug: i_t_beg <- (i_req - 1) * n_t_per_req + 1
debug: i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
debug: t_req <- times_todo[c(i_t_beg, i_t_end)]
debug: t_req_str <- format_ISO8601(t_req, usetz = "Z")
debug: if (verbose) message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
debug: message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
Fetching request 1 of 1 (2003-01-01 to 2003-12-01) ~ 19:38:43 UTC
debug: ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
    0), nc)
debug: unlink(ncs0)
debug: nc_retry <- T
debug: nc_n_try <- 1
debug: n_max_retries
debug: while (nc_retry) {
    res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
        url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
            bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
        time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
    if (inherits(res, "try-error")) {
        err <- attr(res, "condition")
        msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
        nc_n_try <- nc_n_try + 1
        if (nc_n_try > n_max_retries) {
            stop(msg)
        }
        else {
            message(msg, "\nRETRYing...")
            Sys.sleep(1)
        }
    }
    else {
        nc_retry <- F
    }
}
debug: res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
    url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
        bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
    time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
debug: if (inherits(res, "try-error")) {
    err <- attr(res, "condition")
    msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
    nc_n_try <- nc_n_try + 1
    if (nc_n_try > n_max_retries) {
        stop(msg)
    }
    else {
        message(msg, "\nRETRYing...")
        Sys.sleep(1)
    }
} else {
    nc_retry <- F
}
debug: nc_retry <- F
debug: (while) nc_retry
debug: i_req <- i_req + 1
debug: (while) i_req <= n_reqs
debug: ncs <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size > 
    0), nc)
debug: r <- terra::rast(ncs)
debug: stopifnot(all(class(terra::time(r)) %in% c("POSIXct", "POSIXt")))
debug: idx <- dplyr::pull(dplyr::filter(dplyr::arrange(dplyr::tibble(idx = 1:terra::nlyr(r), 
    time = terra::time(r)), time), !duplicated(time)), idx)
debug: r <- terra::subset(r, idx)
debug: stopifnot(terra::crs(r, proj = T) == wgs84)
debug: if (mask_tif) r <- terra::mask(r, sf_zones)
debug: lyrs <- glue("{var}|{terra::time(r)}")
debug: if (length(dims_other) > 0 && !all(length(dims[dims_other]) == 
    1)) stop(glue("Other dimensions not yet supported: {paste(dims_other, collapse = ',')}"))
debug: names(r) <- lyrs
debug: if (!is.null(rast_tif)) {
    if (fs::file_exists(rast_tif)) {
        r_tmp_tif <- tempfile(fileext = ".tif")
        r_tmp <- c(rast(rast_tif), r)
        r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
        terra::writeRaster(r_tmp, r_tmp_tif)
        fs::file_delete(rast_tif)
        fs::file_move(r_tmp_tif, rast_tif)
        rm(r)
        rm(r_tmp)
    }
    else {
        terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
    }
    r <- terra::rast(rast_tif)
}
debug: if (fs::file_exists(rast_tif)) {
    r_tmp_tif <- tempfile(fileext = ".tif")
    r_tmp <- c(rast(rast_tif), r)
    r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
    terra::writeRaster(r_tmp, r_tmp_tif)
    fs::file_delete(rast_tif)
    fs::file_move(r_tmp_tif, rast_tif)
    rm(r)
    rm(r_tmp)
} else {
    terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
}
debug: terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
debug: r <- terra::rast(rast_tif)
debug: d_r <- mutate(tidyr::pivot_longer(sf::st_drop_geometry(sf::st_as_sf(terra::zonal(x = r, 
    z = terra::vect(dplyr::select(sf_zones, dplyr::all_of(fld_zones))), 
    fun = zonal_fun, exact = T, na.rm = T, as.polygons = T))), 
    cols = -dplyr::any_of(fld_zones), names_to = "lyr", values_to = zonal_fun), 
    time = readr::parse_datetime(str_replace(lyr, glue("{var}\\|(.*)"), 
        "\\1")))
debug: if (!is.null(zonal_csv)) write_csv(d_r, zonal_csv)
debug: write_csv(d_r, zonal_csv)
debug: if (!keep_nc) unlink(dir_nc, recursive = T)
debug: unlink(dir_nc, recursive = T)
debug: return(d_r)
Downloading 1 requests, up to 67 time slices each
Called from: extractr::ed_extract(ed, var = v, sf_zones = ply, bbox = bb, 
    mask_tif = F, rast_tif = glue("{dir_out}/{nms}/{yr}.tif"), 
    zonal_fun = "mean", zonal_csv = glue("{dir_out}/{nms}/{yr}.csv"), 
    dir_nc = glue("{dir_out}/{nms}/{yr}_nc"), keep_nc = F, n_max_vals_per_req = 1e+05, 
    time_min = time_min, time_max = time_max, verbose = T)
debug: while (i_req <= n_reqs) {
    i_t_beg <- (i_req - 1) * n_t_per_req + 1
    i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
    t_req <- times_todo[c(i_t_beg, i_t_end)]
    t_req_str <- format_ISO8601(t_req, usetz = "Z")
    if (verbose) 
        message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
    ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
        ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
        0), nc)
    unlink(ncs0)
    nc_retry <- T
    nc_n_try <- 1
    n_max_retries
    while (nc_retry) {
        res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
            url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
                bbox[["xmax"]]), latitude = c(bbox[["ymin"]], 
                bbox[["ymax"]]), time = t_req_str, fmt = "nc", 
            store = rerddap::disk(path = dir_nc)))
        if (inherits(res, "try-error")) {
            err <- attr(res, "condition")
            msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
            nc_n_try <- nc_n_try + 1
            if (nc_n_try > n_max_retries) {
                stop(msg)
            }
            else {
                message(msg, "\nRETRYing...")
                Sys.sleep(1)
            }
        }
        else {
            nc_retry <- F
        }
    }
    i_req <- i_req + 1
}
debug: i_t_beg <- (i_req - 1) * n_t_per_req + 1
debug: i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
debug: t_req <- times_todo[c(i_t_beg, i_t_end)]
debug: t_req_str <- format_ISO8601(t_req, usetz = "Z")
debug: if (verbose) message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
debug: message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
Fetching request 1 of 1 (2004-01-01 to 2004-12-01) ~ 19:38:45 UTC
debug: ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
    0), nc)
debug: unlink(ncs0)
debug: nc_retry <- T
debug: nc_n_try <- 1
debug: n_max_retries
debug: while (nc_retry) {
    res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
        url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
            bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
        time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
    if (inherits(res, "try-error")) {
        err <- attr(res, "condition")
        msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
        nc_n_try <- nc_n_try + 1
        if (nc_n_try > n_max_retries) {
            stop(msg)
        }
        else {
            message(msg, "\nRETRYing...")
            Sys.sleep(1)
        }
    }
    else {
        nc_retry <- F
    }
}
debug: res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
    url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
        bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
    time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
debug: if (inherits(res, "try-error")) {
    err <- attr(res, "condition")
    msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
    nc_n_try <- nc_n_try + 1
    if (nc_n_try > n_max_retries) {
        stop(msg)
    }
    else {
        message(msg, "\nRETRYing...")
        Sys.sleep(1)
    }
} else {
    nc_retry <- F
}
debug: nc_retry <- F
debug: (while) nc_retry
debug: i_req <- i_req + 1
debug: (while) i_req <= n_reqs
debug: ncs <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size > 
    0), nc)
debug: r <- terra::rast(ncs)
debug: stopifnot(all(class(terra::time(r)) %in% c("POSIXct", "POSIXt")))
debug: idx <- dplyr::pull(dplyr::filter(dplyr::arrange(dplyr::tibble(idx = 1:terra::nlyr(r), 
    time = terra::time(r)), time), !duplicated(time)), idx)
debug: r <- terra::subset(r, idx)
debug: stopifnot(terra::crs(r, proj = T) == wgs84)
debug: if (mask_tif) r <- terra::mask(r, sf_zones)
debug: lyrs <- glue("{var}|{terra::time(r)}")
debug: if (length(dims_other) > 0 && !all(length(dims[dims_other]) == 
    1)) stop(glue("Other dimensions not yet supported: {paste(dims_other, collapse = ',')}"))
debug: names(r) <- lyrs
debug: if (!is.null(rast_tif)) {
    if (fs::file_exists(rast_tif)) {
        r_tmp_tif <- tempfile(fileext = ".tif")
        r_tmp <- c(rast(rast_tif), r)
        r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
        terra::writeRaster(r_tmp, r_tmp_tif)
        fs::file_delete(rast_tif)
        fs::file_move(r_tmp_tif, rast_tif)
        rm(r)
        rm(r_tmp)
    }
    else {
        terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
    }
    r <- terra::rast(rast_tif)
}
debug: if (fs::file_exists(rast_tif)) {
    r_tmp_tif <- tempfile(fileext = ".tif")
    r_tmp <- c(rast(rast_tif), r)
    r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
    terra::writeRaster(r_tmp, r_tmp_tif)
    fs::file_delete(rast_tif)
    fs::file_move(r_tmp_tif, rast_tif)
    rm(r)
    rm(r_tmp)
} else {
    terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
}
debug: terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
debug: r <- terra::rast(rast_tif)
debug: d_r <- mutate(tidyr::pivot_longer(sf::st_drop_geometry(sf::st_as_sf(terra::zonal(x = r, 
    z = terra::vect(dplyr::select(sf_zones, dplyr::all_of(fld_zones))), 
    fun = zonal_fun, exact = T, na.rm = T, as.polygons = T))), 
    cols = -dplyr::any_of(fld_zones), names_to = "lyr", values_to = zonal_fun), 
    time = readr::parse_datetime(str_replace(lyr, glue("{var}\\|(.*)"), 
        "\\1")))
debug: if (!is.null(zonal_csv)) write_csv(d_r, zonal_csv)
debug: write_csv(d_r, zonal_csv)
debug: if (!keep_nc) unlink(dir_nc, recursive = T)
debug: unlink(dir_nc, recursive = T)
debug: return(d_r)
Downloading 1 requests, up to 67 time slices each
Called from: extractr::ed_extract(ed, var = v, sf_zones = ply, bbox = bb, 
    mask_tif = F, rast_tif = glue("{dir_out}/{nms}/{yr}.tif"), 
    zonal_fun = "mean", zonal_csv = glue("{dir_out}/{nms}/{yr}.csv"), 
    dir_nc = glue("{dir_out}/{nms}/{yr}_nc"), keep_nc = F, n_max_vals_per_req = 1e+05, 
    time_min = time_min, time_max = time_max, verbose = T)
debug: while (i_req <= n_reqs) {
    i_t_beg <- (i_req - 1) * n_t_per_req + 1
    i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
    t_req <- times_todo[c(i_t_beg, i_t_end)]
    t_req_str <- format_ISO8601(t_req, usetz = "Z")
    if (verbose) 
        message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
    ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
        ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
        0), nc)
    unlink(ncs0)
    nc_retry <- T
    nc_n_try <- 1
    n_max_retries
    while (nc_retry) {
        res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
            url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
                bbox[["xmax"]]), latitude = c(bbox[["ymin"]], 
                bbox[["ymax"]]), time = t_req_str, fmt = "nc", 
            store = rerddap::disk(path = dir_nc)))
        if (inherits(res, "try-error")) {
            err <- attr(res, "condition")
            msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
            nc_n_try <- nc_n_try + 1
            if (nc_n_try > n_max_retries) {
                stop(msg)
            }
            else {
                message(msg, "\nRETRYing...")
                Sys.sleep(1)
            }
        }
        else {
            nc_retry <- F
        }
    }
    i_req <- i_req + 1
}
debug: i_t_beg <- (i_req - 1) * n_t_per_req + 1
debug: i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
debug: t_req <- times_todo[c(i_t_beg, i_t_end)]
debug: t_req_str <- format_ISO8601(t_req, usetz = "Z")
debug: if (verbose) message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
debug: message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
Fetching request 1 of 1 (2005-01-01 to 2005-12-01) ~ 19:38:47 UTC
debug: ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
    0), nc)
debug: unlink(ncs0)
debug: nc_retry <- T
debug: nc_n_try <- 1
debug: n_max_retries
debug: while (nc_retry) {
    res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
        url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
            bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
        time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
    if (inherits(res, "try-error")) {
        err <- attr(res, "condition")
        msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
        nc_n_try <- nc_n_try + 1
        if (nc_n_try > n_max_retries) {
            stop(msg)
        }
        else {
            message(msg, "\nRETRYing...")
            Sys.sleep(1)
        }
    }
    else {
        nc_retry <- F
    }
}
debug: res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
    url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
        bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
    time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
debug: if (inherits(res, "try-error")) {
    err <- attr(res, "condition")
    msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
    nc_n_try <- nc_n_try + 1
    if (nc_n_try > n_max_retries) {
        stop(msg)
    }
    else {
        message(msg, "\nRETRYing...")
        Sys.sleep(1)
    }
} else {
    nc_retry <- F
}
debug: nc_retry <- F
debug: (while) nc_retry
debug: i_req <- i_req + 1
debug: (while) i_req <= n_reqs
debug: ncs <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size > 
    0), nc)
debug: r <- terra::rast(ncs)
debug: stopifnot(all(class(terra::time(r)) %in% c("POSIXct", "POSIXt")))
debug: idx <- dplyr::pull(dplyr::filter(dplyr::arrange(dplyr::tibble(idx = 1:terra::nlyr(r), 
    time = terra::time(r)), time), !duplicated(time)), idx)
debug: r <- terra::subset(r, idx)
debug: stopifnot(terra::crs(r, proj = T) == wgs84)
debug: if (mask_tif) r <- terra::mask(r, sf_zones)
debug: lyrs <- glue("{var}|{terra::time(r)}")
debug: if (length(dims_other) > 0 && !all(length(dims[dims_other]) == 
    1)) stop(glue("Other dimensions not yet supported: {paste(dims_other, collapse = ',')}"))
debug: names(r) <- lyrs
debug: if (!is.null(rast_tif)) {
    if (fs::file_exists(rast_tif)) {
        r_tmp_tif <- tempfile(fileext = ".tif")
        r_tmp <- c(rast(rast_tif), r)
        r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
        terra::writeRaster(r_tmp, r_tmp_tif)
        fs::file_delete(rast_tif)
        fs::file_move(r_tmp_tif, rast_tif)
        rm(r)
        rm(r_tmp)
    }
    else {
        terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
    }
    r <- terra::rast(rast_tif)
}
debug: if (fs::file_exists(rast_tif)) {
    r_tmp_tif <- tempfile(fileext = ".tif")
    r_tmp <- c(rast(rast_tif), r)
    r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
    terra::writeRaster(r_tmp, r_tmp_tif)
    fs::file_delete(rast_tif)
    fs::file_move(r_tmp_tif, rast_tif)
    rm(r)
    rm(r_tmp)
} else {
    terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
}
debug: terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
debug: r <- terra::rast(rast_tif)
debug: d_r <- mutate(tidyr::pivot_longer(sf::st_drop_geometry(sf::st_as_sf(terra::zonal(x = r, 
    z = terra::vect(dplyr::select(sf_zones, dplyr::all_of(fld_zones))), 
    fun = zonal_fun, exact = T, na.rm = T, as.polygons = T))), 
    cols = -dplyr::any_of(fld_zones), names_to = "lyr", values_to = zonal_fun), 
    time = readr::parse_datetime(str_replace(lyr, glue("{var}\\|(.*)"), 
        "\\1")))
debug: if (!is.null(zonal_csv)) write_csv(d_r, zonal_csv)
debug: write_csv(d_r, zonal_csv)
debug: if (!keep_nc) unlink(dir_nc, recursive = T)
debug: unlink(dir_nc, recursive = T)
debug: return(d_r)
Downloading 1 requests, up to 67 time slices each
Called from: extractr::ed_extract(ed, var = v, sf_zones = ply, bbox = bb, 
    mask_tif = F, rast_tif = glue("{dir_out}/{nms}/{yr}.tif"), 
    zonal_fun = "mean", zonal_csv = glue("{dir_out}/{nms}/{yr}.csv"), 
    dir_nc = glue("{dir_out}/{nms}/{yr}_nc"), keep_nc = F, n_max_vals_per_req = 1e+05, 
    time_min = time_min, time_max = time_max, verbose = T)
debug: while (i_req <= n_reqs) {
    i_t_beg <- (i_req - 1) * n_t_per_req + 1
    i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
    t_req <- times_todo[c(i_t_beg, i_t_end)]
    t_req_str <- format_ISO8601(t_req, usetz = "Z")
    if (verbose) 
        message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
    ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
        ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
        0), nc)
    unlink(ncs0)
    nc_retry <- T
    nc_n_try <- 1
    n_max_retries
    while (nc_retry) {
        res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
            url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
                bbox[["xmax"]]), latitude = c(bbox[["ymin"]], 
                bbox[["ymax"]]), time = t_req_str, fmt = "nc", 
            store = rerddap::disk(path = dir_nc)))
        if (inherits(res, "try-error")) {
            err <- attr(res, "condition")
            msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
            nc_n_try <- nc_n_try + 1
            if (nc_n_try > n_max_retries) {
                stop(msg)
            }
            else {
                message(msg, "\nRETRYing...")
                Sys.sleep(1)
            }
        }
        else {
            nc_retry <- F
        }
    }
    i_req <- i_req + 1
}
debug: i_t_beg <- (i_req - 1) * n_t_per_req + 1
debug: i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
debug: t_req <- times_todo[c(i_t_beg, i_t_end)]
debug: t_req_str <- format_ISO8601(t_req, usetz = "Z")
debug: if (verbose) message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
debug: message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
Fetching request 1 of 1 (2006-01-01 to 2006-12-01) ~ 19:38:49 UTC
debug: ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
    0), nc)
debug: unlink(ncs0)
debug: nc_retry <- T
debug: nc_n_try <- 1
debug: n_max_retries
debug: while (nc_retry) {
    res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
        url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
            bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
        time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
    if (inherits(res, "try-error")) {
        err <- attr(res, "condition")
        msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
        nc_n_try <- nc_n_try + 1
        if (nc_n_try > n_max_retries) {
            stop(msg)
        }
        else {
            message(msg, "\nRETRYing...")
            Sys.sleep(1)
        }
    }
    else {
        nc_retry <- F
    }
}
debug: res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
    url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
        bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
    time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
debug: if (inherits(res, "try-error")) {
    err <- attr(res, "condition")
    msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
    nc_n_try <- nc_n_try + 1
    if (nc_n_try > n_max_retries) {
        stop(msg)
    }
    else {
        message(msg, "\nRETRYing...")
        Sys.sleep(1)
    }
} else {
    nc_retry <- F
}
debug: nc_retry <- F
debug: (while) nc_retry
debug: i_req <- i_req + 1
debug: (while) i_req <= n_reqs
debug: ncs <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size > 
    0), nc)
debug: r <- terra::rast(ncs)
debug: stopifnot(all(class(terra::time(r)) %in% c("POSIXct", "POSIXt")))
debug: idx <- dplyr::pull(dplyr::filter(dplyr::arrange(dplyr::tibble(idx = 1:terra::nlyr(r), 
    time = terra::time(r)), time), !duplicated(time)), idx)
debug: r <- terra::subset(r, idx)
debug: stopifnot(terra::crs(r, proj = T) == wgs84)
debug: if (mask_tif) r <- terra::mask(r, sf_zones)
debug: lyrs <- glue("{var}|{terra::time(r)}")
debug: if (length(dims_other) > 0 && !all(length(dims[dims_other]) == 
    1)) stop(glue("Other dimensions not yet supported: {paste(dims_other, collapse = ',')}"))
debug: names(r) <- lyrs
debug: if (!is.null(rast_tif)) {
    if (fs::file_exists(rast_tif)) {
        r_tmp_tif <- tempfile(fileext = ".tif")
        r_tmp <- c(rast(rast_tif), r)
        r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
        terra::writeRaster(r_tmp, r_tmp_tif)
        fs::file_delete(rast_tif)
        fs::file_move(r_tmp_tif, rast_tif)
        rm(r)
        rm(r_tmp)
    }
    else {
        terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
    }
    r <- terra::rast(rast_tif)
}
debug: if (fs::file_exists(rast_tif)) {
    r_tmp_tif <- tempfile(fileext = ".tif")
    r_tmp <- c(rast(rast_tif), r)
    r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
    terra::writeRaster(r_tmp, r_tmp_tif)
    fs::file_delete(rast_tif)
    fs::file_move(r_tmp_tif, rast_tif)
    rm(r)
    rm(r_tmp)
} else {
    terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
}
debug: terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
debug: r <- terra::rast(rast_tif)
debug: d_r <- mutate(tidyr::pivot_longer(sf::st_drop_geometry(sf::st_as_sf(terra::zonal(x = r, 
    z = terra::vect(dplyr::select(sf_zones, dplyr::all_of(fld_zones))), 
    fun = zonal_fun, exact = T, na.rm = T, as.polygons = T))), 
    cols = -dplyr::any_of(fld_zones), names_to = "lyr", values_to = zonal_fun), 
    time = readr::parse_datetime(str_replace(lyr, glue("{var}\\|(.*)"), 
        "\\1")))
debug: if (!is.null(zonal_csv)) write_csv(d_r, zonal_csv)
debug: write_csv(d_r, zonal_csv)
debug: if (!keep_nc) unlink(dir_nc, recursive = T)
debug: unlink(dir_nc, recursive = T)
debug: return(d_r)
Downloading 1 requests, up to 67 time slices each
Called from: extractr::ed_extract(ed, var = v, sf_zones = ply, bbox = bb, 
    mask_tif = F, rast_tif = glue("{dir_out}/{nms}/{yr}.tif"), 
    zonal_fun = "mean", zonal_csv = glue("{dir_out}/{nms}/{yr}.csv"), 
    dir_nc = glue("{dir_out}/{nms}/{yr}_nc"), keep_nc = F, n_max_vals_per_req = 1e+05, 
    time_min = time_min, time_max = time_max, verbose = T)
debug: while (i_req <= n_reqs) {
    i_t_beg <- (i_req - 1) * n_t_per_req + 1
    i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
    t_req <- times_todo[c(i_t_beg, i_t_end)]
    t_req_str <- format_ISO8601(t_req, usetz = "Z")
    if (verbose) 
        message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
    ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
        ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
        0), nc)
    unlink(ncs0)
    nc_retry <- T
    nc_n_try <- 1
    n_max_retries
    while (nc_retry) {
        res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
            url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
                bbox[["xmax"]]), latitude = c(bbox[["ymin"]], 
                bbox[["ymax"]]), time = t_req_str, fmt = "nc", 
            store = rerddap::disk(path = dir_nc)))
        if (inherits(res, "try-error")) {
            err <- attr(res, "condition")
            msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
            nc_n_try <- nc_n_try + 1
            if (nc_n_try > n_max_retries) {
                stop(msg)
            }
            else {
                message(msg, "\nRETRYing...")
                Sys.sleep(1)
            }
        }
        else {
            nc_retry <- F
        }
    }
    i_req <- i_req + 1
}
debug: i_t_beg <- (i_req - 1) * n_t_per_req + 1
debug: i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
debug: t_req <- times_todo[c(i_t_beg, i_t_end)]
debug: t_req_str <- format_ISO8601(t_req, usetz = "Z")
debug: if (verbose) message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
debug: message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
Fetching request 1 of 1 (2007-01-01 to 2007-12-01) ~ 19:38:51 UTC
debug: ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
    0), nc)
debug: unlink(ncs0)
debug: nc_retry <- T
debug: nc_n_try <- 1
debug: n_max_retries
debug: while (nc_retry) {
    res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
        url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
            bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
        time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
    if (inherits(res, "try-error")) {
        err <- attr(res, "condition")
        msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
        nc_n_try <- nc_n_try + 1
        if (nc_n_try > n_max_retries) {
            stop(msg)
        }
        else {
            message(msg, "\nRETRYing...")
            Sys.sleep(1)
        }
    }
    else {
        nc_retry <- F
    }
}
debug: res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
    url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
        bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
    time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
debug: if (inherits(res, "try-error")) {
    err <- attr(res, "condition")
    msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
    nc_n_try <- nc_n_try + 1
    if (nc_n_try > n_max_retries) {
        stop(msg)
    }
    else {
        message(msg, "\nRETRYing...")
        Sys.sleep(1)
    }
} else {
    nc_retry <- F
}
debug: nc_retry <- F
debug: (while) nc_retry
debug: i_req <- i_req + 1
debug: (while) i_req <= n_reqs
debug: ncs <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size > 
    0), nc)
debug: r <- terra::rast(ncs)
debug: stopifnot(all(class(terra::time(r)) %in% c("POSIXct", "POSIXt")))
debug: idx <- dplyr::pull(dplyr::filter(dplyr::arrange(dplyr::tibble(idx = 1:terra::nlyr(r), 
    time = terra::time(r)), time), !duplicated(time)), idx)
debug: r <- terra::subset(r, idx)
debug: stopifnot(terra::crs(r, proj = T) == wgs84)
debug: if (mask_tif) r <- terra::mask(r, sf_zones)
debug: lyrs <- glue("{var}|{terra::time(r)}")
debug: if (length(dims_other) > 0 && !all(length(dims[dims_other]) == 
    1)) stop(glue("Other dimensions not yet supported: {paste(dims_other, collapse = ',')}"))
debug: names(r) <- lyrs
debug: if (!is.null(rast_tif)) {
    if (fs::file_exists(rast_tif)) {
        r_tmp_tif <- tempfile(fileext = ".tif")
        r_tmp <- c(rast(rast_tif), r)
        r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
        terra::writeRaster(r_tmp, r_tmp_tif)
        fs::file_delete(rast_tif)
        fs::file_move(r_tmp_tif, rast_tif)
        rm(r)
        rm(r_tmp)
    }
    else {
        terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
    }
    r <- terra::rast(rast_tif)
}
debug: if (fs::file_exists(rast_tif)) {
    r_tmp_tif <- tempfile(fileext = ".tif")
    r_tmp <- c(rast(rast_tif), r)
    r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
    terra::writeRaster(r_tmp, r_tmp_tif)
    fs::file_delete(rast_tif)
    fs::file_move(r_tmp_tif, rast_tif)
    rm(r)
    rm(r_tmp)
} else {
    terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
}
debug: terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
debug: r <- terra::rast(rast_tif)
debug: d_r <- mutate(tidyr::pivot_longer(sf::st_drop_geometry(sf::st_as_sf(terra::zonal(x = r, 
    z = terra::vect(dplyr::select(sf_zones, dplyr::all_of(fld_zones))), 
    fun = zonal_fun, exact = T, na.rm = T, as.polygons = T))), 
    cols = -dplyr::any_of(fld_zones), names_to = "lyr", values_to = zonal_fun), 
    time = readr::parse_datetime(str_replace(lyr, glue("{var}\\|(.*)"), 
        "\\1")))
debug: if (!is.null(zonal_csv)) write_csv(d_r, zonal_csv)
debug: write_csv(d_r, zonal_csv)
debug: if (!keep_nc) unlink(dir_nc, recursive = T)
debug: unlink(dir_nc, recursive = T)
debug: return(d_r)
Downloading 1 requests, up to 67 time slices each
Called from: extractr::ed_extract(ed, var = v, sf_zones = ply, bbox = bb, 
    mask_tif = F, rast_tif = glue("{dir_out}/{nms}/{yr}.tif"), 
    zonal_fun = "mean", zonal_csv = glue("{dir_out}/{nms}/{yr}.csv"), 
    dir_nc = glue("{dir_out}/{nms}/{yr}_nc"), keep_nc = F, n_max_vals_per_req = 1e+05, 
    time_min = time_min, time_max = time_max, verbose = T)
debug: while (i_req <= n_reqs) {
    i_t_beg <- (i_req - 1) * n_t_per_req + 1
    i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
    t_req <- times_todo[c(i_t_beg, i_t_end)]
    t_req_str <- format_ISO8601(t_req, usetz = "Z")
    if (verbose) 
        message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
    ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
        ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
        0), nc)
    unlink(ncs0)
    nc_retry <- T
    nc_n_try <- 1
    n_max_retries
    while (nc_retry) {
        res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
            url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
                bbox[["xmax"]]), latitude = c(bbox[["ymin"]], 
                bbox[["ymax"]]), time = t_req_str, fmt = "nc", 
            store = rerddap::disk(path = dir_nc)))
        if (inherits(res, "try-error")) {
            err <- attr(res, "condition")
            msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
            nc_n_try <- nc_n_try + 1
            if (nc_n_try > n_max_retries) {
                stop(msg)
            }
            else {
                message(msg, "\nRETRYing...")
                Sys.sleep(1)
            }
        }
        else {
            nc_retry <- F
        }
    }
    i_req <- i_req + 1
}
debug: i_t_beg <- (i_req - 1) * n_t_per_req + 1
debug: i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
debug: t_req <- times_todo[c(i_t_beg, i_t_end)]
debug: t_req_str <- format_ISO8601(t_req, usetz = "Z")
debug: if (verbose) message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
debug: message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
Fetching request 1 of 1 (2008-01-01 to 2008-12-01) ~ 19:38:53 UTC
debug: ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
    0), nc)
debug: unlink(ncs0)
debug: nc_retry <- T
debug: nc_n_try <- 1
debug: n_max_retries
debug: while (nc_retry) {
    res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
        url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
            bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
        time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
    if (inherits(res, "try-error")) {
        err <- attr(res, "condition")
        msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
        nc_n_try <- nc_n_try + 1
        if (nc_n_try > n_max_retries) {
            stop(msg)
        }
        else {
            message(msg, "\nRETRYing...")
            Sys.sleep(1)
        }
    }
    else {
        nc_retry <- F
    }
}
debug: res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
    url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
        bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
    time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
debug: if (inherits(res, "try-error")) {
    err <- attr(res, "condition")
    msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
    nc_n_try <- nc_n_try + 1
    if (nc_n_try > n_max_retries) {
        stop(msg)
    }
    else {
        message(msg, "\nRETRYing...")
        Sys.sleep(1)
    }
} else {
    nc_retry <- F
}
debug: nc_retry <- F
debug: (while) nc_retry
debug: i_req <- i_req + 1
debug: (while) i_req <= n_reqs
debug: ncs <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size > 
    0), nc)
debug: r <- terra::rast(ncs)
debug: stopifnot(all(class(terra::time(r)) %in% c("POSIXct", "POSIXt")))
debug: idx <- dplyr::pull(dplyr::filter(dplyr::arrange(dplyr::tibble(idx = 1:terra::nlyr(r), 
    time = terra::time(r)), time), !duplicated(time)), idx)
debug: r <- terra::subset(r, idx)
debug: stopifnot(terra::crs(r, proj = T) == wgs84)
debug: if (mask_tif) r <- terra::mask(r, sf_zones)
debug: lyrs <- glue("{var}|{terra::time(r)}")
debug: if (length(dims_other) > 0 && !all(length(dims[dims_other]) == 
    1)) stop(glue("Other dimensions not yet supported: {paste(dims_other, collapse = ',')}"))
debug: names(r) <- lyrs
debug: if (!is.null(rast_tif)) {
    if (fs::file_exists(rast_tif)) {
        r_tmp_tif <- tempfile(fileext = ".tif")
        r_tmp <- c(rast(rast_tif), r)
        r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
        terra::writeRaster(r_tmp, r_tmp_tif)
        fs::file_delete(rast_tif)
        fs::file_move(r_tmp_tif, rast_tif)
        rm(r)
        rm(r_tmp)
    }
    else {
        terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
    }
    r <- terra::rast(rast_tif)
}
debug: if (fs::file_exists(rast_tif)) {
    r_tmp_tif <- tempfile(fileext = ".tif")
    r_tmp <- c(rast(rast_tif), r)
    r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
    terra::writeRaster(r_tmp, r_tmp_tif)
    fs::file_delete(rast_tif)
    fs::file_move(r_tmp_tif, rast_tif)
    rm(r)
    rm(r_tmp)
} else {
    terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
}
debug: terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
debug: r <- terra::rast(rast_tif)
debug: d_r <- mutate(tidyr::pivot_longer(sf::st_drop_geometry(sf::st_as_sf(terra::zonal(x = r, 
    z = terra::vect(dplyr::select(sf_zones, dplyr::all_of(fld_zones))), 
    fun = zonal_fun, exact = T, na.rm = T, as.polygons = T))), 
    cols = -dplyr::any_of(fld_zones), names_to = "lyr", values_to = zonal_fun), 
    time = readr::parse_datetime(str_replace(lyr, glue("{var}\\|(.*)"), 
        "\\1")))
debug: if (!is.null(zonal_csv)) write_csv(d_r, zonal_csv)
debug: write_csv(d_r, zonal_csv)
debug: if (!keep_nc) unlink(dir_nc, recursive = T)
debug: unlink(dir_nc, recursive = T)
debug: return(d_r)
Downloading 1 requests, up to 67 time slices each
Called from: extractr::ed_extract(ed, var = v, sf_zones = ply, bbox = bb, 
    mask_tif = F, rast_tif = glue("{dir_out}/{nms}/{yr}.tif"), 
    zonal_fun = "mean", zonal_csv = glue("{dir_out}/{nms}/{yr}.csv"), 
    dir_nc = glue("{dir_out}/{nms}/{yr}_nc"), keep_nc = F, n_max_vals_per_req = 1e+05, 
    time_min = time_min, time_max = time_max, verbose = T)
debug: while (i_req <= n_reqs) {
    i_t_beg <- (i_req - 1) * n_t_per_req + 1
    i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
    t_req <- times_todo[c(i_t_beg, i_t_end)]
    t_req_str <- format_ISO8601(t_req, usetz = "Z")
    if (verbose) 
        message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
    ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
        ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
        0), nc)
    unlink(ncs0)
    nc_retry <- T
    nc_n_try <- 1
    n_max_retries
    while (nc_retry) {
        res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
            url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
                bbox[["xmax"]]), latitude = c(bbox[["ymin"]], 
                bbox[["ymax"]]), time = t_req_str, fmt = "nc", 
            store = rerddap::disk(path = dir_nc)))
        if (inherits(res, "try-error")) {
            err <- attr(res, "condition")
            msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
            nc_n_try <- nc_n_try + 1
            if (nc_n_try > n_max_retries) {
                stop(msg)
            }
            else {
                message(msg, "\nRETRYing...")
                Sys.sleep(1)
            }
        }
        else {
            nc_retry <- F
        }
    }
    i_req <- i_req + 1
}
debug: i_t_beg <- (i_req - 1) * n_t_per_req + 1
debug: i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
debug: t_req <- times_todo[c(i_t_beg, i_t_end)]
debug: t_req_str <- format_ISO8601(t_req, usetz = "Z")
debug: if (verbose) message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
debug: message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
Fetching request 1 of 1 (2009-01-01 to 2009-12-01) ~ 19:38:55 UTC
debug: ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
    0), nc)
debug: unlink(ncs0)
debug: nc_retry <- T
debug: nc_n_try <- 1
debug: n_max_retries
debug: while (nc_retry) {
    res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
        url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
            bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
        time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
    if (inherits(res, "try-error")) {
        err <- attr(res, "condition")
        msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
        nc_n_try <- nc_n_try + 1
        if (nc_n_try > n_max_retries) {
            stop(msg)
        }
        else {
            message(msg, "\nRETRYing...")
            Sys.sleep(1)
        }
    }
    else {
        nc_retry <- F
    }
}
debug: res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
    url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
        bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
    time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
debug: if (inherits(res, "try-error")) {
    err <- attr(res, "condition")
    msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
    nc_n_try <- nc_n_try + 1
    if (nc_n_try > n_max_retries) {
        stop(msg)
    }
    else {
        message(msg, "\nRETRYing...")
        Sys.sleep(1)
    }
} else {
    nc_retry <- F
}
debug: nc_retry <- F
debug: (while) nc_retry
debug: i_req <- i_req + 1
debug: (while) i_req <= n_reqs
debug: ncs <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size > 
    0), nc)
debug: r <- terra::rast(ncs)
debug: stopifnot(all(class(terra::time(r)) %in% c("POSIXct", "POSIXt")))
debug: idx <- dplyr::pull(dplyr::filter(dplyr::arrange(dplyr::tibble(idx = 1:terra::nlyr(r), 
    time = terra::time(r)), time), !duplicated(time)), idx)
debug: r <- terra::subset(r, idx)
debug: stopifnot(terra::crs(r, proj = T) == wgs84)
debug: if (mask_tif) r <- terra::mask(r, sf_zones)
debug: lyrs <- glue("{var}|{terra::time(r)}")
debug: if (length(dims_other) > 0 && !all(length(dims[dims_other]) == 
    1)) stop(glue("Other dimensions not yet supported: {paste(dims_other, collapse = ',')}"))
debug: names(r) <- lyrs
debug: if (!is.null(rast_tif)) {
    if (fs::file_exists(rast_tif)) {
        r_tmp_tif <- tempfile(fileext = ".tif")
        r_tmp <- c(rast(rast_tif), r)
        r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
        terra::writeRaster(r_tmp, r_tmp_tif)
        fs::file_delete(rast_tif)
        fs::file_move(r_tmp_tif, rast_tif)
        rm(r)
        rm(r_tmp)
    }
    else {
        terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
    }
    r <- terra::rast(rast_tif)
}
debug: if (fs::file_exists(rast_tif)) {
    r_tmp_tif <- tempfile(fileext = ".tif")
    r_tmp <- c(rast(rast_tif), r)
    r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
    terra::writeRaster(r_tmp, r_tmp_tif)
    fs::file_delete(rast_tif)
    fs::file_move(r_tmp_tif, rast_tif)
    rm(r)
    rm(r_tmp)
} else {
    terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
}
debug: terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
debug: r <- terra::rast(rast_tif)
debug: d_r <- mutate(tidyr::pivot_longer(sf::st_drop_geometry(sf::st_as_sf(terra::zonal(x = r, 
    z = terra::vect(dplyr::select(sf_zones, dplyr::all_of(fld_zones))), 
    fun = zonal_fun, exact = T, na.rm = T, as.polygons = T))), 
    cols = -dplyr::any_of(fld_zones), names_to = "lyr", values_to = zonal_fun), 
    time = readr::parse_datetime(str_replace(lyr, glue("{var}\\|(.*)"), 
        "\\1")))
debug: if (!is.null(zonal_csv)) write_csv(d_r, zonal_csv)
debug: write_csv(d_r, zonal_csv)
debug: if (!keep_nc) unlink(dir_nc, recursive = T)
debug: unlink(dir_nc, recursive = T)
debug: return(d_r)
Downloading 1 requests, up to 67 time slices each
Called from: extractr::ed_extract(ed, var = v, sf_zones = ply, bbox = bb, 
    mask_tif = F, rast_tif = glue("{dir_out}/{nms}/{yr}.tif"), 
    zonal_fun = "mean", zonal_csv = glue("{dir_out}/{nms}/{yr}.csv"), 
    dir_nc = glue("{dir_out}/{nms}/{yr}_nc"), keep_nc = F, n_max_vals_per_req = 1e+05, 
    time_min = time_min, time_max = time_max, verbose = T)
debug: while (i_req <= n_reqs) {
    i_t_beg <- (i_req - 1) * n_t_per_req + 1
    i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
    t_req <- times_todo[c(i_t_beg, i_t_end)]
    t_req_str <- format_ISO8601(t_req, usetz = "Z")
    if (verbose) 
        message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
    ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
        ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
        0), nc)
    unlink(ncs0)
    nc_retry <- T
    nc_n_try <- 1
    n_max_retries
    while (nc_retry) {
        res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
            url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
                bbox[["xmax"]]), latitude = c(bbox[["ymin"]], 
                bbox[["ymax"]]), time = t_req_str, fmt = "nc", 
            store = rerddap::disk(path = dir_nc)))
        if (inherits(res, "try-error")) {
            err <- attr(res, "condition")
            msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
            nc_n_try <- nc_n_try + 1
            if (nc_n_try > n_max_retries) {
                stop(msg)
            }
            else {
                message(msg, "\nRETRYing...")
                Sys.sleep(1)
            }
        }
        else {
            nc_retry <- F
        }
    }
    i_req <- i_req + 1
}
debug: i_t_beg <- (i_req - 1) * n_t_per_req + 1
debug: i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
debug: t_req <- times_todo[c(i_t_beg, i_t_end)]
debug: t_req_str <- format_ISO8601(t_req, usetz = "Z")
debug: if (verbose) message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
debug: message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
Fetching request 1 of 1 (2010-01-01 to 2010-12-01) ~ 19:38:57 UTC
debug: ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
    0), nc)
debug: unlink(ncs0)
debug: nc_retry <- T
debug: nc_n_try <- 1
debug: n_max_retries
debug: while (nc_retry) {
    res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
        url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
            bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
        time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
    if (inherits(res, "try-error")) {
        err <- attr(res, "condition")
        msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
        nc_n_try <- nc_n_try + 1
        if (nc_n_try > n_max_retries) {
            stop(msg)
        }
        else {
            message(msg, "\nRETRYing...")
            Sys.sleep(1)
        }
    }
    else {
        nc_retry <- F
    }
}
debug: res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
    url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
        bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
    time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
debug: if (inherits(res, "try-error")) {
    err <- attr(res, "condition")
    msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
    nc_n_try <- nc_n_try + 1
    if (nc_n_try > n_max_retries) {
        stop(msg)
    }
    else {
        message(msg, "\nRETRYing...")
        Sys.sleep(1)
    }
} else {
    nc_retry <- F
}
debug: nc_retry <- F
debug: (while) nc_retry
debug: i_req <- i_req + 1
debug: (while) i_req <= n_reqs
debug: ncs <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size > 
    0), nc)
debug: r <- terra::rast(ncs)
debug: stopifnot(all(class(terra::time(r)) %in% c("POSIXct", "POSIXt")))
debug: idx <- dplyr::pull(dplyr::filter(dplyr::arrange(dplyr::tibble(idx = 1:terra::nlyr(r), 
    time = terra::time(r)), time), !duplicated(time)), idx)
debug: r <- terra::subset(r, idx)
debug: stopifnot(terra::crs(r, proj = T) == wgs84)
debug: if (mask_tif) r <- terra::mask(r, sf_zones)
debug: lyrs <- glue("{var}|{terra::time(r)}")
debug: if (length(dims_other) > 0 && !all(length(dims[dims_other]) == 
    1)) stop(glue("Other dimensions not yet supported: {paste(dims_other, collapse = ',')}"))
debug: names(r) <- lyrs
debug: if (!is.null(rast_tif)) {
    if (fs::file_exists(rast_tif)) {
        r_tmp_tif <- tempfile(fileext = ".tif")
        r_tmp <- c(rast(rast_tif), r)
        r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
        terra::writeRaster(r_tmp, r_tmp_tif)
        fs::file_delete(rast_tif)
        fs::file_move(r_tmp_tif, rast_tif)
        rm(r)
        rm(r_tmp)
    }
    else {
        terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
    }
    r <- terra::rast(rast_tif)
}
debug: if (fs::file_exists(rast_tif)) {
    r_tmp_tif <- tempfile(fileext = ".tif")
    r_tmp <- c(rast(rast_tif), r)
    r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
    terra::writeRaster(r_tmp, r_tmp_tif)
    fs::file_delete(rast_tif)
    fs::file_move(r_tmp_tif, rast_tif)
    rm(r)
    rm(r_tmp)
} else {
    terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
}
debug: terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
debug: r <- terra::rast(rast_tif)
debug: d_r <- mutate(tidyr::pivot_longer(sf::st_drop_geometry(sf::st_as_sf(terra::zonal(x = r, 
    z = terra::vect(dplyr::select(sf_zones, dplyr::all_of(fld_zones))), 
    fun = zonal_fun, exact = T, na.rm = T, as.polygons = T))), 
    cols = -dplyr::any_of(fld_zones), names_to = "lyr", values_to = zonal_fun), 
    time = readr::parse_datetime(str_replace(lyr, glue("{var}\\|(.*)"), 
        "\\1")))
debug: if (!is.null(zonal_csv)) write_csv(d_r, zonal_csv)
debug: write_csv(d_r, zonal_csv)
debug: if (!keep_nc) unlink(dir_nc, recursive = T)
debug: unlink(dir_nc, recursive = T)
debug: return(d_r)
Downloading 1 requests, up to 67 time slices each
Called from: extractr::ed_extract(ed, var = v, sf_zones = ply, bbox = bb, 
    mask_tif = F, rast_tif = glue("{dir_out}/{nms}/{yr}.tif"), 
    zonal_fun = "mean", zonal_csv = glue("{dir_out}/{nms}/{yr}.csv"), 
    dir_nc = glue("{dir_out}/{nms}/{yr}_nc"), keep_nc = F, n_max_vals_per_req = 1e+05, 
    time_min = time_min, time_max = time_max, verbose = T)
debug: while (i_req <= n_reqs) {
    i_t_beg <- (i_req - 1) * n_t_per_req + 1
    i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
    t_req <- times_todo[c(i_t_beg, i_t_end)]
    t_req_str <- format_ISO8601(t_req, usetz = "Z")
    if (verbose) 
        message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
    ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
        ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
        0), nc)
    unlink(ncs0)
    nc_retry <- T
    nc_n_try <- 1
    n_max_retries
    while (nc_retry) {
        res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
            url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
                bbox[["xmax"]]), latitude = c(bbox[["ymin"]], 
                bbox[["ymax"]]), time = t_req_str, fmt = "nc", 
            store = rerddap::disk(path = dir_nc)))
        if (inherits(res, "try-error")) {
            err <- attr(res, "condition")
            msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
            nc_n_try <- nc_n_try + 1
            if (nc_n_try > n_max_retries) {
                stop(msg)
            }
            else {
                message(msg, "\nRETRYing...")
                Sys.sleep(1)
            }
        }
        else {
            nc_retry <- F
        }
    }
    i_req <- i_req + 1
}
debug: i_t_beg <- (i_req - 1) * n_t_per_req + 1
debug: i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
debug: t_req <- times_todo[c(i_t_beg, i_t_end)]
debug: t_req_str <- format_ISO8601(t_req, usetz = "Z")
debug: if (verbose) message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
debug: message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
Fetching request 1 of 1 (2011-01-01 to 2011-12-01) ~ 19:38:59 UTC
debug: ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
    0), nc)
debug: unlink(ncs0)
debug: nc_retry <- T
debug: nc_n_try <- 1
debug: n_max_retries
debug: while (nc_retry) {
    res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
        url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
            bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
        time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
    if (inherits(res, "try-error")) {
        err <- attr(res, "condition")
        msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
        nc_n_try <- nc_n_try + 1
        if (nc_n_try > n_max_retries) {
            stop(msg)
        }
        else {
            message(msg, "\nRETRYing...")
            Sys.sleep(1)
        }
    }
    else {
        nc_retry <- F
    }
}
debug: res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
    url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
        bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
    time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
debug: if (inherits(res, "try-error")) {
    err <- attr(res, "condition")
    msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
    nc_n_try <- nc_n_try + 1
    if (nc_n_try > n_max_retries) {
        stop(msg)
    }
    else {
        message(msg, "\nRETRYing...")
        Sys.sleep(1)
    }
} else {
    nc_retry <- F
}
debug: nc_retry <- F
debug: (while) nc_retry
debug: i_req <- i_req + 1
debug: (while) i_req <= n_reqs
debug: ncs <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size > 
    0), nc)
debug: r <- terra::rast(ncs)
debug: stopifnot(all(class(terra::time(r)) %in% c("POSIXct", "POSIXt")))
debug: idx <- dplyr::pull(dplyr::filter(dplyr::arrange(dplyr::tibble(idx = 1:terra::nlyr(r), 
    time = terra::time(r)), time), !duplicated(time)), idx)
debug: r <- terra::subset(r, idx)
debug: stopifnot(terra::crs(r, proj = T) == wgs84)
debug: if (mask_tif) r <- terra::mask(r, sf_zones)
debug: lyrs <- glue("{var}|{terra::time(r)}")
debug: if (length(dims_other) > 0 && !all(length(dims[dims_other]) == 
    1)) stop(glue("Other dimensions not yet supported: {paste(dims_other, collapse = ',')}"))
debug: names(r) <- lyrs
debug: if (!is.null(rast_tif)) {
    if (fs::file_exists(rast_tif)) {
        r_tmp_tif <- tempfile(fileext = ".tif")
        r_tmp <- c(rast(rast_tif), r)
        r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
        terra::writeRaster(r_tmp, r_tmp_tif)
        fs::file_delete(rast_tif)
        fs::file_move(r_tmp_tif, rast_tif)
        rm(r)
        rm(r_tmp)
    }
    else {
        terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
    }
    r <- terra::rast(rast_tif)
}
debug: if (fs::file_exists(rast_tif)) {
    r_tmp_tif <- tempfile(fileext = ".tif")
    r_tmp <- c(rast(rast_tif), r)
    r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
    terra::writeRaster(r_tmp, r_tmp_tif)
    fs::file_delete(rast_tif)
    fs::file_move(r_tmp_tif, rast_tif)
    rm(r)
    rm(r_tmp)
} else {
    terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
}
debug: terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
debug: r <- terra::rast(rast_tif)
debug: d_r <- mutate(tidyr::pivot_longer(sf::st_drop_geometry(sf::st_as_sf(terra::zonal(x = r, 
    z = terra::vect(dplyr::select(sf_zones, dplyr::all_of(fld_zones))), 
    fun = zonal_fun, exact = T, na.rm = T, as.polygons = T))), 
    cols = -dplyr::any_of(fld_zones), names_to = "lyr", values_to = zonal_fun), 
    time = readr::parse_datetime(str_replace(lyr, glue("{var}\\|(.*)"), 
        "\\1")))
debug: if (!is.null(zonal_csv)) write_csv(d_r, zonal_csv)
debug: write_csv(d_r, zonal_csv)
debug: if (!keep_nc) unlink(dir_nc, recursive = T)
debug: unlink(dir_nc, recursive = T)
debug: return(d_r)
Downloading 1 requests, up to 67 time slices each
Called from: extractr::ed_extract(ed, var = v, sf_zones = ply, bbox = bb, 
    mask_tif = F, rast_tif = glue("{dir_out}/{nms}/{yr}.tif"), 
    zonal_fun = "mean", zonal_csv = glue("{dir_out}/{nms}/{yr}.csv"), 
    dir_nc = glue("{dir_out}/{nms}/{yr}_nc"), keep_nc = F, n_max_vals_per_req = 1e+05, 
    time_min = time_min, time_max = time_max, verbose = T)
debug: while (i_req <= n_reqs) {
    i_t_beg <- (i_req - 1) * n_t_per_req + 1
    i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
    t_req <- times_todo[c(i_t_beg, i_t_end)]
    t_req_str <- format_ISO8601(t_req, usetz = "Z")
    if (verbose) 
        message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
    ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
        ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
        0), nc)
    unlink(ncs0)
    nc_retry <- T
    nc_n_try <- 1
    n_max_retries
    while (nc_retry) {
        res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
            url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
                bbox[["xmax"]]), latitude = c(bbox[["ymin"]], 
                bbox[["ymax"]]), time = t_req_str, fmt = "nc", 
            store = rerddap::disk(path = dir_nc)))
        if (inherits(res, "try-error")) {
            err <- attr(res, "condition")
            msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
            nc_n_try <- nc_n_try + 1
            if (nc_n_try > n_max_retries) {
                stop(msg)
            }
            else {
                message(msg, "\nRETRYing...")
                Sys.sleep(1)
            }
        }
        else {
            nc_retry <- F
        }
    }
    i_req <- i_req + 1
}
debug: i_t_beg <- (i_req - 1) * n_t_per_req + 1
debug: i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
debug: t_req <- times_todo[c(i_t_beg, i_t_end)]
debug: t_req_str <- format_ISO8601(t_req, usetz = "Z")
debug: if (verbose) message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
debug: message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
Fetching request 1 of 1 (2012-01-01 to 2012-12-01) ~ 19:39:01 UTC
debug: ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
    0), nc)
debug: unlink(ncs0)
debug: nc_retry <- T
debug: nc_n_try <- 1
debug: n_max_retries
debug: while (nc_retry) {
    res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
        url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
            bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
        time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
    if (inherits(res, "try-error")) {
        err <- attr(res, "condition")
        msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
        nc_n_try <- nc_n_try + 1
        if (nc_n_try > n_max_retries) {
            stop(msg)
        }
        else {
            message(msg, "\nRETRYing...")
            Sys.sleep(1)
        }
    }
    else {
        nc_retry <- F
    }
}
debug: res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
    url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
        bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
    time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
debug: if (inherits(res, "try-error")) {
    err <- attr(res, "condition")
    msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
    nc_n_try <- nc_n_try + 1
    if (nc_n_try > n_max_retries) {
        stop(msg)
    }
    else {
        message(msg, "\nRETRYing...")
        Sys.sleep(1)
    }
} else {
    nc_retry <- F
}
debug: nc_retry <- F
debug: (while) nc_retry
debug: i_req <- i_req + 1
debug: (while) i_req <= n_reqs
debug: ncs <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size > 
    0), nc)
debug: r <- terra::rast(ncs)
debug: stopifnot(all(class(terra::time(r)) %in% c("POSIXct", "POSIXt")))
debug: idx <- dplyr::pull(dplyr::filter(dplyr::arrange(dplyr::tibble(idx = 1:terra::nlyr(r), 
    time = terra::time(r)), time), !duplicated(time)), idx)
debug: r <- terra::subset(r, idx)
debug: stopifnot(terra::crs(r, proj = T) == wgs84)
debug: if (mask_tif) r <- terra::mask(r, sf_zones)
debug: lyrs <- glue("{var}|{terra::time(r)}")
debug: if (length(dims_other) > 0 && !all(length(dims[dims_other]) == 
    1)) stop(glue("Other dimensions not yet supported: {paste(dims_other, collapse = ',')}"))
debug: names(r) <- lyrs
debug: if (!is.null(rast_tif)) {
    if (fs::file_exists(rast_tif)) {
        r_tmp_tif <- tempfile(fileext = ".tif")
        r_tmp <- c(rast(rast_tif), r)
        r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
        terra::writeRaster(r_tmp, r_tmp_tif)
        fs::file_delete(rast_tif)
        fs::file_move(r_tmp_tif, rast_tif)
        rm(r)
        rm(r_tmp)
    }
    else {
        terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
    }
    r <- terra::rast(rast_tif)
}
debug: if (fs::file_exists(rast_tif)) {
    r_tmp_tif <- tempfile(fileext = ".tif")
    r_tmp <- c(rast(rast_tif), r)
    r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
    terra::writeRaster(r_tmp, r_tmp_tif)
    fs::file_delete(rast_tif)
    fs::file_move(r_tmp_tif, rast_tif)
    rm(r)
    rm(r_tmp)
} else {
    terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
}
debug: terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
debug: r <- terra::rast(rast_tif)
debug: d_r <- mutate(tidyr::pivot_longer(sf::st_drop_geometry(sf::st_as_sf(terra::zonal(x = r, 
    z = terra::vect(dplyr::select(sf_zones, dplyr::all_of(fld_zones))), 
    fun = zonal_fun, exact = T, na.rm = T, as.polygons = T))), 
    cols = -dplyr::any_of(fld_zones), names_to = "lyr", values_to = zonal_fun), 
    time = readr::parse_datetime(str_replace(lyr, glue("{var}\\|(.*)"), 
        "\\1")))
debug: if (!is.null(zonal_csv)) write_csv(d_r, zonal_csv)
debug: write_csv(d_r, zonal_csv)
debug: if (!keep_nc) unlink(dir_nc, recursive = T)
debug: unlink(dir_nc, recursive = T)
debug: return(d_r)
Downloading 1 requests, up to 67 time slices each
Called from: extractr::ed_extract(ed, var = v, sf_zones = ply, bbox = bb, 
    mask_tif = F, rast_tif = glue("{dir_out}/{nms}/{yr}.tif"), 
    zonal_fun = "mean", zonal_csv = glue("{dir_out}/{nms}/{yr}.csv"), 
    dir_nc = glue("{dir_out}/{nms}/{yr}_nc"), keep_nc = F, n_max_vals_per_req = 1e+05, 
    time_min = time_min, time_max = time_max, verbose = T)
debug: while (i_req <= n_reqs) {
    i_t_beg <- (i_req - 1) * n_t_per_req + 1
    i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
    t_req <- times_todo[c(i_t_beg, i_t_end)]
    t_req_str <- format_ISO8601(t_req, usetz = "Z")
    if (verbose) 
        message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
    ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
        ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
        0), nc)
    unlink(ncs0)
    nc_retry <- T
    nc_n_try <- 1
    n_max_retries
    while (nc_retry) {
        res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
            url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
                bbox[["xmax"]]), latitude = c(bbox[["ymin"]], 
                bbox[["ymax"]]), time = t_req_str, fmt = "nc", 
            store = rerddap::disk(path = dir_nc)))
        if (inherits(res, "try-error")) {
            err <- attr(res, "condition")
            msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
            nc_n_try <- nc_n_try + 1
            if (nc_n_try > n_max_retries) {
                stop(msg)
            }
            else {
                message(msg, "\nRETRYing...")
                Sys.sleep(1)
            }
        }
        else {
            nc_retry <- F
        }
    }
    i_req <- i_req + 1
}
debug: i_t_beg <- (i_req - 1) * n_t_per_req + 1
debug: i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
debug: t_req <- times_todo[c(i_t_beg, i_t_end)]
debug: t_req_str <- format_ISO8601(t_req, usetz = "Z")
debug: if (verbose) message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
debug: message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
Fetching request 1 of 1 (2013-01-01 to 2013-12-01) ~ 19:39:03 UTC
debug: ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
    0), nc)
debug: unlink(ncs0)
debug: nc_retry <- T
debug: nc_n_try <- 1
debug: n_max_retries
debug: while (nc_retry) {
    res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
        url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
            bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
        time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
    if (inherits(res, "try-error")) {
        err <- attr(res, "condition")
        msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
        nc_n_try <- nc_n_try + 1
        if (nc_n_try > n_max_retries) {
            stop(msg)
        }
        else {
            message(msg, "\nRETRYing...")
            Sys.sleep(1)
        }
    }
    else {
        nc_retry <- F
    }
}
debug: res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
    url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
        bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
    time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
debug: if (inherits(res, "try-error")) {
    err <- attr(res, "condition")
    msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
    nc_n_try <- nc_n_try + 1
    if (nc_n_try > n_max_retries) {
        stop(msg)
    }
    else {
        message(msg, "\nRETRYing...")
        Sys.sleep(1)
    }
} else {
    nc_retry <- F
}
debug: nc_retry <- F
debug: (while) nc_retry
debug: i_req <- i_req + 1
debug: (while) i_req <= n_reqs
debug: ncs <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size > 
    0), nc)
debug: r <- terra::rast(ncs)
debug: stopifnot(all(class(terra::time(r)) %in% c("POSIXct", "POSIXt")))
debug: idx <- dplyr::pull(dplyr::filter(dplyr::arrange(dplyr::tibble(idx = 1:terra::nlyr(r), 
    time = terra::time(r)), time), !duplicated(time)), idx)
debug: r <- terra::subset(r, idx)
debug: stopifnot(terra::crs(r, proj = T) == wgs84)
debug: if (mask_tif) r <- terra::mask(r, sf_zones)
debug: lyrs <- glue("{var}|{terra::time(r)}")
debug: if (length(dims_other) > 0 && !all(length(dims[dims_other]) == 
    1)) stop(glue("Other dimensions not yet supported: {paste(dims_other, collapse = ',')}"))
debug: names(r) <- lyrs
debug: if (!is.null(rast_tif)) {
    if (fs::file_exists(rast_tif)) {
        r_tmp_tif <- tempfile(fileext = ".tif")
        r_tmp <- c(rast(rast_tif), r)
        r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
        terra::writeRaster(r_tmp, r_tmp_tif)
        fs::file_delete(rast_tif)
        fs::file_move(r_tmp_tif, rast_tif)
        rm(r)
        rm(r_tmp)
    }
    else {
        terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
    }
    r <- terra::rast(rast_tif)
}
debug: if (fs::file_exists(rast_tif)) {
    r_tmp_tif <- tempfile(fileext = ".tif")
    r_tmp <- c(rast(rast_tif), r)
    r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
    terra::writeRaster(r_tmp, r_tmp_tif)
    fs::file_delete(rast_tif)
    fs::file_move(r_tmp_tif, rast_tif)
    rm(r)
    rm(r_tmp)
} else {
    terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
}
debug: terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
debug: r <- terra::rast(rast_tif)
debug: d_r <- mutate(tidyr::pivot_longer(sf::st_drop_geometry(sf::st_as_sf(terra::zonal(x = r, 
    z = terra::vect(dplyr::select(sf_zones, dplyr::all_of(fld_zones))), 
    fun = zonal_fun, exact = T, na.rm = T, as.polygons = T))), 
    cols = -dplyr::any_of(fld_zones), names_to = "lyr", values_to = zonal_fun), 
    time = readr::parse_datetime(str_replace(lyr, glue("{var}\\|(.*)"), 
        "\\1")))
debug: if (!is.null(zonal_csv)) write_csv(d_r, zonal_csv)
debug: write_csv(d_r, zonal_csv)
debug: if (!keep_nc) unlink(dir_nc, recursive = T)
debug: unlink(dir_nc, recursive = T)
debug: return(d_r)
Downloading 1 requests, up to 67 time slices each
Called from: extractr::ed_extract(ed, var = v, sf_zones = ply, bbox = bb, 
    mask_tif = F, rast_tif = glue("{dir_out}/{nms}/{yr}.tif"), 
    zonal_fun = "mean", zonal_csv = glue("{dir_out}/{nms}/{yr}.csv"), 
    dir_nc = glue("{dir_out}/{nms}/{yr}_nc"), keep_nc = F, n_max_vals_per_req = 1e+05, 
    time_min = time_min, time_max = time_max, verbose = T)
debug: while (i_req <= n_reqs) {
    i_t_beg <- (i_req - 1) * n_t_per_req + 1
    i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
    t_req <- times_todo[c(i_t_beg, i_t_end)]
    t_req_str <- format_ISO8601(t_req, usetz = "Z")
    if (verbose) 
        message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
    ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
        ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
        0), nc)
    unlink(ncs0)
    nc_retry <- T
    nc_n_try <- 1
    n_max_retries
    while (nc_retry) {
        res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
            url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
                bbox[["xmax"]]), latitude = c(bbox[["ymin"]], 
                bbox[["ymax"]]), time = t_req_str, fmt = "nc", 
            store = rerddap::disk(path = dir_nc)))
        if (inherits(res, "try-error")) {
            err <- attr(res, "condition")
            msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
            nc_n_try <- nc_n_try + 1
            if (nc_n_try > n_max_retries) {
                stop(msg)
            }
            else {
                message(msg, "\nRETRYing...")
                Sys.sleep(1)
            }
        }
        else {
            nc_retry <- F
        }
    }
    i_req <- i_req + 1
}
debug: i_t_beg <- (i_req - 1) * n_t_per_req + 1
debug: i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
debug: t_req <- times_todo[c(i_t_beg, i_t_end)]
debug: t_req_str <- format_ISO8601(t_req, usetz = "Z")
debug: if (verbose) message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
debug: message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
Fetching request 1 of 1 (2014-01-01 to 2014-12-01) ~ 19:39:06 UTC
debug: ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
    0), nc)
debug: unlink(ncs0)
debug: nc_retry <- T
debug: nc_n_try <- 1
debug: n_max_retries
debug: while (nc_retry) {
    res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
        url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
            bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
        time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
    if (inherits(res, "try-error")) {
        err <- attr(res, "condition")
        msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
        nc_n_try <- nc_n_try + 1
        if (nc_n_try > n_max_retries) {
            stop(msg)
        }
        else {
            message(msg, "\nRETRYing...")
            Sys.sleep(1)
        }
    }
    else {
        nc_retry <- F
    }
}
debug: res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
    url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
        bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
    time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
debug: if (inherits(res, "try-error")) {
    err <- attr(res, "condition")
    msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
    nc_n_try <- nc_n_try + 1
    if (nc_n_try > n_max_retries) {
        stop(msg)
    }
    else {
        message(msg, "\nRETRYing...")
        Sys.sleep(1)
    }
} else {
    nc_retry <- F
}
debug: nc_retry <- F
debug: (while) nc_retry
debug: i_req <- i_req + 1
debug: (while) i_req <= n_reqs
debug: ncs <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size > 
    0), nc)
debug: r <- terra::rast(ncs)
debug: stopifnot(all(class(terra::time(r)) %in% c("POSIXct", "POSIXt")))
debug: idx <- dplyr::pull(dplyr::filter(dplyr::arrange(dplyr::tibble(idx = 1:terra::nlyr(r), 
    time = terra::time(r)), time), !duplicated(time)), idx)
debug: r <- terra::subset(r, idx)
debug: stopifnot(terra::crs(r, proj = T) == wgs84)
debug: if (mask_tif) r <- terra::mask(r, sf_zones)
debug: lyrs <- glue("{var}|{terra::time(r)}")
debug: if (length(dims_other) > 0 && !all(length(dims[dims_other]) == 
    1)) stop(glue("Other dimensions not yet supported: {paste(dims_other, collapse = ',')}"))
debug: names(r) <- lyrs
debug: if (!is.null(rast_tif)) {
    if (fs::file_exists(rast_tif)) {
        r_tmp_tif <- tempfile(fileext = ".tif")
        r_tmp <- c(rast(rast_tif), r)
        r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
        terra::writeRaster(r_tmp, r_tmp_tif)
        fs::file_delete(rast_tif)
        fs::file_move(r_tmp_tif, rast_tif)
        rm(r)
        rm(r_tmp)
    }
    else {
        terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
    }
    r <- terra::rast(rast_tif)
}
debug: if (fs::file_exists(rast_tif)) {
    r_tmp_tif <- tempfile(fileext = ".tif")
    r_tmp <- c(rast(rast_tif), r)
    r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
    terra::writeRaster(r_tmp, r_tmp_tif)
    fs::file_delete(rast_tif)
    fs::file_move(r_tmp_tif, rast_tif)
    rm(r)
    rm(r_tmp)
} else {
    terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
}
debug: terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
debug: r <- terra::rast(rast_tif)
debug: d_r <- mutate(tidyr::pivot_longer(sf::st_drop_geometry(sf::st_as_sf(terra::zonal(x = r, 
    z = terra::vect(dplyr::select(sf_zones, dplyr::all_of(fld_zones))), 
    fun = zonal_fun, exact = T, na.rm = T, as.polygons = T))), 
    cols = -dplyr::any_of(fld_zones), names_to = "lyr", values_to = zonal_fun), 
    time = readr::parse_datetime(str_replace(lyr, glue("{var}\\|(.*)"), 
        "\\1")))
debug: if (!is.null(zonal_csv)) write_csv(d_r, zonal_csv)
debug: write_csv(d_r, zonal_csv)
debug: if (!keep_nc) unlink(dir_nc, recursive = T)
debug: unlink(dir_nc, recursive = T)
debug: return(d_r)
Downloading 1 requests, up to 67 time slices each
Called from: extractr::ed_extract(ed, var = v, sf_zones = ply, bbox = bb, 
    mask_tif = F, rast_tif = glue("{dir_out}/{nms}/{yr}.tif"), 
    zonal_fun = "mean", zonal_csv = glue("{dir_out}/{nms}/{yr}.csv"), 
    dir_nc = glue("{dir_out}/{nms}/{yr}_nc"), keep_nc = F, n_max_vals_per_req = 1e+05, 
    time_min = time_min, time_max = time_max, verbose = T)
debug: while (i_req <= n_reqs) {
    i_t_beg <- (i_req - 1) * n_t_per_req + 1
    i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
    t_req <- times_todo[c(i_t_beg, i_t_end)]
    t_req_str <- format_ISO8601(t_req, usetz = "Z")
    if (verbose) 
        message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
    ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
        ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
        0), nc)
    unlink(ncs0)
    nc_retry <- T
    nc_n_try <- 1
    n_max_retries
    while (nc_retry) {
        res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
            url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
                bbox[["xmax"]]), latitude = c(bbox[["ymin"]], 
                bbox[["ymax"]]), time = t_req_str, fmt = "nc", 
            store = rerddap::disk(path = dir_nc)))
        if (inherits(res, "try-error")) {
            err <- attr(res, "condition")
            msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
            nc_n_try <- nc_n_try + 1
            if (nc_n_try > n_max_retries) {
                stop(msg)
            }
            else {
                message(msg, "\nRETRYing...")
                Sys.sleep(1)
            }
        }
        else {
            nc_retry <- F
        }
    }
    i_req <- i_req + 1
}
debug: i_t_beg <- (i_req - 1) * n_t_per_req + 1
debug: i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
debug: t_req <- times_todo[c(i_t_beg, i_t_end)]
debug: t_req_str <- format_ISO8601(t_req, usetz = "Z")
debug: if (verbose) message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
debug: message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
Fetching request 1 of 1 (2015-01-01 to 2015-12-01) ~ 19:39:08 UTC
debug: ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
    0), nc)
debug: unlink(ncs0)
debug: nc_retry <- T
debug: nc_n_try <- 1
debug: n_max_retries
debug: while (nc_retry) {
    res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
        url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
            bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
        time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
    if (inherits(res, "try-error")) {
        err <- attr(res, "condition")
        msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
        nc_n_try <- nc_n_try + 1
        if (nc_n_try > n_max_retries) {
            stop(msg)
        }
        else {
            message(msg, "\nRETRYing...")
            Sys.sleep(1)
        }
    }
    else {
        nc_retry <- F
    }
}
debug: res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
    url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
        bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
    time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
debug: if (inherits(res, "try-error")) {
    err <- attr(res, "condition")
    msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
    nc_n_try <- nc_n_try + 1
    if (nc_n_try > n_max_retries) {
        stop(msg)
    }
    else {
        message(msg, "\nRETRYing...")
        Sys.sleep(1)
    }
} else {
    nc_retry <- F
}
debug: nc_retry <- F
debug: (while) nc_retry
debug: i_req <- i_req + 1
debug: (while) i_req <= n_reqs
debug: ncs <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size > 
    0), nc)
debug: r <- terra::rast(ncs)
debug: stopifnot(all(class(terra::time(r)) %in% c("POSIXct", "POSIXt")))
debug: idx <- dplyr::pull(dplyr::filter(dplyr::arrange(dplyr::tibble(idx = 1:terra::nlyr(r), 
    time = terra::time(r)), time), !duplicated(time)), idx)
debug: r <- terra::subset(r, idx)
debug: stopifnot(terra::crs(r, proj = T) == wgs84)
debug: if (mask_tif) r <- terra::mask(r, sf_zones)
debug: lyrs <- glue("{var}|{terra::time(r)}")
debug: if (length(dims_other) > 0 && !all(length(dims[dims_other]) == 
    1)) stop(glue("Other dimensions not yet supported: {paste(dims_other, collapse = ',')}"))
debug: names(r) <- lyrs
debug: if (!is.null(rast_tif)) {
    if (fs::file_exists(rast_tif)) {
        r_tmp_tif <- tempfile(fileext = ".tif")
        r_tmp <- c(rast(rast_tif), r)
        r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
        terra::writeRaster(r_tmp, r_tmp_tif)
        fs::file_delete(rast_tif)
        fs::file_move(r_tmp_tif, rast_tif)
        rm(r)
        rm(r_tmp)
    }
    else {
        terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
    }
    r <- terra::rast(rast_tif)
}
debug: if (fs::file_exists(rast_tif)) {
    r_tmp_tif <- tempfile(fileext = ".tif")
    r_tmp <- c(rast(rast_tif), r)
    r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
    terra::writeRaster(r_tmp, r_tmp_tif)
    fs::file_delete(rast_tif)
    fs::file_move(r_tmp_tif, rast_tif)
    rm(r)
    rm(r_tmp)
} else {
    terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
}
debug: terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
debug: r <- terra::rast(rast_tif)
debug: d_r <- mutate(tidyr::pivot_longer(sf::st_drop_geometry(sf::st_as_sf(terra::zonal(x = r, 
    z = terra::vect(dplyr::select(sf_zones, dplyr::all_of(fld_zones))), 
    fun = zonal_fun, exact = T, na.rm = T, as.polygons = T))), 
    cols = -dplyr::any_of(fld_zones), names_to = "lyr", values_to = zonal_fun), 
    time = readr::parse_datetime(str_replace(lyr, glue("{var}\\|(.*)"), 
        "\\1")))
debug: if (!is.null(zonal_csv)) write_csv(d_r, zonal_csv)
debug: write_csv(d_r, zonal_csv)
debug: if (!keep_nc) unlink(dir_nc, recursive = T)
debug: unlink(dir_nc, recursive = T)
debug: return(d_r)
Downloading 1 requests, up to 67 time slices each
Called from: extractr::ed_extract(ed, var = v, sf_zones = ply, bbox = bb, 
    mask_tif = F, rast_tif = glue("{dir_out}/{nms}/{yr}.tif"), 
    zonal_fun = "mean", zonal_csv = glue("{dir_out}/{nms}/{yr}.csv"), 
    dir_nc = glue("{dir_out}/{nms}/{yr}_nc"), keep_nc = F, n_max_vals_per_req = 1e+05, 
    time_min = time_min, time_max = time_max, verbose = T)
debug: while (i_req <= n_reqs) {
    i_t_beg <- (i_req - 1) * n_t_per_req + 1
    i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
    t_req <- times_todo[c(i_t_beg, i_t_end)]
    t_req_str <- format_ISO8601(t_req, usetz = "Z")
    if (verbose) 
        message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
    ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
        ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
        0), nc)
    unlink(ncs0)
    nc_retry <- T
    nc_n_try <- 1
    n_max_retries
    while (nc_retry) {
        res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
            url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
                bbox[["xmax"]]), latitude = c(bbox[["ymin"]], 
                bbox[["ymax"]]), time = t_req_str, fmt = "nc", 
            store = rerddap::disk(path = dir_nc)))
        if (inherits(res, "try-error")) {
            err <- attr(res, "condition")
            msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
            nc_n_try <- nc_n_try + 1
            if (nc_n_try > n_max_retries) {
                stop(msg)
            }
            else {
                message(msg, "\nRETRYing...")
                Sys.sleep(1)
            }
        }
        else {
            nc_retry <- F
        }
    }
    i_req <- i_req + 1
}
debug: i_t_beg <- (i_req - 1) * n_t_per_req + 1
debug: i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
debug: t_req <- times_todo[c(i_t_beg, i_t_end)]
debug: t_req_str <- format_ISO8601(t_req, usetz = "Z")
debug: if (verbose) message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
debug: message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
Fetching request 1 of 1 (2016-01-01 to 2016-12-01) ~ 19:39:10 UTC
debug: ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
    0), nc)
debug: unlink(ncs0)
debug: nc_retry <- T
debug: nc_n_try <- 1
debug: n_max_retries
debug: while (nc_retry) {
    res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
        url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
            bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
        time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
    if (inherits(res, "try-error")) {
        err <- attr(res, "condition")
        msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
        nc_n_try <- nc_n_try + 1
        if (nc_n_try > n_max_retries) {
            stop(msg)
        }
        else {
            message(msg, "\nRETRYing...")
            Sys.sleep(1)
        }
    }
    else {
        nc_retry <- F
    }
}
debug: res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
    url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
        bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
    time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
debug: if (inherits(res, "try-error")) {
    err <- attr(res, "condition")
    msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
    nc_n_try <- nc_n_try + 1
    if (nc_n_try > n_max_retries) {
        stop(msg)
    }
    else {
        message(msg, "\nRETRYing...")
        Sys.sleep(1)
    }
} else {
    nc_retry <- F
}
debug: nc_retry <- F
debug: (while) nc_retry
debug: i_req <- i_req + 1
debug: (while) i_req <= n_reqs
debug: ncs <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size > 
    0), nc)
debug: r <- terra::rast(ncs)
debug: stopifnot(all(class(terra::time(r)) %in% c("POSIXct", "POSIXt")))
debug: idx <- dplyr::pull(dplyr::filter(dplyr::arrange(dplyr::tibble(idx = 1:terra::nlyr(r), 
    time = terra::time(r)), time), !duplicated(time)), idx)
debug: r <- terra::subset(r, idx)
debug: stopifnot(terra::crs(r, proj = T) == wgs84)
debug: if (mask_tif) r <- terra::mask(r, sf_zones)
debug: lyrs <- glue("{var}|{terra::time(r)}")
debug: if (length(dims_other) > 0 && !all(length(dims[dims_other]) == 
    1)) stop(glue("Other dimensions not yet supported: {paste(dims_other, collapse = ',')}"))
debug: names(r) <- lyrs
debug: if (!is.null(rast_tif)) {
    if (fs::file_exists(rast_tif)) {
        r_tmp_tif <- tempfile(fileext = ".tif")
        r_tmp <- c(rast(rast_tif), r)
        r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
        terra::writeRaster(r_tmp, r_tmp_tif)
        fs::file_delete(rast_tif)
        fs::file_move(r_tmp_tif, rast_tif)
        rm(r)
        rm(r_tmp)
    }
    else {
        terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
    }
    r <- terra::rast(rast_tif)
}
debug: if (fs::file_exists(rast_tif)) {
    r_tmp_tif <- tempfile(fileext = ".tif")
    r_tmp <- c(rast(rast_tif), r)
    r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
    terra::writeRaster(r_tmp, r_tmp_tif)
    fs::file_delete(rast_tif)
    fs::file_move(r_tmp_tif, rast_tif)
    rm(r)
    rm(r_tmp)
} else {
    terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
}
debug: terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
debug: r <- terra::rast(rast_tif)
debug: d_r <- mutate(tidyr::pivot_longer(sf::st_drop_geometry(sf::st_as_sf(terra::zonal(x = r, 
    z = terra::vect(dplyr::select(sf_zones, dplyr::all_of(fld_zones))), 
    fun = zonal_fun, exact = T, na.rm = T, as.polygons = T))), 
    cols = -dplyr::any_of(fld_zones), names_to = "lyr", values_to = zonal_fun), 
    time = readr::parse_datetime(str_replace(lyr, glue("{var}\\|(.*)"), 
        "\\1")))
debug: if (!is.null(zonal_csv)) write_csv(d_r, zonal_csv)
debug: write_csv(d_r, zonal_csv)
debug: if (!keep_nc) unlink(dir_nc, recursive = T)
debug: unlink(dir_nc, recursive = T)
debug: return(d_r)
Downloading 1 requests, up to 67 time slices each
Called from: extractr::ed_extract(ed, var = v, sf_zones = ply, bbox = bb, 
    mask_tif = F, rast_tif = glue("{dir_out}/{nms}/{yr}.tif"), 
    zonal_fun = "mean", zonal_csv = glue("{dir_out}/{nms}/{yr}.csv"), 
    dir_nc = glue("{dir_out}/{nms}/{yr}_nc"), keep_nc = F, n_max_vals_per_req = 1e+05, 
    time_min = time_min, time_max = time_max, verbose = T)
debug: while (i_req <= n_reqs) {
    i_t_beg <- (i_req - 1) * n_t_per_req + 1
    i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
    t_req <- times_todo[c(i_t_beg, i_t_end)]
    t_req_str <- format_ISO8601(t_req, usetz = "Z")
    if (verbose) 
        message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
    ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
        ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
        0), nc)
    unlink(ncs0)
    nc_retry <- T
    nc_n_try <- 1
    n_max_retries
    while (nc_retry) {
        res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
            url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
                bbox[["xmax"]]), latitude = c(bbox[["ymin"]], 
                bbox[["ymax"]]), time = t_req_str, fmt = "nc", 
            store = rerddap::disk(path = dir_nc)))
        if (inherits(res, "try-error")) {
            err <- attr(res, "condition")
            msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
            nc_n_try <- nc_n_try + 1
            if (nc_n_try > n_max_retries) {
                stop(msg)
            }
            else {
                message(msg, "\nRETRYing...")
                Sys.sleep(1)
            }
        }
        else {
            nc_retry <- F
        }
    }
    i_req <- i_req + 1
}
debug: i_t_beg <- (i_req - 1) * n_t_per_req + 1
debug: i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
debug: t_req <- times_todo[c(i_t_beg, i_t_end)]
debug: t_req_str <- format_ISO8601(t_req, usetz = "Z")
debug: if (verbose) message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
debug: message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
Fetching request 1 of 1 (2017-01-01 to 2017-12-01) ~ 19:39:12 UTC
debug: ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
    0), nc)
debug: unlink(ncs0)
debug: nc_retry <- T
debug: nc_n_try <- 1
debug: n_max_retries
debug: while (nc_retry) {
    res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
        url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
            bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
        time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
    if (inherits(res, "try-error")) {
        err <- attr(res, "condition")
        msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
        nc_n_try <- nc_n_try + 1
        if (nc_n_try > n_max_retries) {
            stop(msg)
        }
        else {
            message(msg, "\nRETRYing...")
            Sys.sleep(1)
        }
    }
    else {
        nc_retry <- F
    }
}
debug: res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
    url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
        bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
    time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
debug: if (inherits(res, "try-error")) {
    err <- attr(res, "condition")
    msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
    nc_n_try <- nc_n_try + 1
    if (nc_n_try > n_max_retries) {
        stop(msg)
    }
    else {
        message(msg, "\nRETRYing...")
        Sys.sleep(1)
    }
} else {
    nc_retry <- F
}
debug: nc_retry <- F
debug: (while) nc_retry
debug: i_req <- i_req + 1
debug: (while) i_req <= n_reqs
debug: ncs <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size > 
    0), nc)
debug: r <- terra::rast(ncs)
debug: stopifnot(all(class(terra::time(r)) %in% c("POSIXct", "POSIXt")))
debug: idx <- dplyr::pull(dplyr::filter(dplyr::arrange(dplyr::tibble(idx = 1:terra::nlyr(r), 
    time = terra::time(r)), time), !duplicated(time)), idx)
debug: r <- terra::subset(r, idx)
debug: stopifnot(terra::crs(r, proj = T) == wgs84)
debug: if (mask_tif) r <- terra::mask(r, sf_zones)
debug: lyrs <- glue("{var}|{terra::time(r)}")
debug: if (length(dims_other) > 0 && !all(length(dims[dims_other]) == 
    1)) stop(glue("Other dimensions not yet supported: {paste(dims_other, collapse = ',')}"))
debug: names(r) <- lyrs
debug: if (!is.null(rast_tif)) {
    if (fs::file_exists(rast_tif)) {
        r_tmp_tif <- tempfile(fileext = ".tif")
        r_tmp <- c(rast(rast_tif), r)
        r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
        terra::writeRaster(r_tmp, r_tmp_tif)
        fs::file_delete(rast_tif)
        fs::file_move(r_tmp_tif, rast_tif)
        rm(r)
        rm(r_tmp)
    }
    else {
        terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
    }
    r <- terra::rast(rast_tif)
}
debug: if (fs::file_exists(rast_tif)) {
    r_tmp_tif <- tempfile(fileext = ".tif")
    r_tmp <- c(rast(rast_tif), r)
    r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
    terra::writeRaster(r_tmp, r_tmp_tif)
    fs::file_delete(rast_tif)
    fs::file_move(r_tmp_tif, rast_tif)
    rm(r)
    rm(r_tmp)
} else {
    terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
}
debug: terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
debug: r <- terra::rast(rast_tif)
debug: d_r <- mutate(tidyr::pivot_longer(sf::st_drop_geometry(sf::st_as_sf(terra::zonal(x = r, 
    z = terra::vect(dplyr::select(sf_zones, dplyr::all_of(fld_zones))), 
    fun = zonal_fun, exact = T, na.rm = T, as.polygons = T))), 
    cols = -dplyr::any_of(fld_zones), names_to = "lyr", values_to = zonal_fun), 
    time = readr::parse_datetime(str_replace(lyr, glue("{var}\\|(.*)"), 
        "\\1")))
debug: if (!is.null(zonal_csv)) write_csv(d_r, zonal_csv)
debug: write_csv(d_r, zonal_csv)
debug: if (!keep_nc) unlink(dir_nc, recursive = T)
debug: unlink(dir_nc, recursive = T)
debug: return(d_r)
Downloading 1 requests, up to 67 time slices each
Called from: extractr::ed_extract(ed, var = v, sf_zones = ply, bbox = bb, 
    mask_tif = F, rast_tif = glue("{dir_out}/{nms}/{yr}.tif"), 
    zonal_fun = "mean", zonal_csv = glue("{dir_out}/{nms}/{yr}.csv"), 
    dir_nc = glue("{dir_out}/{nms}/{yr}_nc"), keep_nc = F, n_max_vals_per_req = 1e+05, 
    time_min = time_min, time_max = time_max, verbose = T)
debug: while (i_req <= n_reqs) {
    i_t_beg <- (i_req - 1) * n_t_per_req + 1
    i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
    t_req <- times_todo[c(i_t_beg, i_t_end)]
    t_req_str <- format_ISO8601(t_req, usetz = "Z")
    if (verbose) 
        message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
    ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
        ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
        0), nc)
    unlink(ncs0)
    nc_retry <- T
    nc_n_try <- 1
    n_max_retries
    while (nc_retry) {
        res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
            url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
                bbox[["xmax"]]), latitude = c(bbox[["ymin"]], 
                bbox[["ymax"]]), time = t_req_str, fmt = "nc", 
            store = rerddap::disk(path = dir_nc)))
        if (inherits(res, "try-error")) {
            err <- attr(res, "condition")
            msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
            nc_n_try <- nc_n_try + 1
            if (nc_n_try > n_max_retries) {
                stop(msg)
            }
            else {
                message(msg, "\nRETRYing...")
                Sys.sleep(1)
            }
        }
        else {
            nc_retry <- F
        }
    }
    i_req <- i_req + 1
}
debug: i_t_beg <- (i_req - 1) * n_t_per_req + 1
debug: i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
debug: t_req <- times_todo[c(i_t_beg, i_t_end)]
debug: t_req_str <- format_ISO8601(t_req, usetz = "Z")
debug: if (verbose) message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
debug: message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
Fetching request 1 of 1 (2018-01-01 to 2018-12-01) ~ 19:39:14 UTC
debug: ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
    0), nc)
debug: unlink(ncs0)
debug: nc_retry <- T
debug: nc_n_try <- 1
debug: n_max_retries
debug: while (nc_retry) {
    res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
        url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
            bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
        time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
    if (inherits(res, "try-error")) {
        err <- attr(res, "condition")
        msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
        nc_n_try <- nc_n_try + 1
        if (nc_n_try > n_max_retries) {
            stop(msg)
        }
        else {
            message(msg, "\nRETRYing...")
            Sys.sleep(1)
        }
    }
    else {
        nc_retry <- F
    }
}
debug: res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
    url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
        bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
    time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
debug: if (inherits(res, "try-error")) {
    err <- attr(res, "condition")
    msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
    nc_n_try <- nc_n_try + 1
    if (nc_n_try > n_max_retries) {
        stop(msg)
    }
    else {
        message(msg, "\nRETRYing...")
        Sys.sleep(1)
    }
} else {
    nc_retry <- F
}
debug: nc_retry <- F
debug: (while) nc_retry
debug: i_req <- i_req + 1
debug: (while) i_req <= n_reqs
debug: ncs <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size > 
    0), nc)
debug: r <- terra::rast(ncs)
debug: stopifnot(all(class(terra::time(r)) %in% c("POSIXct", "POSIXt")))
debug: idx <- dplyr::pull(dplyr::filter(dplyr::arrange(dplyr::tibble(idx = 1:terra::nlyr(r), 
    time = terra::time(r)), time), !duplicated(time)), idx)
debug: r <- terra::subset(r, idx)
debug: stopifnot(terra::crs(r, proj = T) == wgs84)
debug: if (mask_tif) r <- terra::mask(r, sf_zones)
debug: lyrs <- glue("{var}|{terra::time(r)}")
debug: if (length(dims_other) > 0 && !all(length(dims[dims_other]) == 
    1)) stop(glue("Other dimensions not yet supported: {paste(dims_other, collapse = ',')}"))
debug: names(r) <- lyrs
debug: if (!is.null(rast_tif)) {
    if (fs::file_exists(rast_tif)) {
        r_tmp_tif <- tempfile(fileext = ".tif")
        r_tmp <- c(rast(rast_tif), r)
        r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
        terra::writeRaster(r_tmp, r_tmp_tif)
        fs::file_delete(rast_tif)
        fs::file_move(r_tmp_tif, rast_tif)
        rm(r)
        rm(r_tmp)
    }
    else {
        terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
    }
    r <- terra::rast(rast_tif)
}
debug: if (fs::file_exists(rast_tif)) {
    r_tmp_tif <- tempfile(fileext = ".tif")
    r_tmp <- c(rast(rast_tif), r)
    r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
    terra::writeRaster(r_tmp, r_tmp_tif)
    fs::file_delete(rast_tif)
    fs::file_move(r_tmp_tif, rast_tif)
    rm(r)
    rm(r_tmp)
} else {
    terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
}
debug: terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
debug: r <- terra::rast(rast_tif)
debug: d_r <- mutate(tidyr::pivot_longer(sf::st_drop_geometry(sf::st_as_sf(terra::zonal(x = r, 
    z = terra::vect(dplyr::select(sf_zones, dplyr::all_of(fld_zones))), 
    fun = zonal_fun, exact = T, na.rm = T, as.polygons = T))), 
    cols = -dplyr::any_of(fld_zones), names_to = "lyr", values_to = zonal_fun), 
    time = readr::parse_datetime(str_replace(lyr, glue("{var}\\|(.*)"), 
        "\\1")))
debug: if (!is.null(zonal_csv)) write_csv(d_r, zonal_csv)
debug: write_csv(d_r, zonal_csv)
debug: if (!keep_nc) unlink(dir_nc, recursive = T)
debug: unlink(dir_nc, recursive = T)
debug: return(d_r)
Downloading 1 requests, up to 67 time slices each
Called from: extractr::ed_extract(ed, var = v, sf_zones = ply, bbox = bb, 
    mask_tif = F, rast_tif = glue("{dir_out}/{nms}/{yr}.tif"), 
    zonal_fun = "mean", zonal_csv = glue("{dir_out}/{nms}/{yr}.csv"), 
    dir_nc = glue("{dir_out}/{nms}/{yr}_nc"), keep_nc = F, n_max_vals_per_req = 1e+05, 
    time_min = time_min, time_max = time_max, verbose = T)
debug: while (i_req <= n_reqs) {
    i_t_beg <- (i_req - 1) * n_t_per_req + 1
    i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
    t_req <- times_todo[c(i_t_beg, i_t_end)]
    t_req_str <- format_ISO8601(t_req, usetz = "Z")
    if (verbose) 
        message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
    ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
        ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
        0), nc)
    unlink(ncs0)
    nc_retry <- T
    nc_n_try <- 1
    n_max_retries
    while (nc_retry) {
        res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
            url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
                bbox[["xmax"]]), latitude = c(bbox[["ymin"]], 
                bbox[["ymax"]]), time = t_req_str, fmt = "nc", 
            store = rerddap::disk(path = dir_nc)))
        if (inherits(res, "try-error")) {
            err <- attr(res, "condition")
            msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
            nc_n_try <- nc_n_try + 1
            if (nc_n_try > n_max_retries) {
                stop(msg)
            }
            else {
                message(msg, "\nRETRYing...")
                Sys.sleep(1)
            }
        }
        else {
            nc_retry <- F
        }
    }
    i_req <- i_req + 1
}
debug: i_t_beg <- (i_req - 1) * n_t_per_req + 1
debug: i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
debug: t_req <- times_todo[c(i_t_beg, i_t_end)]
debug: t_req_str <- format_ISO8601(t_req, usetz = "Z")
debug: if (verbose) message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
debug: message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
Fetching request 1 of 1 (2019-01-01 to 2019-12-01) ~ 19:39:16 UTC
debug: ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
    0), nc)
debug: unlink(ncs0)
debug: nc_retry <- T
debug: nc_n_try <- 1
debug: n_max_retries
debug: while (nc_retry) {
    res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
        url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
            bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
        time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
    if (inherits(res, "try-error")) {
        err <- attr(res, "condition")
        msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
        nc_n_try <- nc_n_try + 1
        if (nc_n_try > n_max_retries) {
            stop(msg)
        }
        else {
            message(msg, "\nRETRYing...")
            Sys.sleep(1)
        }
    }
    else {
        nc_retry <- F
    }
}
debug: res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
    url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
        bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
    time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
debug: if (inherits(res, "try-error")) {
    err <- attr(res, "condition")
    msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
    nc_n_try <- nc_n_try + 1
    if (nc_n_try > n_max_retries) {
        stop(msg)
    }
    else {
        message(msg, "\nRETRYing...")
        Sys.sleep(1)
    }
} else {
    nc_retry <- F
}
debug: nc_retry <- F
debug: (while) nc_retry
debug: i_req <- i_req + 1
debug: (while) i_req <= n_reqs
debug: ncs <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size > 
    0), nc)
debug: r <- terra::rast(ncs)
debug: stopifnot(all(class(terra::time(r)) %in% c("POSIXct", "POSIXt")))
debug: idx <- dplyr::pull(dplyr::filter(dplyr::arrange(dplyr::tibble(idx = 1:terra::nlyr(r), 
    time = terra::time(r)), time), !duplicated(time)), idx)
debug: r <- terra::subset(r, idx)
debug: stopifnot(terra::crs(r, proj = T) == wgs84)
debug: if (mask_tif) r <- terra::mask(r, sf_zones)
debug: lyrs <- glue("{var}|{terra::time(r)}")
debug: if (length(dims_other) > 0 && !all(length(dims[dims_other]) == 
    1)) stop(glue("Other dimensions not yet supported: {paste(dims_other, collapse = ',')}"))
debug: names(r) <- lyrs
debug: if (!is.null(rast_tif)) {
    if (fs::file_exists(rast_tif)) {
        r_tmp_tif <- tempfile(fileext = ".tif")
        r_tmp <- c(rast(rast_tif), r)
        r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
        terra::writeRaster(r_tmp, r_tmp_tif)
        fs::file_delete(rast_tif)
        fs::file_move(r_tmp_tif, rast_tif)
        rm(r)
        rm(r_tmp)
    }
    else {
        terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
    }
    r <- terra::rast(rast_tif)
}
debug: if (fs::file_exists(rast_tif)) {
    r_tmp_tif <- tempfile(fileext = ".tif")
    r_tmp <- c(rast(rast_tif), r)
    r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
    terra::writeRaster(r_tmp, r_tmp_tif)
    fs::file_delete(rast_tif)
    fs::file_move(r_tmp_tif, rast_tif)
    rm(r)
    rm(r_tmp)
} else {
    terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
}
debug: terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
debug: r <- terra::rast(rast_tif)
debug: d_r <- mutate(tidyr::pivot_longer(sf::st_drop_geometry(sf::st_as_sf(terra::zonal(x = r, 
    z = terra::vect(dplyr::select(sf_zones, dplyr::all_of(fld_zones))), 
    fun = zonal_fun, exact = T, na.rm = T, as.polygons = T))), 
    cols = -dplyr::any_of(fld_zones), names_to = "lyr", values_to = zonal_fun), 
    time = readr::parse_datetime(str_replace(lyr, glue("{var}\\|(.*)"), 
        "\\1")))
debug: if (!is.null(zonal_csv)) write_csv(d_r, zonal_csv)
debug: write_csv(d_r, zonal_csv)
debug: if (!keep_nc) unlink(dir_nc, recursive = T)
debug: unlink(dir_nc, recursive = T)
debug: return(d_r)
Downloading 1 requests, up to 67 time slices each
Called from: extractr::ed_extract(ed, var = v, sf_zones = ply, bbox = bb, 
    mask_tif = F, rast_tif = glue("{dir_out}/{nms}/{yr}.tif"), 
    zonal_fun = "mean", zonal_csv = glue("{dir_out}/{nms}/{yr}.csv"), 
    dir_nc = glue("{dir_out}/{nms}/{yr}_nc"), keep_nc = F, n_max_vals_per_req = 1e+05, 
    time_min = time_min, time_max = time_max, verbose = T)
debug: while (i_req <= n_reqs) {
    i_t_beg <- (i_req - 1) * n_t_per_req + 1
    i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
    t_req <- times_todo[c(i_t_beg, i_t_end)]
    t_req_str <- format_ISO8601(t_req, usetz = "Z")
    if (verbose) 
        message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
    ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
        ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
        0), nc)
    unlink(ncs0)
    nc_retry <- T
    nc_n_try <- 1
    n_max_retries
    while (nc_retry) {
        res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
            url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
                bbox[["xmax"]]), latitude = c(bbox[["ymin"]], 
                bbox[["ymax"]]), time = t_req_str, fmt = "nc", 
            store = rerddap::disk(path = dir_nc)))
        if (inherits(res, "try-error")) {
            err <- attr(res, "condition")
            msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
            nc_n_try <- nc_n_try + 1
            if (nc_n_try > n_max_retries) {
                stop(msg)
            }
            else {
                message(msg, "\nRETRYing...")
                Sys.sleep(1)
            }
        }
        else {
            nc_retry <- F
        }
    }
    i_req <- i_req + 1
}
debug: i_t_beg <- (i_req - 1) * n_t_per_req + 1
debug: i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
debug: t_req <- times_todo[c(i_t_beg, i_t_end)]
debug: t_req_str <- format_ISO8601(t_req, usetz = "Z")
debug: if (verbose) message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
debug: message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
Fetching request 1 of 1 (2020-01-01 to 2020-12-01) ~ 19:39:19 UTC
debug: ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
    0), nc)
debug: unlink(ncs0)
debug: nc_retry <- T
debug: nc_n_try <- 1
debug: n_max_retries
debug: while (nc_retry) {
    res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
        url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
            bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
        time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
    if (inherits(res, "try-error")) {
        err <- attr(res, "condition")
        msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
        nc_n_try <- nc_n_try + 1
        if (nc_n_try > n_max_retries) {
            stop(msg)
        }
        else {
            message(msg, "\nRETRYing...")
            Sys.sleep(1)
        }
    }
    else {
        nc_retry <- F
    }
}
debug: res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
    url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
        bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
    time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
debug: if (inherits(res, "try-error")) {
    err <- attr(res, "condition")
    msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
    nc_n_try <- nc_n_try + 1
    if (nc_n_try > n_max_retries) {
        stop(msg)
    }
    else {
        message(msg, "\nRETRYing...")
        Sys.sleep(1)
    }
} else {
    nc_retry <- F
}
debug: nc_retry <- F
debug: (while) nc_retry
debug: i_req <- i_req + 1
debug: (while) i_req <= n_reqs
debug: ncs <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size > 
    0), nc)
debug: r <- terra::rast(ncs)
debug: stopifnot(all(class(terra::time(r)) %in% c("POSIXct", "POSIXt")))
debug: idx <- dplyr::pull(dplyr::filter(dplyr::arrange(dplyr::tibble(idx = 1:terra::nlyr(r), 
    time = terra::time(r)), time), !duplicated(time)), idx)
debug: r <- terra::subset(r, idx)
debug: stopifnot(terra::crs(r, proj = T) == wgs84)
debug: if (mask_tif) r <- terra::mask(r, sf_zones)
debug: lyrs <- glue("{var}|{terra::time(r)}")
debug: if (length(dims_other) > 0 && !all(length(dims[dims_other]) == 
    1)) stop(glue("Other dimensions not yet supported: {paste(dims_other, collapse = ',')}"))
debug: names(r) <- lyrs
debug: if (!is.null(rast_tif)) {
    if (fs::file_exists(rast_tif)) {
        r_tmp_tif <- tempfile(fileext = ".tif")
        r_tmp <- c(rast(rast_tif), r)
        r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
        terra::writeRaster(r_tmp, r_tmp_tif)
        fs::file_delete(rast_tif)
        fs::file_move(r_tmp_tif, rast_tif)
        rm(r)
        rm(r_tmp)
    }
    else {
        terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
    }
    r <- terra::rast(rast_tif)
}
debug: if (fs::file_exists(rast_tif)) {
    r_tmp_tif <- tempfile(fileext = ".tif")
    r_tmp <- c(rast(rast_tif), r)
    r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
    terra::writeRaster(r_tmp, r_tmp_tif)
    fs::file_delete(rast_tif)
    fs::file_move(r_tmp_tif, rast_tif)
    rm(r)
    rm(r_tmp)
} else {
    terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
}
debug: terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
debug: r <- terra::rast(rast_tif)
debug: d_r <- mutate(tidyr::pivot_longer(sf::st_drop_geometry(sf::st_as_sf(terra::zonal(x = r, 
    z = terra::vect(dplyr::select(sf_zones, dplyr::all_of(fld_zones))), 
    fun = zonal_fun, exact = T, na.rm = T, as.polygons = T))), 
    cols = -dplyr::any_of(fld_zones), names_to = "lyr", values_to = zonal_fun), 
    time = readr::parse_datetime(str_replace(lyr, glue("{var}\\|(.*)"), 
        "\\1")))
debug: if (!is.null(zonal_csv)) write_csv(d_r, zonal_csv)
debug: write_csv(d_r, zonal_csv)
debug: if (!keep_nc) unlink(dir_nc, recursive = T)
debug: unlink(dir_nc, recursive = T)
debug: return(d_r)
Downloading 1 requests, up to 67 time slices each
Called from: extractr::ed_extract(ed, var = v, sf_zones = ply, bbox = bb, 
    mask_tif = F, rast_tif = glue("{dir_out}/{nms}/{yr}.tif"), 
    zonal_fun = "mean", zonal_csv = glue("{dir_out}/{nms}/{yr}.csv"), 
    dir_nc = glue("{dir_out}/{nms}/{yr}_nc"), keep_nc = F, n_max_vals_per_req = 1e+05, 
    time_min = time_min, time_max = time_max, verbose = T)
debug: while (i_req <= n_reqs) {
    i_t_beg <- (i_req - 1) * n_t_per_req + 1
    i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
    t_req <- times_todo[c(i_t_beg, i_t_end)]
    t_req_str <- format_ISO8601(t_req, usetz = "Z")
    if (verbose) 
        message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
    ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
        ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
        0), nc)
    unlink(ncs0)
    nc_retry <- T
    nc_n_try <- 1
    n_max_retries
    while (nc_retry) {
        res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
            url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
                bbox[["xmax"]]), latitude = c(bbox[["ymin"]], 
                bbox[["ymax"]]), time = t_req_str, fmt = "nc", 
            store = rerddap::disk(path = dir_nc)))
        if (inherits(res, "try-error")) {
            err <- attr(res, "condition")
            msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
            nc_n_try <- nc_n_try + 1
            if (nc_n_try > n_max_retries) {
                stop(msg)
            }
            else {
                message(msg, "\nRETRYing...")
                Sys.sleep(1)
            }
        }
        else {
            nc_retry <- F
        }
    }
    i_req <- i_req + 1
}
debug: i_t_beg <- (i_req - 1) * n_t_per_req + 1
debug: i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
debug: t_req <- times_todo[c(i_t_beg, i_t_end)]
debug: t_req_str <- format_ISO8601(t_req, usetz = "Z")
debug: if (verbose) message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
debug: message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
Fetching request 1 of 1 (2021-01-01 to 2021-12-01) ~ 19:39:21 UTC
debug: ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
    0), nc)
debug: unlink(ncs0)
debug: nc_retry <- T
debug: nc_n_try <- 1
debug: n_max_retries
debug: while (nc_retry) {
    res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
        url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
            bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
        time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
    if (inherits(res, "try-error")) {
        err <- attr(res, "condition")
        msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
        nc_n_try <- nc_n_try + 1
        if (nc_n_try > n_max_retries) {
            stop(msg)
        }
        else {
            message(msg, "\nRETRYing...")
            Sys.sleep(1)
        }
    }
    else {
        nc_retry <- F
    }
}
debug: res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
    url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
        bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
    time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
debug: if (inherits(res, "try-error")) {
    err <- attr(res, "condition")
    msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
    nc_n_try <- nc_n_try + 1
    if (nc_n_try > n_max_retries) {
        stop(msg)
    }
    else {
        message(msg, "\nRETRYing...")
        Sys.sleep(1)
    }
} else {
    nc_retry <- F
}
debug: nc_retry <- F
debug: (while) nc_retry
debug: i_req <- i_req + 1
debug: (while) i_req <= n_reqs
debug: ncs <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size > 
    0), nc)
debug: r <- terra::rast(ncs)
debug: stopifnot(all(class(terra::time(r)) %in% c("POSIXct", "POSIXt")))
debug: idx <- dplyr::pull(dplyr::filter(dplyr::arrange(dplyr::tibble(idx = 1:terra::nlyr(r), 
    time = terra::time(r)), time), !duplicated(time)), idx)
debug: r <- terra::subset(r, idx)
debug: stopifnot(terra::crs(r, proj = T) == wgs84)
debug: if (mask_tif) r <- terra::mask(r, sf_zones)
debug: lyrs <- glue("{var}|{terra::time(r)}")
debug: if (length(dims_other) > 0 && !all(length(dims[dims_other]) == 
    1)) stop(glue("Other dimensions not yet supported: {paste(dims_other, collapse = ',')}"))
debug: names(r) <- lyrs
debug: if (!is.null(rast_tif)) {
    if (fs::file_exists(rast_tif)) {
        r_tmp_tif <- tempfile(fileext = ".tif")
        r_tmp <- c(rast(rast_tif), r)
        r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
        terra::writeRaster(r_tmp, r_tmp_tif)
        fs::file_delete(rast_tif)
        fs::file_move(r_tmp_tif, rast_tif)
        rm(r)
        rm(r_tmp)
    }
    else {
        terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
    }
    r <- terra::rast(rast_tif)
}
debug: if (fs::file_exists(rast_tif)) {
    r_tmp_tif <- tempfile(fileext = ".tif")
    r_tmp <- c(rast(rast_tif), r)
    r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
    terra::writeRaster(r_tmp, r_tmp_tif)
    fs::file_delete(rast_tif)
    fs::file_move(r_tmp_tif, rast_tif)
    rm(r)
    rm(r_tmp)
} else {
    terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
}
debug: terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
debug: r <- terra::rast(rast_tif)
debug: d_r <- mutate(tidyr::pivot_longer(sf::st_drop_geometry(sf::st_as_sf(terra::zonal(x = r, 
    z = terra::vect(dplyr::select(sf_zones, dplyr::all_of(fld_zones))), 
    fun = zonal_fun, exact = T, na.rm = T, as.polygons = T))), 
    cols = -dplyr::any_of(fld_zones), names_to = "lyr", values_to = zonal_fun), 
    time = readr::parse_datetime(str_replace(lyr, glue("{var}\\|(.*)"), 
        "\\1")))
debug: if (!is.null(zonal_csv)) write_csv(d_r, zonal_csv)
debug: write_csv(d_r, zonal_csv)
debug: if (!keep_nc) unlink(dir_nc, recursive = T)
debug: unlink(dir_nc, recursive = T)
debug: return(d_r)
Downloading 1 requests, up to 67 time slices each
Called from: extractr::ed_extract(ed, var = v, sf_zones = ply, bbox = bb, 
    mask_tif = F, rast_tif = glue("{dir_out}/{nms}/{yr}.tif"), 
    zonal_fun = "mean", zonal_csv = glue("{dir_out}/{nms}/{yr}.csv"), 
    dir_nc = glue("{dir_out}/{nms}/{yr}_nc"), keep_nc = F, n_max_vals_per_req = 1e+05, 
    time_min = time_min, time_max = time_max, verbose = T)
debug: while (i_req <= n_reqs) {
    i_t_beg <- (i_req - 1) * n_t_per_req + 1
    i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
    t_req <- times_todo[c(i_t_beg, i_t_end)]
    t_req_str <- format_ISO8601(t_req, usetz = "Z")
    if (verbose) 
        message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
    ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
        ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
        0), nc)
    unlink(ncs0)
    nc_retry <- T
    nc_n_try <- 1
    n_max_retries
    while (nc_retry) {
        res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
            url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
                bbox[["xmax"]]), latitude = c(bbox[["ymin"]], 
                bbox[["ymax"]]), time = t_req_str, fmt = "nc", 
            store = rerddap::disk(path = dir_nc)))
        if (inherits(res, "try-error")) {
            err <- attr(res, "condition")
            msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
            nc_n_try <- nc_n_try + 1
            if (nc_n_try > n_max_retries) {
                stop(msg)
            }
            else {
                message(msg, "\nRETRYing...")
                Sys.sleep(1)
            }
        }
        else {
            nc_retry <- F
        }
    }
    i_req <- i_req + 1
}
debug: i_t_beg <- (i_req - 1) * n_t_per_req + 1
debug: i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
debug: t_req <- times_todo[c(i_t_beg, i_t_end)]
debug: t_req_str <- format_ISO8601(t_req, usetz = "Z")
debug: if (verbose) message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
debug: message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
Fetching request 1 of 1 (2022-01-01 to 2022-12-01) ~ 19:39:23 UTC
debug: ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
    0), nc)
debug: unlink(ncs0)
debug: nc_retry <- T
debug: nc_n_try <- 1
debug: n_max_retries
debug: while (nc_retry) {
    res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
        url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
            bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
        time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
    if (inherits(res, "try-error")) {
        err <- attr(res, "condition")
        msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
        nc_n_try <- nc_n_try + 1
        if (nc_n_try > n_max_retries) {
            stop(msg)
        }
        else {
            message(msg, "\nRETRYing...")
            Sys.sleep(1)
        }
    }
    else {
        nc_retry <- F
    }
}
debug: res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
    url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
        bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
    time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
debug: if (inherits(res, "try-error")) {
    err <- attr(res, "condition")
    msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
    nc_n_try <- nc_n_try + 1
    if (nc_n_try > n_max_retries) {
        stop(msg)
    }
    else {
        message(msg, "\nRETRYing...")
        Sys.sleep(1)
    }
} else {
    nc_retry <- F
}
debug: nc_retry <- F
debug: (while) nc_retry
debug: i_req <- i_req + 1
debug: (while) i_req <= n_reqs
debug: ncs <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size > 
    0), nc)
debug: r <- terra::rast(ncs)
debug: stopifnot(all(class(terra::time(r)) %in% c("POSIXct", "POSIXt")))
debug: idx <- dplyr::pull(dplyr::filter(dplyr::arrange(dplyr::tibble(idx = 1:terra::nlyr(r), 
    time = terra::time(r)), time), !duplicated(time)), idx)
debug: r <- terra::subset(r, idx)
debug: stopifnot(terra::crs(r, proj = T) == wgs84)
debug: if (mask_tif) r <- terra::mask(r, sf_zones)
debug: lyrs <- glue("{var}|{terra::time(r)}")
debug: if (length(dims_other) > 0 && !all(length(dims[dims_other]) == 
    1)) stop(glue("Other dimensions not yet supported: {paste(dims_other, collapse = ',')}"))
debug: names(r) <- lyrs
debug: if (!is.null(rast_tif)) {
    if (fs::file_exists(rast_tif)) {
        r_tmp_tif <- tempfile(fileext = ".tif")
        r_tmp <- c(rast(rast_tif), r)
        r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
        terra::writeRaster(r_tmp, r_tmp_tif)
        fs::file_delete(rast_tif)
        fs::file_move(r_tmp_tif, rast_tif)
        rm(r)
        rm(r_tmp)
    }
    else {
        terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
    }
    r <- terra::rast(rast_tif)
}
debug: if (fs::file_exists(rast_tif)) {
    r_tmp_tif <- tempfile(fileext = ".tif")
    r_tmp <- c(rast(rast_tif), r)
    r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
    terra::writeRaster(r_tmp, r_tmp_tif)
    fs::file_delete(rast_tif)
    fs::file_move(r_tmp_tif, rast_tif)
    rm(r)
    rm(r_tmp)
} else {
    terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
}
debug: terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
debug: r <- terra::rast(rast_tif)
debug: d_r <- mutate(tidyr::pivot_longer(sf::st_drop_geometry(sf::st_as_sf(terra::zonal(x = r, 
    z = terra::vect(dplyr::select(sf_zones, dplyr::all_of(fld_zones))), 
    fun = zonal_fun, exact = T, na.rm = T, as.polygons = T))), 
    cols = -dplyr::any_of(fld_zones), names_to = "lyr", values_to = zonal_fun), 
    time = readr::parse_datetime(str_replace(lyr, glue("{var}\\|(.*)"), 
        "\\1")))
debug: if (!is.null(zonal_csv)) write_csv(d_r, zonal_csv)
debug: write_csv(d_r, zonal_csv)
debug: if (!keep_nc) unlink(dir_nc, recursive = T)
debug: unlink(dir_nc, recursive = T)
debug: return(d_r)
Downloading 1 requests, up to 67 time slices each
Called from: extractr::ed_extract(ed, var = v, sf_zones = ply, bbox = bb, 
    mask_tif = F, rast_tif = glue("{dir_out}/{nms}/{yr}.tif"), 
    zonal_fun = "mean", zonal_csv = glue("{dir_out}/{nms}/{yr}.csv"), 
    dir_nc = glue("{dir_out}/{nms}/{yr}_nc"), keep_nc = F, n_max_vals_per_req = 1e+05, 
    time_min = time_min, time_max = time_max, verbose = T)
debug: while (i_req <= n_reqs) {
    i_t_beg <- (i_req - 1) * n_t_per_req + 1
    i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
    t_req <- times_todo[c(i_t_beg, i_t_end)]
    t_req_str <- format_ISO8601(t_req, usetz = "Z")
    if (verbose) 
        message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
    ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
        ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
        0), nc)
    unlink(ncs0)
    nc_retry <- T
    nc_n_try <- 1
    n_max_retries
    while (nc_retry) {
        res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
            url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
                bbox[["xmax"]]), latitude = c(bbox[["ymin"]], 
                bbox[["ymax"]]), time = t_req_str, fmt = "nc", 
            store = rerddap::disk(path = dir_nc)))
        if (inherits(res, "try-error")) {
            err <- attr(res, "condition")
            msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
            nc_n_try <- nc_n_try + 1
            if (nc_n_try > n_max_retries) {
                stop(msg)
            }
            else {
                message(msg, "\nRETRYing...")
                Sys.sleep(1)
            }
        }
        else {
            nc_retry <- F
        }
    }
    i_req <- i_req + 1
}
debug: i_t_beg <- (i_req - 1) * n_t_per_req + 1
debug: i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
debug: t_req <- times_todo[c(i_t_beg, i_t_end)]
debug: t_req_str <- format_ISO8601(t_req, usetz = "Z")
debug: if (verbose) message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
debug: message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
Fetching request 1 of 1 (2023-01-01 to 2023-12-01) ~ 19:39:25 UTC
debug: ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
    0), nc)
debug: unlink(ncs0)
debug: nc_retry <- T
debug: nc_n_try <- 1
debug: n_max_retries
debug: while (nc_retry) {
    res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
        url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
            bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
        time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
    if (inherits(res, "try-error")) {
        err <- attr(res, "condition")
        msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
        nc_n_try <- nc_n_try + 1
        if (nc_n_try > n_max_retries) {
            stop(msg)
        }
        else {
            message(msg, "\nRETRYing...")
            Sys.sleep(1)
        }
    }
    else {
        nc_retry <- F
    }
}
debug: res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
    url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
        bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
    time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
debug: if (inherits(res, "try-error")) {
    err <- attr(res, "condition")
    msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
    nc_n_try <- nc_n_try + 1
    if (nc_n_try > n_max_retries) {
        stop(msg)
    }
    else {
        message(msg, "\nRETRYing...")
        Sys.sleep(1)
    }
} else {
    nc_retry <- F
}
debug: nc_retry <- F
debug: (while) nc_retry
debug: i_req <- i_req + 1
debug: (while) i_req <= n_reqs
debug: ncs <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size > 
    0), nc)
debug: r <- terra::rast(ncs)
debug: stopifnot(all(class(terra::time(r)) %in% c("POSIXct", "POSIXt")))
debug: idx <- dplyr::pull(dplyr::filter(dplyr::arrange(dplyr::tibble(idx = 1:terra::nlyr(r), 
    time = terra::time(r)), time), !duplicated(time)), idx)
debug: r <- terra::subset(r, idx)
debug: stopifnot(terra::crs(r, proj = T) == wgs84)
debug: if (mask_tif) r <- terra::mask(r, sf_zones)
debug: lyrs <- glue("{var}|{terra::time(r)}")
debug: if (length(dims_other) > 0 && !all(length(dims[dims_other]) == 
    1)) stop(glue("Other dimensions not yet supported: {paste(dims_other, collapse = ',')}"))
debug: names(r) <- lyrs
debug: if (!is.null(rast_tif)) {
    if (fs::file_exists(rast_tif)) {
        r_tmp_tif <- tempfile(fileext = ".tif")
        r_tmp <- c(rast(rast_tif), r)
        r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
        terra::writeRaster(r_tmp, r_tmp_tif)
        fs::file_delete(rast_tif)
        fs::file_move(r_tmp_tif, rast_tif)
        rm(r)
        rm(r_tmp)
    }
    else {
        terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
    }
    r <- terra::rast(rast_tif)
}
debug: if (fs::file_exists(rast_tif)) {
    r_tmp_tif <- tempfile(fileext = ".tif")
    r_tmp <- c(rast(rast_tif), r)
    r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
    terra::writeRaster(r_tmp, r_tmp_tif)
    fs::file_delete(rast_tif)
    fs::file_move(r_tmp_tif, rast_tif)
    rm(r)
    rm(r_tmp)
} else {
    terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
}
debug: terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
debug: r <- terra::rast(rast_tif)
debug: d_r <- mutate(tidyr::pivot_longer(sf::st_drop_geometry(sf::st_as_sf(terra::zonal(x = r, 
    z = terra::vect(dplyr::select(sf_zones, dplyr::all_of(fld_zones))), 
    fun = zonal_fun, exact = T, na.rm = T, as.polygons = T))), 
    cols = -dplyr::any_of(fld_zones), names_to = "lyr", values_to = zonal_fun), 
    time = readr::parse_datetime(str_replace(lyr, glue("{var}\\|(.*)"), 
        "\\1")))
debug: if (!is.null(zonal_csv)) write_csv(d_r, zonal_csv)
debug: write_csv(d_r, zonal_csv)
debug: if (!keep_nc) unlink(dir_nc, recursive = T)
debug: unlink(dir_nc, recursive = T)
debug: return(d_r)
Downloading 1 requests, up to 67 time slices each
Called from: extractr::ed_extract(ed, var = v, sf_zones = ply, bbox = bb, 
    mask_tif = F, rast_tif = glue("{dir_out}/{nms}/{yr}.tif"), 
    zonal_fun = "mean", zonal_csv = glue("{dir_out}/{nms}/{yr}.csv"), 
    dir_nc = glue("{dir_out}/{nms}/{yr}_nc"), keep_nc = F, n_max_vals_per_req = 1e+05, 
    time_min = time_min, time_max = time_max, verbose = T)
debug: while (i_req <= n_reqs) {
    i_t_beg <- (i_req - 1) * n_t_per_req + 1
    i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
    t_req <- times_todo[c(i_t_beg, i_t_end)]
    t_req_str <- format_ISO8601(t_req, usetz = "Z")
    if (verbose) 
        message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
    ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
        ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
        0), nc)
    unlink(ncs0)
    nc_retry <- T
    nc_n_try <- 1
    n_max_retries
    while (nc_retry) {
        res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
            url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
                bbox[["xmax"]]), latitude = c(bbox[["ymin"]], 
                bbox[["ymax"]]), time = t_req_str, fmt = "nc", 
            store = rerddap::disk(path = dir_nc)))
        if (inherits(res, "try-error")) {
            err <- attr(res, "condition")
            msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
            nc_n_try <- nc_n_try + 1
            if (nc_n_try > n_max_retries) {
                stop(msg)
            }
            else {
                message(msg, "\nRETRYing...")
                Sys.sleep(1)
            }
        }
        else {
            nc_retry <- F
        }
    }
    i_req <- i_req + 1
}
debug: i_t_beg <- (i_req - 1) * n_t_per_req + 1
debug: i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
debug: t_req <- times_todo[c(i_t_beg, i_t_end)]
debug: t_req_str <- format_ISO8601(t_req, usetz = "Z")
debug: if (verbose) message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
debug: message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
Fetching request 1 of 1 (2024-01-01 to 2024-12-01) ~ 19:39:27 UTC
debug: ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
    0), nc)
debug: unlink(ncs0)
debug: nc_retry <- T
debug: nc_n_try <- 1
debug: n_max_retries
debug: while (nc_retry) {
    res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
        url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
            bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
        time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
    if (inherits(res, "try-error")) {
        err <- attr(res, "condition")
        msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
        nc_n_try <- nc_n_try + 1
        if (nc_n_try > n_max_retries) {
            stop(msg)
        }
        else {
            message(msg, "\nRETRYing...")
            Sys.sleep(1)
        }
    }
    else {
        nc_retry <- F
    }
}
debug: res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
    url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
        bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
    time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
debug: if (inherits(res, "try-error")) {
    err <- attr(res, "condition")
    msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
    nc_n_try <- nc_n_try + 1
    if (nc_n_try > n_max_retries) {
        stop(msg)
    }
    else {
        message(msg, "\nRETRYing...")
        Sys.sleep(1)
    }
} else {
    nc_retry <- F
}
debug: nc_retry <- F
debug: (while) nc_retry
debug: i_req <- i_req + 1
debug: (while) i_req <= n_reqs
debug: ncs <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size > 
    0), nc)
debug: r <- terra::rast(ncs)
debug: stopifnot(all(class(terra::time(r)) %in% c("POSIXct", "POSIXt")))
debug: idx <- dplyr::pull(dplyr::filter(dplyr::arrange(dplyr::tibble(idx = 1:terra::nlyr(r), 
    time = terra::time(r)), time), !duplicated(time)), idx)
debug: r <- terra::subset(r, idx)
debug: stopifnot(terra::crs(r, proj = T) == wgs84)
debug: if (mask_tif) r <- terra::mask(r, sf_zones)
debug: lyrs <- glue("{var}|{terra::time(r)}")
debug: if (length(dims_other) > 0 && !all(length(dims[dims_other]) == 
    1)) stop(glue("Other dimensions not yet supported: {paste(dims_other, collapse = ',')}"))
debug: names(r) <- lyrs
debug: if (!is.null(rast_tif)) {
    if (fs::file_exists(rast_tif)) {
        r_tmp_tif <- tempfile(fileext = ".tif")
        r_tmp <- c(rast(rast_tif), r)
        r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
        terra::writeRaster(r_tmp, r_tmp_tif)
        fs::file_delete(rast_tif)
        fs::file_move(r_tmp_tif, rast_tif)
        rm(r)
        rm(r_tmp)
    }
    else {
        terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
    }
    r <- terra::rast(rast_tif)
}
debug: if (fs::file_exists(rast_tif)) {
    r_tmp_tif <- tempfile(fileext = ".tif")
    r_tmp <- c(rast(rast_tif), r)
    r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
    terra::writeRaster(r_tmp, r_tmp_tif)
    fs::file_delete(rast_tif)
    fs::file_move(r_tmp_tif, rast_tif)
    rm(r)
    rm(r_tmp)
} else {
    terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
}
debug: terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
debug: r <- terra::rast(rast_tif)
debug: d_r <- mutate(tidyr::pivot_longer(sf::st_drop_geometry(sf::st_as_sf(terra::zonal(x = r, 
    z = terra::vect(dplyr::select(sf_zones, dplyr::all_of(fld_zones))), 
    fun = zonal_fun, exact = T, na.rm = T, as.polygons = T))), 
    cols = -dplyr::any_of(fld_zones), names_to = "lyr", values_to = zonal_fun), 
    time = readr::parse_datetime(str_replace(lyr, glue("{var}\\|(.*)"), 
        "\\1")))
debug: if (!is.null(zonal_csv)) write_csv(d_r, zonal_csv)
debug: write_csv(d_r, zonal_csv)
debug: if (!keep_nc) unlink(dir_nc, recursive = T)
debug: unlink(dir_nc, recursive = T)
debug: return(d_r)
Downloading 1 requests, up to 67 time slices each
Called from: extractr::ed_extract(ed, var = v, sf_zones = ply, bbox = bb, 
    mask_tif = F, rast_tif = glue("{dir_out}/{nms}/{yr}.tif"), 
    zonal_fun = "mean", zonal_csv = glue("{dir_out}/{nms}/{yr}.csv"), 
    dir_nc = glue("{dir_out}/{nms}/{yr}_nc"), keep_nc = F, n_max_vals_per_req = 1e+05, 
    time_min = time_min, time_max = time_max, verbose = T)
debug: while (i_req <= n_reqs) {
    i_t_beg <- (i_req - 1) * n_t_per_req + 1
    i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
    t_req <- times_todo[c(i_t_beg, i_t_end)]
    t_req_str <- format_ISO8601(t_req, usetz = "Z")
    if (verbose) 
        message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
    ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
        ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
        0), nc)
    unlink(ncs0)
    nc_retry <- T
    nc_n_try <- 1
    n_max_retries
    while (nc_retry) {
        res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
            url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
                bbox[["xmax"]]), latitude = c(bbox[["ymin"]], 
                bbox[["ymax"]]), time = t_req_str, fmt = "nc", 
            store = rerddap::disk(path = dir_nc)))
        if (inherits(res, "try-error")) {
            err <- attr(res, "condition")
            msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
            nc_n_try <- nc_n_try + 1
            if (nc_n_try > n_max_retries) {
                stop(msg)
            }
            else {
                message(msg, "\nRETRYing...")
                Sys.sleep(1)
            }
        }
        else {
            nc_retry <- F
        }
    }
    i_req <- i_req + 1
}
debug: i_t_beg <- (i_req - 1) * n_t_per_req + 1
debug: i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
debug: t_req <- times_todo[c(i_t_beg, i_t_end)]
debug: t_req_str <- format_ISO8601(t_req, usetz = "Z")
debug: if (verbose) message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
debug: message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
Fetching request 1 of 1 (2025-01-01 to 2025-07-01) ~ 19:39:29 UTC
debug: ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
    0), nc)
debug: unlink(ncs0)
debug: nc_retry <- T
debug: nc_n_try <- 1
debug: n_max_retries
debug: while (nc_retry) {
    res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
        url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
            bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
        time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
    if (inherits(res, "try-error")) {
        err <- attr(res, "condition")
        msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
        nc_n_try <- nc_n_try + 1
        if (nc_n_try > n_max_retries) {
            stop(msg)
        }
        else {
            message(msg, "\nRETRYing...")
            Sys.sleep(1)
        }
    }
    else {
        nc_retry <- F
    }
}
debug: res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
    url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
        bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
    time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
debug: if (inherits(res, "try-error")) {
    err <- attr(res, "condition")
    msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
    nc_n_try <- nc_n_try + 1
    if (nc_n_try > n_max_retries) {
        stop(msg)
    }
    else {
        message(msg, "\nRETRYing...")
        Sys.sleep(1)
    }
} else {
    nc_retry <- F
}
debug: nc_retry <- F
debug: (while) nc_retry
debug: i_req <- i_req + 1
debug: (while) i_req <= n_reqs
debug: ncs <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size > 
    0), nc)
debug: r <- terra::rast(ncs)
debug: stopifnot(all(class(terra::time(r)) %in% c("POSIXct", "POSIXt")))
debug: idx <- dplyr::pull(dplyr::filter(dplyr::arrange(dplyr::tibble(idx = 1:terra::nlyr(r), 
    time = terra::time(r)), time), !duplicated(time)), idx)
debug: r <- terra::subset(r, idx)
debug: stopifnot(terra::crs(r, proj = T) == wgs84)
debug: if (mask_tif) r <- terra::mask(r, sf_zones)
debug: lyrs <- glue("{var}|{terra::time(r)}")
debug: if (length(dims_other) > 0 && !all(length(dims[dims_other]) == 
    1)) stop(glue("Other dimensions not yet supported: {paste(dims_other, collapse = ',')}"))
debug: names(r) <- lyrs
debug: if (!is.null(rast_tif)) {
    if (fs::file_exists(rast_tif)) {
        r_tmp_tif <- tempfile(fileext = ".tif")
        r_tmp <- c(rast(rast_tif), r)
        r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
        terra::writeRaster(r_tmp, r_tmp_tif)
        fs::file_delete(rast_tif)
        fs::file_move(r_tmp_tif, rast_tif)
        rm(r)
        rm(r_tmp)
    }
    else {
        terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
    }
    r <- terra::rast(rast_tif)
}
debug: if (fs::file_exists(rast_tif)) {
    r_tmp_tif <- tempfile(fileext = ".tif")
    r_tmp <- c(rast(rast_tif), r)
    r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
    terra::writeRaster(r_tmp, r_tmp_tif)
    fs::file_delete(rast_tif)
    fs::file_move(r_tmp_tif, rast_tif)
    rm(r)
    rm(r_tmp)
} else {
    terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
}
debug: terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
debug: r <- terra::rast(rast_tif)
debug: d_r <- mutate(tidyr::pivot_longer(sf::st_drop_geometry(sf::st_as_sf(terra::zonal(x = r, 
    z = terra::vect(dplyr::select(sf_zones, dplyr::all_of(fld_zones))), 
    fun = zonal_fun, exact = T, na.rm = T, as.polygons = T))), 
    cols = -dplyr::any_of(fld_zones), names_to = "lyr", values_to = zonal_fun), 
    time = readr::parse_datetime(str_replace(lyr, glue("{var}\\|(.*)"), 
        "\\1")))
debug: if (!is.null(zonal_csv)) write_csv(d_r, zonal_csv)
debug: write_csv(d_r, zonal_csv)
debug: if (!keep_nc) unlink(dir_nc, recursive = T)
debug: unlink(dir_nc, recursive = T)
debug: return(d_r)
Downloading 1 requests, up to 111 time slices each
Called from: extractr::ed_extract(ed, var = v, sf_zones = ply, bbox = bb, 
    mask_tif = F, rast_tif = glue("{dir_out}/{nms}/{yr}.tif"), 
    zonal_fun = "mean", zonal_csv = glue("{dir_out}/{nms}/{yr}.csv"), 
    dir_nc = glue("{dir_out}/{nms}/{yr}_nc"), keep_nc = F, n_max_vals_per_req = 1e+05, 
    time_min = time_min, time_max = time_max, verbose = T)
debug: while (i_req <= n_reqs) {
    i_t_beg <- (i_req - 1) * n_t_per_req + 1
    i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
    t_req <- times_todo[c(i_t_beg, i_t_end)]
    t_req_str <- format_ISO8601(t_req, usetz = "Z")
    if (verbose) 
        message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
    ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
        ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
        0), nc)
    unlink(ncs0)
    nc_retry <- T
    nc_n_try <- 1
    n_max_retries
    while (nc_retry) {
        res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
            url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
                bbox[["xmax"]]), latitude = c(bbox[["ymin"]], 
                bbox[["ymax"]]), time = t_req_str, fmt = "nc", 
            store = rerddap::disk(path = dir_nc)))
        if (inherits(res, "try-error")) {
            err <- attr(res, "condition")
            msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
            nc_n_try <- nc_n_try + 1
            if (nc_n_try > n_max_retries) {
                stop(msg)
            }
            else {
                message(msg, "\nRETRYing...")
                Sys.sleep(1)
            }
        }
        else {
            nc_retry <- F
        }
    }
    i_req <- i_req + 1
}
debug: i_t_beg <- (i_req - 1) * n_t_per_req + 1
debug: i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
debug: t_req <- times_todo[c(i_t_beg, i_t_end)]
debug: t_req_str <- format_ISO8601(t_req, usetz = "Z")
debug: if (verbose) message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
debug: message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
Fetching request 1 of 1 (1998-01-01 to 1998-12-01) ~ 19:39:31 UTC
debug: ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
    0), nc)
debug: unlink(ncs0)
debug: nc_retry <- T
debug: nc_n_try <- 1
debug: n_max_retries
debug: while (nc_retry) {
    res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
        url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
            bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
        time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
    if (inherits(res, "try-error")) {
        err <- attr(res, "condition")
        msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
        nc_n_try <- nc_n_try + 1
        if (nc_n_try > n_max_retries) {
            stop(msg)
        }
        else {
            message(msg, "\nRETRYing...")
            Sys.sleep(1)
        }
    }
    else {
        nc_retry <- F
    }
}
debug: res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
    url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
        bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
    time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
debug: if (inherits(res, "try-error")) {
    err <- attr(res, "condition")
    msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
    nc_n_try <- nc_n_try + 1
    if (nc_n_try > n_max_retries) {
        stop(msg)
    }
    else {
        message(msg, "\nRETRYing...")
        Sys.sleep(1)
    }
} else {
    nc_retry <- F
}
debug: nc_retry <- F
debug: (while) nc_retry
debug: i_req <- i_req + 1
debug: (while) i_req <= n_reqs
debug: ncs <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size > 
    0), nc)
debug: r <- terra::rast(ncs)
debug: stopifnot(all(class(terra::time(r)) %in% c("POSIXct", "POSIXt")))
debug: idx <- dplyr::pull(dplyr::filter(dplyr::arrange(dplyr::tibble(idx = 1:terra::nlyr(r), 
    time = terra::time(r)), time), !duplicated(time)), idx)
debug: r <- terra::subset(r, idx)
debug: stopifnot(terra::crs(r, proj = T) == wgs84)
debug: if (mask_tif) r <- terra::mask(r, sf_zones)
debug: lyrs <- glue("{var}|{terra::time(r)}")
debug: if (length(dims_other) > 0 && !all(length(dims[dims_other]) == 
    1)) stop(glue("Other dimensions not yet supported: {paste(dims_other, collapse = ',')}"))
debug: names(r) <- lyrs
debug: if (!is.null(rast_tif)) {
    if (fs::file_exists(rast_tif)) {
        r_tmp_tif <- tempfile(fileext = ".tif")
        r_tmp <- c(rast(rast_tif), r)
        r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
        terra::writeRaster(r_tmp, r_tmp_tif)
        fs::file_delete(rast_tif)
        fs::file_move(r_tmp_tif, rast_tif)
        rm(r)
        rm(r_tmp)
    }
    else {
        terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
    }
    r <- terra::rast(rast_tif)
}
debug: if (fs::file_exists(rast_tif)) {
    r_tmp_tif <- tempfile(fileext = ".tif")
    r_tmp <- c(rast(rast_tif), r)
    r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
    terra::writeRaster(r_tmp, r_tmp_tif)
    fs::file_delete(rast_tif)
    fs::file_move(r_tmp_tif, rast_tif)
    rm(r)
    rm(r_tmp)
} else {
    terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
}
debug: terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
debug: r <- terra::rast(rast_tif)
debug: d_r <- mutate(tidyr::pivot_longer(sf::st_drop_geometry(sf::st_as_sf(terra::zonal(x = r, 
    z = terra::vect(dplyr::select(sf_zones, dplyr::all_of(fld_zones))), 
    fun = zonal_fun, exact = T, na.rm = T, as.polygons = T))), 
    cols = -dplyr::any_of(fld_zones), names_to = "lyr", values_to = zonal_fun), 
    time = readr::parse_datetime(str_replace(lyr, glue("{var}\\|(.*)"), 
        "\\1")))
debug: if (!is.null(zonal_csv)) write_csv(d_r, zonal_csv)
debug: write_csv(d_r, zonal_csv)
debug: if (!keep_nc) unlink(dir_nc, recursive = T)
debug: unlink(dir_nc, recursive = T)
debug: return(d_r)
Downloading 1 requests, up to 111 time slices each
Called from: extractr::ed_extract(ed, var = v, sf_zones = ply, bbox = bb, 
    mask_tif = F, rast_tif = glue("{dir_out}/{nms}/{yr}.tif"), 
    zonal_fun = "mean", zonal_csv = glue("{dir_out}/{nms}/{yr}.csv"), 
    dir_nc = glue("{dir_out}/{nms}/{yr}_nc"), keep_nc = F, n_max_vals_per_req = 1e+05, 
    time_min = time_min, time_max = time_max, verbose = T)
debug: while (i_req <= n_reqs) {
    i_t_beg <- (i_req - 1) * n_t_per_req + 1
    i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
    t_req <- times_todo[c(i_t_beg, i_t_end)]
    t_req_str <- format_ISO8601(t_req, usetz = "Z")
    if (verbose) 
        message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
    ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
        ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
        0), nc)
    unlink(ncs0)
    nc_retry <- T
    nc_n_try <- 1
    n_max_retries
    while (nc_retry) {
        res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
            url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
                bbox[["xmax"]]), latitude = c(bbox[["ymin"]], 
                bbox[["ymax"]]), time = t_req_str, fmt = "nc", 
            store = rerddap::disk(path = dir_nc)))
        if (inherits(res, "try-error")) {
            err <- attr(res, "condition")
            msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
            nc_n_try <- nc_n_try + 1
            if (nc_n_try > n_max_retries) {
                stop(msg)
            }
            else {
                message(msg, "\nRETRYing...")
                Sys.sleep(1)
            }
        }
        else {
            nc_retry <- F
        }
    }
    i_req <- i_req + 1
}
debug: i_t_beg <- (i_req - 1) * n_t_per_req + 1
debug: i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
debug: t_req <- times_todo[c(i_t_beg, i_t_end)]
debug: t_req_str <- format_ISO8601(t_req, usetz = "Z")
debug: if (verbose) message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
debug: message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
Fetching request 1 of 1 (1999-01-01 to 1999-12-01) ~ 19:39:32 UTC
debug: ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
    0), nc)
debug: unlink(ncs0)
debug: nc_retry <- T
debug: nc_n_try <- 1
debug: n_max_retries
debug: while (nc_retry) {
    res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
        url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
            bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
        time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
    if (inherits(res, "try-error")) {
        err <- attr(res, "condition")
        msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
        nc_n_try <- nc_n_try + 1
        if (nc_n_try > n_max_retries) {
            stop(msg)
        }
        else {
            message(msg, "\nRETRYing...")
            Sys.sleep(1)
        }
    }
    else {
        nc_retry <- F
    }
}
debug: res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
    url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
        bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
    time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
debug: if (inherits(res, "try-error")) {
    err <- attr(res, "condition")
    msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
    nc_n_try <- nc_n_try + 1
    if (nc_n_try > n_max_retries) {
        stop(msg)
    }
    else {
        message(msg, "\nRETRYing...")
        Sys.sleep(1)
    }
} else {
    nc_retry <- F
}
debug: nc_retry <- F
debug: (while) nc_retry
debug: i_req <- i_req + 1
debug: (while) i_req <= n_reqs
debug: ncs <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size > 
    0), nc)
debug: r <- terra::rast(ncs)
debug: stopifnot(all(class(terra::time(r)) %in% c("POSIXct", "POSIXt")))
debug: idx <- dplyr::pull(dplyr::filter(dplyr::arrange(dplyr::tibble(idx = 1:terra::nlyr(r), 
    time = terra::time(r)), time), !duplicated(time)), idx)
debug: r <- terra::subset(r, idx)
debug: stopifnot(terra::crs(r, proj = T) == wgs84)
debug: if (mask_tif) r <- terra::mask(r, sf_zones)
debug: lyrs <- glue("{var}|{terra::time(r)}")
debug: if (length(dims_other) > 0 && !all(length(dims[dims_other]) == 
    1)) stop(glue("Other dimensions not yet supported: {paste(dims_other, collapse = ',')}"))
debug: names(r) <- lyrs
debug: if (!is.null(rast_tif)) {
    if (fs::file_exists(rast_tif)) {
        r_tmp_tif <- tempfile(fileext = ".tif")
        r_tmp <- c(rast(rast_tif), r)
        r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
        terra::writeRaster(r_tmp, r_tmp_tif)
        fs::file_delete(rast_tif)
        fs::file_move(r_tmp_tif, rast_tif)
        rm(r)
        rm(r_tmp)
    }
    else {
        terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
    }
    r <- terra::rast(rast_tif)
}
debug: if (fs::file_exists(rast_tif)) {
    r_tmp_tif <- tempfile(fileext = ".tif")
    r_tmp <- c(rast(rast_tif), r)
    r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
    terra::writeRaster(r_tmp, r_tmp_tif)
    fs::file_delete(rast_tif)
    fs::file_move(r_tmp_tif, rast_tif)
    rm(r)
    rm(r_tmp)
} else {
    terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
}
debug: terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
debug: r <- terra::rast(rast_tif)
debug: d_r <- mutate(tidyr::pivot_longer(sf::st_drop_geometry(sf::st_as_sf(terra::zonal(x = r, 
    z = terra::vect(dplyr::select(sf_zones, dplyr::all_of(fld_zones))), 
    fun = zonal_fun, exact = T, na.rm = T, as.polygons = T))), 
    cols = -dplyr::any_of(fld_zones), names_to = "lyr", values_to = zonal_fun), 
    time = readr::parse_datetime(str_replace(lyr, glue("{var}\\|(.*)"), 
        "\\1")))
debug: if (!is.null(zonal_csv)) write_csv(d_r, zonal_csv)
debug: write_csv(d_r, zonal_csv)
debug: if (!keep_nc) unlink(dir_nc, recursive = T)
debug: unlink(dir_nc, recursive = T)
debug: return(d_r)
Downloading 1 requests, up to 111 time slices each
Called from: extractr::ed_extract(ed, var = v, sf_zones = ply, bbox = bb, 
    mask_tif = F, rast_tif = glue("{dir_out}/{nms}/{yr}.tif"), 
    zonal_fun = "mean", zonal_csv = glue("{dir_out}/{nms}/{yr}.csv"), 
    dir_nc = glue("{dir_out}/{nms}/{yr}_nc"), keep_nc = F, n_max_vals_per_req = 1e+05, 
    time_min = time_min, time_max = time_max, verbose = T)
debug: while (i_req <= n_reqs) {
    i_t_beg <- (i_req - 1) * n_t_per_req + 1
    i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
    t_req <- times_todo[c(i_t_beg, i_t_end)]
    t_req_str <- format_ISO8601(t_req, usetz = "Z")
    if (verbose) 
        message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
    ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
        ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
        0), nc)
    unlink(ncs0)
    nc_retry <- T
    nc_n_try <- 1
    n_max_retries
    while (nc_retry) {
        res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
            url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
                bbox[["xmax"]]), latitude = c(bbox[["ymin"]], 
                bbox[["ymax"]]), time = t_req_str, fmt = "nc", 
            store = rerddap::disk(path = dir_nc)))
        if (inherits(res, "try-error")) {
            err <- attr(res, "condition")
            msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
            nc_n_try <- nc_n_try + 1
            if (nc_n_try > n_max_retries) {
                stop(msg)
            }
            else {
                message(msg, "\nRETRYing...")
                Sys.sleep(1)
            }
        }
        else {
            nc_retry <- F
        }
    }
    i_req <- i_req + 1
}
debug: i_t_beg <- (i_req - 1) * n_t_per_req + 1
debug: i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
debug: t_req <- times_todo[c(i_t_beg, i_t_end)]
debug: t_req_str <- format_ISO8601(t_req, usetz = "Z")
debug: if (verbose) message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
debug: message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
Fetching request 1 of 1 (2000-01-01 to 2000-12-01) ~ 19:39:34 UTC
debug: ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
    0), nc)
debug: unlink(ncs0)
debug: nc_retry <- T
debug: nc_n_try <- 1
debug: n_max_retries
debug: while (nc_retry) {
    res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
        url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
            bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
        time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
    if (inherits(res, "try-error")) {
        err <- attr(res, "condition")
        msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
        nc_n_try <- nc_n_try + 1
        if (nc_n_try > n_max_retries) {
            stop(msg)
        }
        else {
            message(msg, "\nRETRYing...")
            Sys.sleep(1)
        }
    }
    else {
        nc_retry <- F
    }
}
debug: res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
    url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
        bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
    time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
debug: if (inherits(res, "try-error")) {
    err <- attr(res, "condition")
    msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
    nc_n_try <- nc_n_try + 1
    if (nc_n_try > n_max_retries) {
        stop(msg)
    }
    else {
        message(msg, "\nRETRYing...")
        Sys.sleep(1)
    }
} else {
    nc_retry <- F
}
debug: nc_retry <- F
debug: (while) nc_retry
debug: i_req <- i_req + 1
debug: (while) i_req <= n_reqs
debug: ncs <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size > 
    0), nc)
debug: r <- terra::rast(ncs)
debug: stopifnot(all(class(terra::time(r)) %in% c("POSIXct", "POSIXt")))
debug: idx <- dplyr::pull(dplyr::filter(dplyr::arrange(dplyr::tibble(idx = 1:terra::nlyr(r), 
    time = terra::time(r)), time), !duplicated(time)), idx)
debug: r <- terra::subset(r, idx)
debug: stopifnot(terra::crs(r, proj = T) == wgs84)
debug: if (mask_tif) r <- terra::mask(r, sf_zones)
debug: lyrs <- glue("{var}|{terra::time(r)}")
debug: if (length(dims_other) > 0 && !all(length(dims[dims_other]) == 
    1)) stop(glue("Other dimensions not yet supported: {paste(dims_other, collapse = ',')}"))
debug: names(r) <- lyrs
debug: if (!is.null(rast_tif)) {
    if (fs::file_exists(rast_tif)) {
        r_tmp_tif <- tempfile(fileext = ".tif")
        r_tmp <- c(rast(rast_tif), r)
        r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
        terra::writeRaster(r_tmp, r_tmp_tif)
        fs::file_delete(rast_tif)
        fs::file_move(r_tmp_tif, rast_tif)
        rm(r)
        rm(r_tmp)
    }
    else {
        terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
    }
    r <- terra::rast(rast_tif)
}
debug: if (fs::file_exists(rast_tif)) {
    r_tmp_tif <- tempfile(fileext = ".tif")
    r_tmp <- c(rast(rast_tif), r)
    r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
    terra::writeRaster(r_tmp, r_tmp_tif)
    fs::file_delete(rast_tif)
    fs::file_move(r_tmp_tif, rast_tif)
    rm(r)
    rm(r_tmp)
} else {
    terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
}
debug: terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
debug: r <- terra::rast(rast_tif)
debug: d_r <- mutate(tidyr::pivot_longer(sf::st_drop_geometry(sf::st_as_sf(terra::zonal(x = r, 
    z = terra::vect(dplyr::select(sf_zones, dplyr::all_of(fld_zones))), 
    fun = zonal_fun, exact = T, na.rm = T, as.polygons = T))), 
    cols = -dplyr::any_of(fld_zones), names_to = "lyr", values_to = zonal_fun), 
    time = readr::parse_datetime(str_replace(lyr, glue("{var}\\|(.*)"), 
        "\\1")))
debug: if (!is.null(zonal_csv)) write_csv(d_r, zonal_csv)
debug: write_csv(d_r, zonal_csv)
debug: if (!keep_nc) unlink(dir_nc, recursive = T)
debug: unlink(dir_nc, recursive = T)
debug: return(d_r)
Downloading 1 requests, up to 111 time slices each
Called from: extractr::ed_extract(ed, var = v, sf_zones = ply, bbox = bb, 
    mask_tif = F, rast_tif = glue("{dir_out}/{nms}/{yr}.tif"), 
    zonal_fun = "mean", zonal_csv = glue("{dir_out}/{nms}/{yr}.csv"), 
    dir_nc = glue("{dir_out}/{nms}/{yr}_nc"), keep_nc = F, n_max_vals_per_req = 1e+05, 
    time_min = time_min, time_max = time_max, verbose = T)
debug: while (i_req <= n_reqs) {
    i_t_beg <- (i_req - 1) * n_t_per_req + 1
    i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
    t_req <- times_todo[c(i_t_beg, i_t_end)]
    t_req_str <- format_ISO8601(t_req, usetz = "Z")
    if (verbose) 
        message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
    ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
        ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
        0), nc)
    unlink(ncs0)
    nc_retry <- T
    nc_n_try <- 1
    n_max_retries
    while (nc_retry) {
        res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
            url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
                bbox[["xmax"]]), latitude = c(bbox[["ymin"]], 
                bbox[["ymax"]]), time = t_req_str, fmt = "nc", 
            store = rerddap::disk(path = dir_nc)))
        if (inherits(res, "try-error")) {
            err <- attr(res, "condition")
            msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
            nc_n_try <- nc_n_try + 1
            if (nc_n_try > n_max_retries) {
                stop(msg)
            }
            else {
                message(msg, "\nRETRYing...")
                Sys.sleep(1)
            }
        }
        else {
            nc_retry <- F
        }
    }
    i_req <- i_req + 1
}
debug: i_t_beg <- (i_req - 1) * n_t_per_req + 1
debug: i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
debug: t_req <- times_todo[c(i_t_beg, i_t_end)]
debug: t_req_str <- format_ISO8601(t_req, usetz = "Z")
debug: if (verbose) message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
debug: message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
Fetching request 1 of 1 (2001-01-01 to 2001-12-01) ~ 19:39:36 UTC
debug: ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
    0), nc)
debug: unlink(ncs0)
debug: nc_retry <- T
debug: nc_n_try <- 1
debug: n_max_retries
debug: while (nc_retry) {
    res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
        url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
            bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
        time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
    if (inherits(res, "try-error")) {
        err <- attr(res, "condition")
        msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
        nc_n_try <- nc_n_try + 1
        if (nc_n_try > n_max_retries) {
            stop(msg)
        }
        else {
            message(msg, "\nRETRYing...")
            Sys.sleep(1)
        }
    }
    else {
        nc_retry <- F
    }
}
debug: res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
    url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
        bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
    time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
debug: if (inherits(res, "try-error")) {
    err <- attr(res, "condition")
    msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
    nc_n_try <- nc_n_try + 1
    if (nc_n_try > n_max_retries) {
        stop(msg)
    }
    else {
        message(msg, "\nRETRYing...")
        Sys.sleep(1)
    }
} else {
    nc_retry <- F
}
debug: nc_retry <- F
debug: (while) nc_retry
debug: i_req <- i_req + 1
debug: (while) i_req <= n_reqs
debug: ncs <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size > 
    0), nc)
debug: r <- terra::rast(ncs)
debug: stopifnot(all(class(terra::time(r)) %in% c("POSIXct", "POSIXt")))
debug: idx <- dplyr::pull(dplyr::filter(dplyr::arrange(dplyr::tibble(idx = 1:terra::nlyr(r), 
    time = terra::time(r)), time), !duplicated(time)), idx)
debug: r <- terra::subset(r, idx)
debug: stopifnot(terra::crs(r, proj = T) == wgs84)
debug: if (mask_tif) r <- terra::mask(r, sf_zones)
debug: lyrs <- glue("{var}|{terra::time(r)}")
debug: if (length(dims_other) > 0 && !all(length(dims[dims_other]) == 
    1)) stop(glue("Other dimensions not yet supported: {paste(dims_other, collapse = ',')}"))
debug: names(r) <- lyrs
debug: if (!is.null(rast_tif)) {
    if (fs::file_exists(rast_tif)) {
        r_tmp_tif <- tempfile(fileext = ".tif")
        r_tmp <- c(rast(rast_tif), r)
        r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
        terra::writeRaster(r_tmp, r_tmp_tif)
        fs::file_delete(rast_tif)
        fs::file_move(r_tmp_tif, rast_tif)
        rm(r)
        rm(r_tmp)
    }
    else {
        terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
    }
    r <- terra::rast(rast_tif)
}
debug: if (fs::file_exists(rast_tif)) {
    r_tmp_tif <- tempfile(fileext = ".tif")
    r_tmp <- c(rast(rast_tif), r)
    r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
    terra::writeRaster(r_tmp, r_tmp_tif)
    fs::file_delete(rast_tif)
    fs::file_move(r_tmp_tif, rast_tif)
    rm(r)
    rm(r_tmp)
} else {
    terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
}
debug: terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
debug: r <- terra::rast(rast_tif)
debug: d_r <- mutate(tidyr::pivot_longer(sf::st_drop_geometry(sf::st_as_sf(terra::zonal(x = r, 
    z = terra::vect(dplyr::select(sf_zones, dplyr::all_of(fld_zones))), 
    fun = zonal_fun, exact = T, na.rm = T, as.polygons = T))), 
    cols = -dplyr::any_of(fld_zones), names_to = "lyr", values_to = zonal_fun), 
    time = readr::parse_datetime(str_replace(lyr, glue("{var}\\|(.*)"), 
        "\\1")))
debug: if (!is.null(zonal_csv)) write_csv(d_r, zonal_csv)
debug: write_csv(d_r, zonal_csv)
debug: if (!keep_nc) unlink(dir_nc, recursive = T)
debug: unlink(dir_nc, recursive = T)
debug: return(d_r)
Downloading 1 requests, up to 111 time slices each
Called from: extractr::ed_extract(ed, var = v, sf_zones = ply, bbox = bb, 
    mask_tif = F, rast_tif = glue("{dir_out}/{nms}/{yr}.tif"), 
    zonal_fun = "mean", zonal_csv = glue("{dir_out}/{nms}/{yr}.csv"), 
    dir_nc = glue("{dir_out}/{nms}/{yr}_nc"), keep_nc = F, n_max_vals_per_req = 1e+05, 
    time_min = time_min, time_max = time_max, verbose = T)
debug: while (i_req <= n_reqs) {
    i_t_beg <- (i_req - 1) * n_t_per_req + 1
    i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
    t_req <- times_todo[c(i_t_beg, i_t_end)]
    t_req_str <- format_ISO8601(t_req, usetz = "Z")
    if (verbose) 
        message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
    ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
        ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
        0), nc)
    unlink(ncs0)
    nc_retry <- T
    nc_n_try <- 1
    n_max_retries
    while (nc_retry) {
        res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
            url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
                bbox[["xmax"]]), latitude = c(bbox[["ymin"]], 
                bbox[["ymax"]]), time = t_req_str, fmt = "nc", 
            store = rerddap::disk(path = dir_nc)))
        if (inherits(res, "try-error")) {
            err <- attr(res, "condition")
            msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
            nc_n_try <- nc_n_try + 1
            if (nc_n_try > n_max_retries) {
                stop(msg)
            }
            else {
                message(msg, "\nRETRYing...")
                Sys.sleep(1)
            }
        }
        else {
            nc_retry <- F
        }
    }
    i_req <- i_req + 1
}
debug: i_t_beg <- (i_req - 1) * n_t_per_req + 1
debug: i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
debug: t_req <- times_todo[c(i_t_beg, i_t_end)]
debug: t_req_str <- format_ISO8601(t_req, usetz = "Z")
debug: if (verbose) message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
debug: message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
Fetching request 1 of 1 (2002-01-01 to 2002-12-01) ~ 19:39:38 UTC
debug: ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
    0), nc)
debug: unlink(ncs0)
debug: nc_retry <- T
debug: nc_n_try <- 1
debug: n_max_retries
debug: while (nc_retry) {
    res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
        url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
            bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
        time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
    if (inherits(res, "try-error")) {
        err <- attr(res, "condition")
        msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
        nc_n_try <- nc_n_try + 1
        if (nc_n_try > n_max_retries) {
            stop(msg)
        }
        else {
            message(msg, "\nRETRYing...")
            Sys.sleep(1)
        }
    }
    else {
        nc_retry <- F
    }
}
debug: res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
    url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
        bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
    time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
debug: if (inherits(res, "try-error")) {
    err <- attr(res, "condition")
    msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
    nc_n_try <- nc_n_try + 1
    if (nc_n_try > n_max_retries) {
        stop(msg)
    }
    else {
        message(msg, "\nRETRYing...")
        Sys.sleep(1)
    }
} else {
    nc_retry <- F
}
debug: nc_retry <- F
debug: (while) nc_retry
debug: i_req <- i_req + 1
debug: (while) i_req <= n_reqs
debug: ncs <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size > 
    0), nc)
debug: r <- terra::rast(ncs)
debug: stopifnot(all(class(terra::time(r)) %in% c("POSIXct", "POSIXt")))
debug: idx <- dplyr::pull(dplyr::filter(dplyr::arrange(dplyr::tibble(idx = 1:terra::nlyr(r), 
    time = terra::time(r)), time), !duplicated(time)), idx)
debug: r <- terra::subset(r, idx)
debug: stopifnot(terra::crs(r, proj = T) == wgs84)
debug: if (mask_tif) r <- terra::mask(r, sf_zones)
debug: lyrs <- glue("{var}|{terra::time(r)}")
debug: if (length(dims_other) > 0 && !all(length(dims[dims_other]) == 
    1)) stop(glue("Other dimensions not yet supported: {paste(dims_other, collapse = ',')}"))
debug: names(r) <- lyrs
debug: if (!is.null(rast_tif)) {
    if (fs::file_exists(rast_tif)) {
        r_tmp_tif <- tempfile(fileext = ".tif")
        r_tmp <- c(rast(rast_tif), r)
        r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
        terra::writeRaster(r_tmp, r_tmp_tif)
        fs::file_delete(rast_tif)
        fs::file_move(r_tmp_tif, rast_tif)
        rm(r)
        rm(r_tmp)
    }
    else {
        terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
    }
    r <- terra::rast(rast_tif)
}
debug: if (fs::file_exists(rast_tif)) {
    r_tmp_tif <- tempfile(fileext = ".tif")
    r_tmp <- c(rast(rast_tif), r)
    r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
    terra::writeRaster(r_tmp, r_tmp_tif)
    fs::file_delete(rast_tif)
    fs::file_move(r_tmp_tif, rast_tif)
    rm(r)
    rm(r_tmp)
} else {
    terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
}
debug: terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
debug: r <- terra::rast(rast_tif)
debug: d_r <- mutate(tidyr::pivot_longer(sf::st_drop_geometry(sf::st_as_sf(terra::zonal(x = r, 
    z = terra::vect(dplyr::select(sf_zones, dplyr::all_of(fld_zones))), 
    fun = zonal_fun, exact = T, na.rm = T, as.polygons = T))), 
    cols = -dplyr::any_of(fld_zones), names_to = "lyr", values_to = zonal_fun), 
    time = readr::parse_datetime(str_replace(lyr, glue("{var}\\|(.*)"), 
        "\\1")))
debug: if (!is.null(zonal_csv)) write_csv(d_r, zonal_csv)
debug: write_csv(d_r, zonal_csv)
debug: if (!keep_nc) unlink(dir_nc, recursive = T)
debug: unlink(dir_nc, recursive = T)
debug: return(d_r)
Downloading 1 requests, up to 111 time slices each
Called from: extractr::ed_extract(ed, var = v, sf_zones = ply, bbox = bb, 
    mask_tif = F, rast_tif = glue("{dir_out}/{nms}/{yr}.tif"), 
    zonal_fun = "mean", zonal_csv = glue("{dir_out}/{nms}/{yr}.csv"), 
    dir_nc = glue("{dir_out}/{nms}/{yr}_nc"), keep_nc = F, n_max_vals_per_req = 1e+05, 
    time_min = time_min, time_max = time_max, verbose = T)
debug: while (i_req <= n_reqs) {
    i_t_beg <- (i_req - 1) * n_t_per_req + 1
    i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
    t_req <- times_todo[c(i_t_beg, i_t_end)]
    t_req_str <- format_ISO8601(t_req, usetz = "Z")
    if (verbose) 
        message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
    ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
        ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
        0), nc)
    unlink(ncs0)
    nc_retry <- T
    nc_n_try <- 1
    n_max_retries
    while (nc_retry) {
        res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
            url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
                bbox[["xmax"]]), latitude = c(bbox[["ymin"]], 
                bbox[["ymax"]]), time = t_req_str, fmt = "nc", 
            store = rerddap::disk(path = dir_nc)))
        if (inherits(res, "try-error")) {
            err <- attr(res, "condition")
            msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
            nc_n_try <- nc_n_try + 1
            if (nc_n_try > n_max_retries) {
                stop(msg)
            }
            else {
                message(msg, "\nRETRYing...")
                Sys.sleep(1)
            }
        }
        else {
            nc_retry <- F
        }
    }
    i_req <- i_req + 1
}
debug: i_t_beg <- (i_req - 1) * n_t_per_req + 1
debug: i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
debug: t_req <- times_todo[c(i_t_beg, i_t_end)]
debug: t_req_str <- format_ISO8601(t_req, usetz = "Z")
debug: if (verbose) message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
debug: message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
Fetching request 1 of 1 (2003-01-01 to 2003-12-01) ~ 19:39:40 UTC
debug: ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
    0), nc)
debug: unlink(ncs0)
debug: nc_retry <- T
debug: nc_n_try <- 1
debug: n_max_retries
debug: while (nc_retry) {
    res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
        url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
            bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
        time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
    if (inherits(res, "try-error")) {
        err <- attr(res, "condition")
        msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
        nc_n_try <- nc_n_try + 1
        if (nc_n_try > n_max_retries) {
            stop(msg)
        }
        else {
            message(msg, "\nRETRYing...")
            Sys.sleep(1)
        }
    }
    else {
        nc_retry <- F
    }
}
debug: res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
    url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
        bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
    time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
debug: if (inherits(res, "try-error")) {
    err <- attr(res, "condition")
    msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
    nc_n_try <- nc_n_try + 1
    if (nc_n_try > n_max_retries) {
        stop(msg)
    }
    else {
        message(msg, "\nRETRYing...")
        Sys.sleep(1)
    }
} else {
    nc_retry <- F
}
debug: nc_retry <- F
debug: (while) nc_retry
debug: i_req <- i_req + 1
debug: (while) i_req <= n_reqs
debug: ncs <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size > 
    0), nc)
debug: r <- terra::rast(ncs)
debug: stopifnot(all(class(terra::time(r)) %in% c("POSIXct", "POSIXt")))
debug: idx <- dplyr::pull(dplyr::filter(dplyr::arrange(dplyr::tibble(idx = 1:terra::nlyr(r), 
    time = terra::time(r)), time), !duplicated(time)), idx)
debug: r <- terra::subset(r, idx)
debug: stopifnot(terra::crs(r, proj = T) == wgs84)
debug: if (mask_tif) r <- terra::mask(r, sf_zones)
debug: lyrs <- glue("{var}|{terra::time(r)}")
debug: if (length(dims_other) > 0 && !all(length(dims[dims_other]) == 
    1)) stop(glue("Other dimensions not yet supported: {paste(dims_other, collapse = ',')}"))
debug: names(r) <- lyrs
debug: if (!is.null(rast_tif)) {
    if (fs::file_exists(rast_tif)) {
        r_tmp_tif <- tempfile(fileext = ".tif")
        r_tmp <- c(rast(rast_tif), r)
        r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
        terra::writeRaster(r_tmp, r_tmp_tif)
        fs::file_delete(rast_tif)
        fs::file_move(r_tmp_tif, rast_tif)
        rm(r)
        rm(r_tmp)
    }
    else {
        terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
    }
    r <- terra::rast(rast_tif)
}
debug: if (fs::file_exists(rast_tif)) {
    r_tmp_tif <- tempfile(fileext = ".tif")
    r_tmp <- c(rast(rast_tif), r)
    r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
    terra::writeRaster(r_tmp, r_tmp_tif)
    fs::file_delete(rast_tif)
    fs::file_move(r_tmp_tif, rast_tif)
    rm(r)
    rm(r_tmp)
} else {
    terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
}
debug: terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
debug: r <- terra::rast(rast_tif)
debug: d_r <- mutate(tidyr::pivot_longer(sf::st_drop_geometry(sf::st_as_sf(terra::zonal(x = r, 
    z = terra::vect(dplyr::select(sf_zones, dplyr::all_of(fld_zones))), 
    fun = zonal_fun, exact = T, na.rm = T, as.polygons = T))), 
    cols = -dplyr::any_of(fld_zones), names_to = "lyr", values_to = zonal_fun), 
    time = readr::parse_datetime(str_replace(lyr, glue("{var}\\|(.*)"), 
        "\\1")))
debug: if (!is.null(zonal_csv)) write_csv(d_r, zonal_csv)
debug: write_csv(d_r, zonal_csv)
debug: if (!keep_nc) unlink(dir_nc, recursive = T)
debug: unlink(dir_nc, recursive = T)
debug: return(d_r)
Downloading 1 requests, up to 111 time slices each
Called from: extractr::ed_extract(ed, var = v, sf_zones = ply, bbox = bb, 
    mask_tif = F, rast_tif = glue("{dir_out}/{nms}/{yr}.tif"), 
    zonal_fun = "mean", zonal_csv = glue("{dir_out}/{nms}/{yr}.csv"), 
    dir_nc = glue("{dir_out}/{nms}/{yr}_nc"), keep_nc = F, n_max_vals_per_req = 1e+05, 
    time_min = time_min, time_max = time_max, verbose = T)
debug: while (i_req <= n_reqs) {
    i_t_beg <- (i_req - 1) * n_t_per_req + 1
    i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
    t_req <- times_todo[c(i_t_beg, i_t_end)]
    t_req_str <- format_ISO8601(t_req, usetz = "Z")
    if (verbose) 
        message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
    ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
        ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
        0), nc)
    unlink(ncs0)
    nc_retry <- T
    nc_n_try <- 1
    n_max_retries
    while (nc_retry) {
        res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
            url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
                bbox[["xmax"]]), latitude = c(bbox[["ymin"]], 
                bbox[["ymax"]]), time = t_req_str, fmt = "nc", 
            store = rerddap::disk(path = dir_nc)))
        if (inherits(res, "try-error")) {
            err <- attr(res, "condition")
            msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
            nc_n_try <- nc_n_try + 1
            if (nc_n_try > n_max_retries) {
                stop(msg)
            }
            else {
                message(msg, "\nRETRYing...")
                Sys.sleep(1)
            }
        }
        else {
            nc_retry <- F
        }
    }
    i_req <- i_req + 1
}
debug: i_t_beg <- (i_req - 1) * n_t_per_req + 1
debug: i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
debug: t_req <- times_todo[c(i_t_beg, i_t_end)]
debug: t_req_str <- format_ISO8601(t_req, usetz = "Z")
debug: if (verbose) message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
debug: message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
Fetching request 1 of 1 (2004-01-01 to 2004-12-01) ~ 19:39:42 UTC
debug: ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
    0), nc)
debug: unlink(ncs0)
debug: nc_retry <- T
debug: nc_n_try <- 1
debug: n_max_retries
debug: while (nc_retry) {
    res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
        url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
            bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
        time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
    if (inherits(res, "try-error")) {
        err <- attr(res, "condition")
        msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
        nc_n_try <- nc_n_try + 1
        if (nc_n_try > n_max_retries) {
            stop(msg)
        }
        else {
            message(msg, "\nRETRYing...")
            Sys.sleep(1)
        }
    }
    else {
        nc_retry <- F
    }
}
debug: res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
    url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
        bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
    time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
debug: if (inherits(res, "try-error")) {
    err <- attr(res, "condition")
    msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
    nc_n_try <- nc_n_try + 1
    if (nc_n_try > n_max_retries) {
        stop(msg)
    }
    else {
        message(msg, "\nRETRYing...")
        Sys.sleep(1)
    }
} else {
    nc_retry <- F
}
debug: nc_retry <- F
debug: (while) nc_retry
debug: i_req <- i_req + 1
debug: (while) i_req <= n_reqs
debug: ncs <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size > 
    0), nc)
debug: r <- terra::rast(ncs)
debug: stopifnot(all(class(terra::time(r)) %in% c("POSIXct", "POSIXt")))
debug: idx <- dplyr::pull(dplyr::filter(dplyr::arrange(dplyr::tibble(idx = 1:terra::nlyr(r), 
    time = terra::time(r)), time), !duplicated(time)), idx)
debug: r <- terra::subset(r, idx)
debug: stopifnot(terra::crs(r, proj = T) == wgs84)
debug: if (mask_tif) r <- terra::mask(r, sf_zones)
debug: lyrs <- glue("{var}|{terra::time(r)}")
debug: if (length(dims_other) > 0 && !all(length(dims[dims_other]) == 
    1)) stop(glue("Other dimensions not yet supported: {paste(dims_other, collapse = ',')}"))
debug: names(r) <- lyrs
debug: if (!is.null(rast_tif)) {
    if (fs::file_exists(rast_tif)) {
        r_tmp_tif <- tempfile(fileext = ".tif")
        r_tmp <- c(rast(rast_tif), r)
        r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
        terra::writeRaster(r_tmp, r_tmp_tif)
        fs::file_delete(rast_tif)
        fs::file_move(r_tmp_tif, rast_tif)
        rm(r)
        rm(r_tmp)
    }
    else {
        terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
    }
    r <- terra::rast(rast_tif)
}
debug: if (fs::file_exists(rast_tif)) {
    r_tmp_tif <- tempfile(fileext = ".tif")
    r_tmp <- c(rast(rast_tif), r)
    r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
    terra::writeRaster(r_tmp, r_tmp_tif)
    fs::file_delete(rast_tif)
    fs::file_move(r_tmp_tif, rast_tif)
    rm(r)
    rm(r_tmp)
} else {
    terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
}
debug: terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
debug: r <- terra::rast(rast_tif)
debug: d_r <- mutate(tidyr::pivot_longer(sf::st_drop_geometry(sf::st_as_sf(terra::zonal(x = r, 
    z = terra::vect(dplyr::select(sf_zones, dplyr::all_of(fld_zones))), 
    fun = zonal_fun, exact = T, na.rm = T, as.polygons = T))), 
    cols = -dplyr::any_of(fld_zones), names_to = "lyr", values_to = zonal_fun), 
    time = readr::parse_datetime(str_replace(lyr, glue("{var}\\|(.*)"), 
        "\\1")))
debug: if (!is.null(zonal_csv)) write_csv(d_r, zonal_csv)
debug: write_csv(d_r, zonal_csv)
debug: if (!keep_nc) unlink(dir_nc, recursive = T)
debug: unlink(dir_nc, recursive = T)
debug: return(d_r)
Downloading 1 requests, up to 111 time slices each
Called from: extractr::ed_extract(ed, var = v, sf_zones = ply, bbox = bb, 
    mask_tif = F, rast_tif = glue("{dir_out}/{nms}/{yr}.tif"), 
    zonal_fun = "mean", zonal_csv = glue("{dir_out}/{nms}/{yr}.csv"), 
    dir_nc = glue("{dir_out}/{nms}/{yr}_nc"), keep_nc = F, n_max_vals_per_req = 1e+05, 
    time_min = time_min, time_max = time_max, verbose = T)
debug: while (i_req <= n_reqs) {
    i_t_beg <- (i_req - 1) * n_t_per_req + 1
    i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
    t_req <- times_todo[c(i_t_beg, i_t_end)]
    t_req_str <- format_ISO8601(t_req, usetz = "Z")
    if (verbose) 
        message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
    ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
        ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
        0), nc)
    unlink(ncs0)
    nc_retry <- T
    nc_n_try <- 1
    n_max_retries
    while (nc_retry) {
        res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
            url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
                bbox[["xmax"]]), latitude = c(bbox[["ymin"]], 
                bbox[["ymax"]]), time = t_req_str, fmt = "nc", 
            store = rerddap::disk(path = dir_nc)))
        if (inherits(res, "try-error")) {
            err <- attr(res, "condition")
            msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
            nc_n_try <- nc_n_try + 1
            if (nc_n_try > n_max_retries) {
                stop(msg)
            }
            else {
                message(msg, "\nRETRYing...")
                Sys.sleep(1)
            }
        }
        else {
            nc_retry <- F
        }
    }
    i_req <- i_req + 1
}
debug: i_t_beg <- (i_req - 1) * n_t_per_req + 1
debug: i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
debug: t_req <- times_todo[c(i_t_beg, i_t_end)]
debug: t_req_str <- format_ISO8601(t_req, usetz = "Z")
debug: if (verbose) message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
debug: message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
Fetching request 1 of 1 (2005-01-01 to 2005-12-01) ~ 19:39:44 UTC
debug: ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
    0), nc)
debug: unlink(ncs0)
debug: nc_retry <- T
debug: nc_n_try <- 1
debug: n_max_retries
debug: while (nc_retry) {
    res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
        url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
            bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
        time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
    if (inherits(res, "try-error")) {
        err <- attr(res, "condition")
        msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
        nc_n_try <- nc_n_try + 1
        if (nc_n_try > n_max_retries) {
            stop(msg)
        }
        else {
            message(msg, "\nRETRYing...")
            Sys.sleep(1)
        }
    }
    else {
        nc_retry <- F
    }
}
debug: res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
    url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
        bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
    time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
debug: if (inherits(res, "try-error")) {
    err <- attr(res, "condition")
    msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
    nc_n_try <- nc_n_try + 1
    if (nc_n_try > n_max_retries) {
        stop(msg)
    }
    else {
        message(msg, "\nRETRYing...")
        Sys.sleep(1)
    }
} else {
    nc_retry <- F
}
debug: nc_retry <- F
debug: (while) nc_retry
debug: i_req <- i_req + 1
debug: (while) i_req <= n_reqs
debug: ncs <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size > 
    0), nc)
debug: r <- terra::rast(ncs)
debug: stopifnot(all(class(terra::time(r)) %in% c("POSIXct", "POSIXt")))
debug: idx <- dplyr::pull(dplyr::filter(dplyr::arrange(dplyr::tibble(idx = 1:terra::nlyr(r), 
    time = terra::time(r)), time), !duplicated(time)), idx)
debug: r <- terra::subset(r, idx)
debug: stopifnot(terra::crs(r, proj = T) == wgs84)
debug: if (mask_tif) r <- terra::mask(r, sf_zones)
debug: lyrs <- glue("{var}|{terra::time(r)}")
debug: if (length(dims_other) > 0 && !all(length(dims[dims_other]) == 
    1)) stop(glue("Other dimensions not yet supported: {paste(dims_other, collapse = ',')}"))
debug: names(r) <- lyrs
debug: if (!is.null(rast_tif)) {
    if (fs::file_exists(rast_tif)) {
        r_tmp_tif <- tempfile(fileext = ".tif")
        r_tmp <- c(rast(rast_tif), r)
        r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
        terra::writeRaster(r_tmp, r_tmp_tif)
        fs::file_delete(rast_tif)
        fs::file_move(r_tmp_tif, rast_tif)
        rm(r)
        rm(r_tmp)
    }
    else {
        terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
    }
    r <- terra::rast(rast_tif)
}
debug: if (fs::file_exists(rast_tif)) {
    r_tmp_tif <- tempfile(fileext = ".tif")
    r_tmp <- c(rast(rast_tif), r)
    r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
    terra::writeRaster(r_tmp, r_tmp_tif)
    fs::file_delete(rast_tif)
    fs::file_move(r_tmp_tif, rast_tif)
    rm(r)
    rm(r_tmp)
} else {
    terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
}
debug: terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
debug: r <- terra::rast(rast_tif)
debug: d_r <- mutate(tidyr::pivot_longer(sf::st_drop_geometry(sf::st_as_sf(terra::zonal(x = r, 
    z = terra::vect(dplyr::select(sf_zones, dplyr::all_of(fld_zones))), 
    fun = zonal_fun, exact = T, na.rm = T, as.polygons = T))), 
    cols = -dplyr::any_of(fld_zones), names_to = "lyr", values_to = zonal_fun), 
    time = readr::parse_datetime(str_replace(lyr, glue("{var}\\|(.*)"), 
        "\\1")))
debug: if (!is.null(zonal_csv)) write_csv(d_r, zonal_csv)
debug: write_csv(d_r, zonal_csv)
debug: if (!keep_nc) unlink(dir_nc, recursive = T)
debug: unlink(dir_nc, recursive = T)
debug: return(d_r)
Downloading 1 requests, up to 111 time slices each
Called from: extractr::ed_extract(ed, var = v, sf_zones = ply, bbox = bb, 
    mask_tif = F, rast_tif = glue("{dir_out}/{nms}/{yr}.tif"), 
    zonal_fun = "mean", zonal_csv = glue("{dir_out}/{nms}/{yr}.csv"), 
    dir_nc = glue("{dir_out}/{nms}/{yr}_nc"), keep_nc = F, n_max_vals_per_req = 1e+05, 
    time_min = time_min, time_max = time_max, verbose = T)
debug: while (i_req <= n_reqs) {
    i_t_beg <- (i_req - 1) * n_t_per_req + 1
    i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
    t_req <- times_todo[c(i_t_beg, i_t_end)]
    t_req_str <- format_ISO8601(t_req, usetz = "Z")
    if (verbose) 
        message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
    ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
        ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
        0), nc)
    unlink(ncs0)
    nc_retry <- T
    nc_n_try <- 1
    n_max_retries
    while (nc_retry) {
        res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
            url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
                bbox[["xmax"]]), latitude = c(bbox[["ymin"]], 
                bbox[["ymax"]]), time = t_req_str, fmt = "nc", 
            store = rerddap::disk(path = dir_nc)))
        if (inherits(res, "try-error")) {
            err <- attr(res, "condition")
            msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
            nc_n_try <- nc_n_try + 1
            if (nc_n_try > n_max_retries) {
                stop(msg)
            }
            else {
                message(msg, "\nRETRYing...")
                Sys.sleep(1)
            }
        }
        else {
            nc_retry <- F
        }
    }
    i_req <- i_req + 1
}
debug: i_t_beg <- (i_req - 1) * n_t_per_req + 1
debug: i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
debug: t_req <- times_todo[c(i_t_beg, i_t_end)]
debug: t_req_str <- format_ISO8601(t_req, usetz = "Z")
debug: if (verbose) message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
debug: message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
Fetching request 1 of 1 (2006-01-01 to 2006-12-01) ~ 19:39:46 UTC
debug: ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
    0), nc)
debug: unlink(ncs0)
debug: nc_retry <- T
debug: nc_n_try <- 1
debug: n_max_retries
debug: while (nc_retry) {
    res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
        url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
            bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
        time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
    if (inherits(res, "try-error")) {
        err <- attr(res, "condition")
        msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
        nc_n_try <- nc_n_try + 1
        if (nc_n_try > n_max_retries) {
            stop(msg)
        }
        else {
            message(msg, "\nRETRYing...")
            Sys.sleep(1)
        }
    }
    else {
        nc_retry <- F
    }
}
debug: res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
    url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
        bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
    time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
debug: if (inherits(res, "try-error")) {
    err <- attr(res, "condition")
    msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
    nc_n_try <- nc_n_try + 1
    if (nc_n_try > n_max_retries) {
        stop(msg)
    }
    else {
        message(msg, "\nRETRYing...")
        Sys.sleep(1)
    }
} else {
    nc_retry <- F
}
debug: nc_retry <- F
debug: (while) nc_retry
debug: i_req <- i_req + 1
debug: (while) i_req <= n_reqs
debug: ncs <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size > 
    0), nc)
debug: r <- terra::rast(ncs)
debug: stopifnot(all(class(terra::time(r)) %in% c("POSIXct", "POSIXt")))
debug: idx <- dplyr::pull(dplyr::filter(dplyr::arrange(dplyr::tibble(idx = 1:terra::nlyr(r), 
    time = terra::time(r)), time), !duplicated(time)), idx)
debug: r <- terra::subset(r, idx)
debug: stopifnot(terra::crs(r, proj = T) == wgs84)
debug: if (mask_tif) r <- terra::mask(r, sf_zones)
debug: lyrs <- glue("{var}|{terra::time(r)}")
debug: if (length(dims_other) > 0 && !all(length(dims[dims_other]) == 
    1)) stop(glue("Other dimensions not yet supported: {paste(dims_other, collapse = ',')}"))
debug: names(r) <- lyrs
debug: if (!is.null(rast_tif)) {
    if (fs::file_exists(rast_tif)) {
        r_tmp_tif <- tempfile(fileext = ".tif")
        r_tmp <- c(rast(rast_tif), r)
        r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
        terra::writeRaster(r_tmp, r_tmp_tif)
        fs::file_delete(rast_tif)
        fs::file_move(r_tmp_tif, rast_tif)
        rm(r)
        rm(r_tmp)
    }
    else {
        terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
    }
    r <- terra::rast(rast_tif)
}
debug: if (fs::file_exists(rast_tif)) {
    r_tmp_tif <- tempfile(fileext = ".tif")
    r_tmp <- c(rast(rast_tif), r)
    r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
    terra::writeRaster(r_tmp, r_tmp_tif)
    fs::file_delete(rast_tif)
    fs::file_move(r_tmp_tif, rast_tif)
    rm(r)
    rm(r_tmp)
} else {
    terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
}
debug: terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
debug: r <- terra::rast(rast_tif)
debug: d_r <- mutate(tidyr::pivot_longer(sf::st_drop_geometry(sf::st_as_sf(terra::zonal(x = r, 
    z = terra::vect(dplyr::select(sf_zones, dplyr::all_of(fld_zones))), 
    fun = zonal_fun, exact = T, na.rm = T, as.polygons = T))), 
    cols = -dplyr::any_of(fld_zones), names_to = "lyr", values_to = zonal_fun), 
    time = readr::parse_datetime(str_replace(lyr, glue("{var}\\|(.*)"), 
        "\\1")))
debug: if (!is.null(zonal_csv)) write_csv(d_r, zonal_csv)
debug: write_csv(d_r, zonal_csv)
debug: if (!keep_nc) unlink(dir_nc, recursive = T)
debug: unlink(dir_nc, recursive = T)
debug: return(d_r)
Downloading 1 requests, up to 111 time slices each
Called from: extractr::ed_extract(ed, var = v, sf_zones = ply, bbox = bb, 
    mask_tif = F, rast_tif = glue("{dir_out}/{nms}/{yr}.tif"), 
    zonal_fun = "mean", zonal_csv = glue("{dir_out}/{nms}/{yr}.csv"), 
    dir_nc = glue("{dir_out}/{nms}/{yr}_nc"), keep_nc = F, n_max_vals_per_req = 1e+05, 
    time_min = time_min, time_max = time_max, verbose = T)
debug: while (i_req <= n_reqs) {
    i_t_beg <- (i_req - 1) * n_t_per_req + 1
    i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
    t_req <- times_todo[c(i_t_beg, i_t_end)]
    t_req_str <- format_ISO8601(t_req, usetz = "Z")
    if (verbose) 
        message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
    ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
        ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
        0), nc)
    unlink(ncs0)
    nc_retry <- T
    nc_n_try <- 1
    n_max_retries
    while (nc_retry) {
        res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
            url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
                bbox[["xmax"]]), latitude = c(bbox[["ymin"]], 
                bbox[["ymax"]]), time = t_req_str, fmt = "nc", 
            store = rerddap::disk(path = dir_nc)))
        if (inherits(res, "try-error")) {
            err <- attr(res, "condition")
            msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
            nc_n_try <- nc_n_try + 1
            if (nc_n_try > n_max_retries) {
                stop(msg)
            }
            else {
                message(msg, "\nRETRYing...")
                Sys.sleep(1)
            }
        }
        else {
            nc_retry <- F
        }
    }
    i_req <- i_req + 1
}
debug: i_t_beg <- (i_req - 1) * n_t_per_req + 1
debug: i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
debug: t_req <- times_todo[c(i_t_beg, i_t_end)]
debug: t_req_str <- format_ISO8601(t_req, usetz = "Z")
debug: if (verbose) message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
debug: message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
Fetching request 1 of 1 (2007-01-01 to 2007-12-01) ~ 19:39:48 UTC
debug: ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
    0), nc)
debug: unlink(ncs0)
debug: nc_retry <- T
debug: nc_n_try <- 1
debug: n_max_retries
debug: while (nc_retry) {
    res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
        url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
            bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
        time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
    if (inherits(res, "try-error")) {
        err <- attr(res, "condition")
        msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
        nc_n_try <- nc_n_try + 1
        if (nc_n_try > n_max_retries) {
            stop(msg)
        }
        else {
            message(msg, "\nRETRYing...")
            Sys.sleep(1)
        }
    }
    else {
        nc_retry <- F
    }
}
debug: res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
    url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
        bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
    time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
debug: if (inherits(res, "try-error")) {
    err <- attr(res, "condition")
    msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
    nc_n_try <- nc_n_try + 1
    if (nc_n_try > n_max_retries) {
        stop(msg)
    }
    else {
        message(msg, "\nRETRYing...")
        Sys.sleep(1)
    }
} else {
    nc_retry <- F
}
debug: nc_retry <- F
debug: (while) nc_retry
debug: i_req <- i_req + 1
debug: (while) i_req <= n_reqs
debug: ncs <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size > 
    0), nc)
debug: r <- terra::rast(ncs)
debug: stopifnot(all(class(terra::time(r)) %in% c("POSIXct", "POSIXt")))
debug: idx <- dplyr::pull(dplyr::filter(dplyr::arrange(dplyr::tibble(idx = 1:terra::nlyr(r), 
    time = terra::time(r)), time), !duplicated(time)), idx)
debug: r <- terra::subset(r, idx)
debug: stopifnot(terra::crs(r, proj = T) == wgs84)
debug: if (mask_tif) r <- terra::mask(r, sf_zones)
debug: lyrs <- glue("{var}|{terra::time(r)}")
debug: if (length(dims_other) > 0 && !all(length(dims[dims_other]) == 
    1)) stop(glue("Other dimensions not yet supported: {paste(dims_other, collapse = ',')}"))
debug: names(r) <- lyrs
debug: if (!is.null(rast_tif)) {
    if (fs::file_exists(rast_tif)) {
        r_tmp_tif <- tempfile(fileext = ".tif")
        r_tmp <- c(rast(rast_tif), r)
        r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
        terra::writeRaster(r_tmp, r_tmp_tif)
        fs::file_delete(rast_tif)
        fs::file_move(r_tmp_tif, rast_tif)
        rm(r)
        rm(r_tmp)
    }
    else {
        terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
    }
    r <- terra::rast(rast_tif)
}
debug: if (fs::file_exists(rast_tif)) {
    r_tmp_tif <- tempfile(fileext = ".tif")
    r_tmp <- c(rast(rast_tif), r)
    r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
    terra::writeRaster(r_tmp, r_tmp_tif)
    fs::file_delete(rast_tif)
    fs::file_move(r_tmp_tif, rast_tif)
    rm(r)
    rm(r_tmp)
} else {
    terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
}
debug: terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
debug: r <- terra::rast(rast_tif)
debug: d_r <- mutate(tidyr::pivot_longer(sf::st_drop_geometry(sf::st_as_sf(terra::zonal(x = r, 
    z = terra::vect(dplyr::select(sf_zones, dplyr::all_of(fld_zones))), 
    fun = zonal_fun, exact = T, na.rm = T, as.polygons = T))), 
    cols = -dplyr::any_of(fld_zones), names_to = "lyr", values_to = zonal_fun), 
    time = readr::parse_datetime(str_replace(lyr, glue("{var}\\|(.*)"), 
        "\\1")))
debug: if (!is.null(zonal_csv)) write_csv(d_r, zonal_csv)
debug: write_csv(d_r, zonal_csv)
debug: if (!keep_nc) unlink(dir_nc, recursive = T)
debug: unlink(dir_nc, recursive = T)
debug: return(d_r)
Downloading 1 requests, up to 111 time slices each
Called from: extractr::ed_extract(ed, var = v, sf_zones = ply, bbox = bb, 
    mask_tif = F, rast_tif = glue("{dir_out}/{nms}/{yr}.tif"), 
    zonal_fun = "mean", zonal_csv = glue("{dir_out}/{nms}/{yr}.csv"), 
    dir_nc = glue("{dir_out}/{nms}/{yr}_nc"), keep_nc = F, n_max_vals_per_req = 1e+05, 
    time_min = time_min, time_max = time_max, verbose = T)
debug: while (i_req <= n_reqs) {
    i_t_beg <- (i_req - 1) * n_t_per_req + 1
    i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
    t_req <- times_todo[c(i_t_beg, i_t_end)]
    t_req_str <- format_ISO8601(t_req, usetz = "Z")
    if (verbose) 
        message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
    ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
        ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
        0), nc)
    unlink(ncs0)
    nc_retry <- T
    nc_n_try <- 1
    n_max_retries
    while (nc_retry) {
        res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
            url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
                bbox[["xmax"]]), latitude = c(bbox[["ymin"]], 
                bbox[["ymax"]]), time = t_req_str, fmt = "nc", 
            store = rerddap::disk(path = dir_nc)))
        if (inherits(res, "try-error")) {
            err <- attr(res, "condition")
            msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
            nc_n_try <- nc_n_try + 1
            if (nc_n_try > n_max_retries) {
                stop(msg)
            }
            else {
                message(msg, "\nRETRYing...")
                Sys.sleep(1)
            }
        }
        else {
            nc_retry <- F
        }
    }
    i_req <- i_req + 1
}
debug: i_t_beg <- (i_req - 1) * n_t_per_req + 1
debug: i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
debug: t_req <- times_todo[c(i_t_beg, i_t_end)]
debug: t_req_str <- format_ISO8601(t_req, usetz = "Z")
debug: if (verbose) message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
debug: message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
Fetching request 1 of 1 (2008-01-01 to 2008-12-01) ~ 19:39:50 UTC
debug: ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
    0), nc)
debug: unlink(ncs0)
debug: nc_retry <- T
debug: nc_n_try <- 1
debug: n_max_retries
debug: while (nc_retry) {
    res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
        url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
            bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
        time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
    if (inherits(res, "try-error")) {
        err <- attr(res, "condition")
        msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
        nc_n_try <- nc_n_try + 1
        if (nc_n_try > n_max_retries) {
            stop(msg)
        }
        else {
            message(msg, "\nRETRYing...")
            Sys.sleep(1)
        }
    }
    else {
        nc_retry <- F
    }
}
debug: res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
    url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
        bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
    time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
debug: if (inherits(res, "try-error")) {
    err <- attr(res, "condition")
    msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
    nc_n_try <- nc_n_try + 1
    if (nc_n_try > n_max_retries) {
        stop(msg)
    }
    else {
        message(msg, "\nRETRYing...")
        Sys.sleep(1)
    }
} else {
    nc_retry <- F
}
debug: nc_retry <- F
debug: (while) nc_retry
debug: i_req <- i_req + 1
debug: (while) i_req <= n_reqs
debug: ncs <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size > 
    0), nc)
debug: r <- terra::rast(ncs)
debug: stopifnot(all(class(terra::time(r)) %in% c("POSIXct", "POSIXt")))
debug: idx <- dplyr::pull(dplyr::filter(dplyr::arrange(dplyr::tibble(idx = 1:terra::nlyr(r), 
    time = terra::time(r)), time), !duplicated(time)), idx)
debug: r <- terra::subset(r, idx)
debug: stopifnot(terra::crs(r, proj = T) == wgs84)
debug: if (mask_tif) r <- terra::mask(r, sf_zones)
debug: lyrs <- glue("{var}|{terra::time(r)}")
debug: if (length(dims_other) > 0 && !all(length(dims[dims_other]) == 
    1)) stop(glue("Other dimensions not yet supported: {paste(dims_other, collapse = ',')}"))
debug: names(r) <- lyrs
debug: if (!is.null(rast_tif)) {
    if (fs::file_exists(rast_tif)) {
        r_tmp_tif <- tempfile(fileext = ".tif")
        r_tmp <- c(rast(rast_tif), r)
        r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
        terra::writeRaster(r_tmp, r_tmp_tif)
        fs::file_delete(rast_tif)
        fs::file_move(r_tmp_tif, rast_tif)
        rm(r)
        rm(r_tmp)
    }
    else {
        terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
    }
    r <- terra::rast(rast_tif)
}
debug: if (fs::file_exists(rast_tif)) {
    r_tmp_tif <- tempfile(fileext = ".tif")
    r_tmp <- c(rast(rast_tif), r)
    r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
    terra::writeRaster(r_tmp, r_tmp_tif)
    fs::file_delete(rast_tif)
    fs::file_move(r_tmp_tif, rast_tif)
    rm(r)
    rm(r_tmp)
} else {
    terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
}
debug: terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
debug: r <- terra::rast(rast_tif)
debug: d_r <- mutate(tidyr::pivot_longer(sf::st_drop_geometry(sf::st_as_sf(terra::zonal(x = r, 
    z = terra::vect(dplyr::select(sf_zones, dplyr::all_of(fld_zones))), 
    fun = zonal_fun, exact = T, na.rm = T, as.polygons = T))), 
    cols = -dplyr::any_of(fld_zones), names_to = "lyr", values_to = zonal_fun), 
    time = readr::parse_datetime(str_replace(lyr, glue("{var}\\|(.*)"), 
        "\\1")))
debug: if (!is.null(zonal_csv)) write_csv(d_r, zonal_csv)
debug: write_csv(d_r, zonal_csv)
debug: if (!keep_nc) unlink(dir_nc, recursive = T)
debug: unlink(dir_nc, recursive = T)
debug: return(d_r)
Downloading 1 requests, up to 111 time slices each
Called from: extractr::ed_extract(ed, var = v, sf_zones = ply, bbox = bb, 
    mask_tif = F, rast_tif = glue("{dir_out}/{nms}/{yr}.tif"), 
    zonal_fun = "mean", zonal_csv = glue("{dir_out}/{nms}/{yr}.csv"), 
    dir_nc = glue("{dir_out}/{nms}/{yr}_nc"), keep_nc = F, n_max_vals_per_req = 1e+05, 
    time_min = time_min, time_max = time_max, verbose = T)
debug: while (i_req <= n_reqs) {
    i_t_beg <- (i_req - 1) * n_t_per_req + 1
    i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
    t_req <- times_todo[c(i_t_beg, i_t_end)]
    t_req_str <- format_ISO8601(t_req, usetz = "Z")
    if (verbose) 
        message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
    ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
        ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
        0), nc)
    unlink(ncs0)
    nc_retry <- T
    nc_n_try <- 1
    n_max_retries
    while (nc_retry) {
        res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
            url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
                bbox[["xmax"]]), latitude = c(bbox[["ymin"]], 
                bbox[["ymax"]]), time = t_req_str, fmt = "nc", 
            store = rerddap::disk(path = dir_nc)))
        if (inherits(res, "try-error")) {
            err <- attr(res, "condition")
            msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
            nc_n_try <- nc_n_try + 1
            if (nc_n_try > n_max_retries) {
                stop(msg)
            }
            else {
                message(msg, "\nRETRYing...")
                Sys.sleep(1)
            }
        }
        else {
            nc_retry <- F
        }
    }
    i_req <- i_req + 1
}
debug: i_t_beg <- (i_req - 1) * n_t_per_req + 1
debug: i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
debug: t_req <- times_todo[c(i_t_beg, i_t_end)]
debug: t_req_str <- format_ISO8601(t_req, usetz = "Z")
debug: if (verbose) message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
debug: message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
Fetching request 1 of 1 (2009-01-01 to 2009-12-01) ~ 19:39:52 UTC
debug: ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
    0), nc)
debug: unlink(ncs0)
debug: nc_retry <- T
debug: nc_n_try <- 1
debug: n_max_retries
debug: while (nc_retry) {
    res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
        url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
            bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
        time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
    if (inherits(res, "try-error")) {
        err <- attr(res, "condition")
        msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
        nc_n_try <- nc_n_try + 1
        if (nc_n_try > n_max_retries) {
            stop(msg)
        }
        else {
            message(msg, "\nRETRYing...")
            Sys.sleep(1)
        }
    }
    else {
        nc_retry <- F
    }
}
debug: res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
    url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
        bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
    time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
debug: if (inherits(res, "try-error")) {
    err <- attr(res, "condition")
    msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
    nc_n_try <- nc_n_try + 1
    if (nc_n_try > n_max_retries) {
        stop(msg)
    }
    else {
        message(msg, "\nRETRYing...")
        Sys.sleep(1)
    }
} else {
    nc_retry <- F
}
debug: nc_retry <- F
debug: (while) nc_retry
debug: i_req <- i_req + 1
debug: (while) i_req <= n_reqs
debug: ncs <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size > 
    0), nc)
debug: r <- terra::rast(ncs)
debug: stopifnot(all(class(terra::time(r)) %in% c("POSIXct", "POSIXt")))
debug: idx <- dplyr::pull(dplyr::filter(dplyr::arrange(dplyr::tibble(idx = 1:terra::nlyr(r), 
    time = terra::time(r)), time), !duplicated(time)), idx)
debug: r <- terra::subset(r, idx)
debug: stopifnot(terra::crs(r, proj = T) == wgs84)
debug: if (mask_tif) r <- terra::mask(r, sf_zones)
debug: lyrs <- glue("{var}|{terra::time(r)}")
debug: if (length(dims_other) > 0 && !all(length(dims[dims_other]) == 
    1)) stop(glue("Other dimensions not yet supported: {paste(dims_other, collapse = ',')}"))
debug: names(r) <- lyrs
debug: if (!is.null(rast_tif)) {
    if (fs::file_exists(rast_tif)) {
        r_tmp_tif <- tempfile(fileext = ".tif")
        r_tmp <- c(rast(rast_tif), r)
        r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
        terra::writeRaster(r_tmp, r_tmp_tif)
        fs::file_delete(rast_tif)
        fs::file_move(r_tmp_tif, rast_tif)
        rm(r)
        rm(r_tmp)
    }
    else {
        terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
    }
    r <- terra::rast(rast_tif)
}
debug: if (fs::file_exists(rast_tif)) {
    r_tmp_tif <- tempfile(fileext = ".tif")
    r_tmp <- c(rast(rast_tif), r)
    r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
    terra::writeRaster(r_tmp, r_tmp_tif)
    fs::file_delete(rast_tif)
    fs::file_move(r_tmp_tif, rast_tif)
    rm(r)
    rm(r_tmp)
} else {
    terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
}
debug: terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
debug: r <- terra::rast(rast_tif)
debug: d_r <- mutate(tidyr::pivot_longer(sf::st_drop_geometry(sf::st_as_sf(terra::zonal(x = r, 
    z = terra::vect(dplyr::select(sf_zones, dplyr::all_of(fld_zones))), 
    fun = zonal_fun, exact = T, na.rm = T, as.polygons = T))), 
    cols = -dplyr::any_of(fld_zones), names_to = "lyr", values_to = zonal_fun), 
    time = readr::parse_datetime(str_replace(lyr, glue("{var}\\|(.*)"), 
        "\\1")))
debug: if (!is.null(zonal_csv)) write_csv(d_r, zonal_csv)
debug: write_csv(d_r, zonal_csv)
debug: if (!keep_nc) unlink(dir_nc, recursive = T)
debug: unlink(dir_nc, recursive = T)
debug: return(d_r)
Downloading 1 requests, up to 111 time slices each
Called from: extractr::ed_extract(ed, var = v, sf_zones = ply, bbox = bb, 
    mask_tif = F, rast_tif = glue("{dir_out}/{nms}/{yr}.tif"), 
    zonal_fun = "mean", zonal_csv = glue("{dir_out}/{nms}/{yr}.csv"), 
    dir_nc = glue("{dir_out}/{nms}/{yr}_nc"), keep_nc = F, n_max_vals_per_req = 1e+05, 
    time_min = time_min, time_max = time_max, verbose = T)
debug: while (i_req <= n_reqs) {
    i_t_beg <- (i_req - 1) * n_t_per_req + 1
    i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
    t_req <- times_todo[c(i_t_beg, i_t_end)]
    t_req_str <- format_ISO8601(t_req, usetz = "Z")
    if (verbose) 
        message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
    ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
        ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
        0), nc)
    unlink(ncs0)
    nc_retry <- T
    nc_n_try <- 1
    n_max_retries
    while (nc_retry) {
        res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
            url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
                bbox[["xmax"]]), latitude = c(bbox[["ymin"]], 
                bbox[["ymax"]]), time = t_req_str, fmt = "nc", 
            store = rerddap::disk(path = dir_nc)))
        if (inherits(res, "try-error")) {
            err <- attr(res, "condition")
            msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
            nc_n_try <- nc_n_try + 1
            if (nc_n_try > n_max_retries) {
                stop(msg)
            }
            else {
                message(msg, "\nRETRYing...")
                Sys.sleep(1)
            }
        }
        else {
            nc_retry <- F
        }
    }
    i_req <- i_req + 1
}
debug: i_t_beg <- (i_req - 1) * n_t_per_req + 1
debug: i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
debug: t_req <- times_todo[c(i_t_beg, i_t_end)]
debug: t_req_str <- format_ISO8601(t_req, usetz = "Z")
debug: if (verbose) message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
debug: message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
Fetching request 1 of 1 (2010-01-01 to 2010-12-01) ~ 19:39:54 UTC
debug: ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
    0), nc)
debug: unlink(ncs0)
debug: nc_retry <- T
debug: nc_n_try <- 1
debug: n_max_retries
debug: while (nc_retry) {
    res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
        url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
            bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
        time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
    if (inherits(res, "try-error")) {
        err <- attr(res, "condition")
        msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
        nc_n_try <- nc_n_try + 1
        if (nc_n_try > n_max_retries) {
            stop(msg)
        }
        else {
            message(msg, "\nRETRYing...")
            Sys.sleep(1)
        }
    }
    else {
        nc_retry <- F
    }
}
debug: res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
    url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
        bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
    time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
debug: if (inherits(res, "try-error")) {
    err <- attr(res, "condition")
    msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
    nc_n_try <- nc_n_try + 1
    if (nc_n_try > n_max_retries) {
        stop(msg)
    }
    else {
        message(msg, "\nRETRYing...")
        Sys.sleep(1)
    }
} else {
    nc_retry <- F
}
debug: nc_retry <- F
debug: (while) nc_retry
debug: i_req <- i_req + 1
debug: (while) i_req <= n_reqs
debug: ncs <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size > 
    0), nc)
debug: r <- terra::rast(ncs)
debug: stopifnot(all(class(terra::time(r)) %in% c("POSIXct", "POSIXt")))
debug: idx <- dplyr::pull(dplyr::filter(dplyr::arrange(dplyr::tibble(idx = 1:terra::nlyr(r), 
    time = terra::time(r)), time), !duplicated(time)), idx)
debug: r <- terra::subset(r, idx)
debug: stopifnot(terra::crs(r, proj = T) == wgs84)
debug: if (mask_tif) r <- terra::mask(r, sf_zones)
debug: lyrs <- glue("{var}|{terra::time(r)}")
debug: if (length(dims_other) > 0 && !all(length(dims[dims_other]) == 
    1)) stop(glue("Other dimensions not yet supported: {paste(dims_other, collapse = ',')}"))
debug: names(r) <- lyrs
debug: if (!is.null(rast_tif)) {
    if (fs::file_exists(rast_tif)) {
        r_tmp_tif <- tempfile(fileext = ".tif")
        r_tmp <- c(rast(rast_tif), r)
        r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
        terra::writeRaster(r_tmp, r_tmp_tif)
        fs::file_delete(rast_tif)
        fs::file_move(r_tmp_tif, rast_tif)
        rm(r)
        rm(r_tmp)
    }
    else {
        terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
    }
    r <- terra::rast(rast_tif)
}
debug: if (fs::file_exists(rast_tif)) {
    r_tmp_tif <- tempfile(fileext = ".tif")
    r_tmp <- c(rast(rast_tif), r)
    r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
    terra::writeRaster(r_tmp, r_tmp_tif)
    fs::file_delete(rast_tif)
    fs::file_move(r_tmp_tif, rast_tif)
    rm(r)
    rm(r_tmp)
} else {
    terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
}
debug: terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
debug: r <- terra::rast(rast_tif)
debug: d_r <- mutate(tidyr::pivot_longer(sf::st_drop_geometry(sf::st_as_sf(terra::zonal(x = r, 
    z = terra::vect(dplyr::select(sf_zones, dplyr::all_of(fld_zones))), 
    fun = zonal_fun, exact = T, na.rm = T, as.polygons = T))), 
    cols = -dplyr::any_of(fld_zones), names_to = "lyr", values_to = zonal_fun), 
    time = readr::parse_datetime(str_replace(lyr, glue("{var}\\|(.*)"), 
        "\\1")))
debug: if (!is.null(zonal_csv)) write_csv(d_r, zonal_csv)
debug: write_csv(d_r, zonal_csv)
debug: if (!keep_nc) unlink(dir_nc, recursive = T)
debug: unlink(dir_nc, recursive = T)
debug: return(d_r)
Downloading 1 requests, up to 111 time slices each
Called from: extractr::ed_extract(ed, var = v, sf_zones = ply, bbox = bb, 
    mask_tif = F, rast_tif = glue("{dir_out}/{nms}/{yr}.tif"), 
    zonal_fun = "mean", zonal_csv = glue("{dir_out}/{nms}/{yr}.csv"), 
    dir_nc = glue("{dir_out}/{nms}/{yr}_nc"), keep_nc = F, n_max_vals_per_req = 1e+05, 
    time_min = time_min, time_max = time_max, verbose = T)
debug: while (i_req <= n_reqs) {
    i_t_beg <- (i_req - 1) * n_t_per_req + 1
    i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
    t_req <- times_todo[c(i_t_beg, i_t_end)]
    t_req_str <- format_ISO8601(t_req, usetz = "Z")
    if (verbose) 
        message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
    ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
        ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
        0), nc)
    unlink(ncs0)
    nc_retry <- T
    nc_n_try <- 1
    n_max_retries
    while (nc_retry) {
        res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
            url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
                bbox[["xmax"]]), latitude = c(bbox[["ymin"]], 
                bbox[["ymax"]]), time = t_req_str, fmt = "nc", 
            store = rerddap::disk(path = dir_nc)))
        if (inherits(res, "try-error")) {
            err <- attr(res, "condition")
            msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
            nc_n_try <- nc_n_try + 1
            if (nc_n_try > n_max_retries) {
                stop(msg)
            }
            else {
                message(msg, "\nRETRYing...")
                Sys.sleep(1)
            }
        }
        else {
            nc_retry <- F
        }
    }
    i_req <- i_req + 1
}
debug: i_t_beg <- (i_req - 1) * n_t_per_req + 1
debug: i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
debug: t_req <- times_todo[c(i_t_beg, i_t_end)]
debug: t_req_str <- format_ISO8601(t_req, usetz = "Z")
debug: if (verbose) message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
debug: message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
Fetching request 1 of 1 (2011-01-01 to 2011-12-01) ~ 19:39:56 UTC
debug: ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
    0), nc)
debug: unlink(ncs0)
debug: nc_retry <- T
debug: nc_n_try <- 1
debug: n_max_retries
debug: while (nc_retry) {
    res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
        url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
            bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
        time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
    if (inherits(res, "try-error")) {
        err <- attr(res, "condition")
        msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
        nc_n_try <- nc_n_try + 1
        if (nc_n_try > n_max_retries) {
            stop(msg)
        }
        else {
            message(msg, "\nRETRYing...")
            Sys.sleep(1)
        }
    }
    else {
        nc_retry <- F
    }
}
debug: res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
    url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
        bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
    time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
debug: if (inherits(res, "try-error")) {
    err <- attr(res, "condition")
    msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
    nc_n_try <- nc_n_try + 1
    if (nc_n_try > n_max_retries) {
        stop(msg)
    }
    else {
        message(msg, "\nRETRYing...")
        Sys.sleep(1)
    }
} else {
    nc_retry <- F
}
debug: nc_retry <- F
debug: (while) nc_retry
debug: i_req <- i_req + 1
debug: (while) i_req <= n_reqs
debug: ncs <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size > 
    0), nc)
debug: r <- terra::rast(ncs)
debug: stopifnot(all(class(terra::time(r)) %in% c("POSIXct", "POSIXt")))
debug: idx <- dplyr::pull(dplyr::filter(dplyr::arrange(dplyr::tibble(idx = 1:terra::nlyr(r), 
    time = terra::time(r)), time), !duplicated(time)), idx)
debug: r <- terra::subset(r, idx)
debug: stopifnot(terra::crs(r, proj = T) == wgs84)
debug: if (mask_tif) r <- terra::mask(r, sf_zones)
debug: lyrs <- glue("{var}|{terra::time(r)}")
debug: if (length(dims_other) > 0 && !all(length(dims[dims_other]) == 
    1)) stop(glue("Other dimensions not yet supported: {paste(dims_other, collapse = ',')}"))
debug: names(r) <- lyrs
debug: if (!is.null(rast_tif)) {
    if (fs::file_exists(rast_tif)) {
        r_tmp_tif <- tempfile(fileext = ".tif")
        r_tmp <- c(rast(rast_tif), r)
        r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
        terra::writeRaster(r_tmp, r_tmp_tif)
        fs::file_delete(rast_tif)
        fs::file_move(r_tmp_tif, rast_tif)
        rm(r)
        rm(r_tmp)
    }
    else {
        terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
    }
    r <- terra::rast(rast_tif)
}
debug: if (fs::file_exists(rast_tif)) {
    r_tmp_tif <- tempfile(fileext = ".tif")
    r_tmp <- c(rast(rast_tif), r)
    r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
    terra::writeRaster(r_tmp, r_tmp_tif)
    fs::file_delete(rast_tif)
    fs::file_move(r_tmp_tif, rast_tif)
    rm(r)
    rm(r_tmp)
} else {
    terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
}
debug: terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
debug: r <- terra::rast(rast_tif)
debug: d_r <- mutate(tidyr::pivot_longer(sf::st_drop_geometry(sf::st_as_sf(terra::zonal(x = r, 
    z = terra::vect(dplyr::select(sf_zones, dplyr::all_of(fld_zones))), 
    fun = zonal_fun, exact = T, na.rm = T, as.polygons = T))), 
    cols = -dplyr::any_of(fld_zones), names_to = "lyr", values_to = zonal_fun), 
    time = readr::parse_datetime(str_replace(lyr, glue("{var}\\|(.*)"), 
        "\\1")))
debug: if (!is.null(zonal_csv)) write_csv(d_r, zonal_csv)
debug: write_csv(d_r, zonal_csv)
debug: if (!keep_nc) unlink(dir_nc, recursive = T)
debug: unlink(dir_nc, recursive = T)
debug: return(d_r)
Downloading 1 requests, up to 111 time slices each
Called from: extractr::ed_extract(ed, var = v, sf_zones = ply, bbox = bb, 
    mask_tif = F, rast_tif = glue("{dir_out}/{nms}/{yr}.tif"), 
    zonal_fun = "mean", zonal_csv = glue("{dir_out}/{nms}/{yr}.csv"), 
    dir_nc = glue("{dir_out}/{nms}/{yr}_nc"), keep_nc = F, n_max_vals_per_req = 1e+05, 
    time_min = time_min, time_max = time_max, verbose = T)
debug: while (i_req <= n_reqs) {
    i_t_beg <- (i_req - 1) * n_t_per_req + 1
    i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
    t_req <- times_todo[c(i_t_beg, i_t_end)]
    t_req_str <- format_ISO8601(t_req, usetz = "Z")
    if (verbose) 
        message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
    ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
        ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
        0), nc)
    unlink(ncs0)
    nc_retry <- T
    nc_n_try <- 1
    n_max_retries
    while (nc_retry) {
        res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
            url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
                bbox[["xmax"]]), latitude = c(bbox[["ymin"]], 
                bbox[["ymax"]]), time = t_req_str, fmt = "nc", 
            store = rerddap::disk(path = dir_nc)))
        if (inherits(res, "try-error")) {
            err <- attr(res, "condition")
            msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
            nc_n_try <- nc_n_try + 1
            if (nc_n_try > n_max_retries) {
                stop(msg)
            }
            else {
                message(msg, "\nRETRYing...")
                Sys.sleep(1)
            }
        }
        else {
            nc_retry <- F
        }
    }
    i_req <- i_req + 1
}
debug: i_t_beg <- (i_req - 1) * n_t_per_req + 1
debug: i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
debug: t_req <- times_todo[c(i_t_beg, i_t_end)]
debug: t_req_str <- format_ISO8601(t_req, usetz = "Z")
debug: if (verbose) message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
debug: message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
Fetching request 1 of 1 (2012-01-01 to 2012-12-01) ~ 19:39:58 UTC
debug: ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
    0), nc)
debug: unlink(ncs0)
debug: nc_retry <- T
debug: nc_n_try <- 1
debug: n_max_retries
debug: while (nc_retry) {
    res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
        url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
            bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
        time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
    if (inherits(res, "try-error")) {
        err <- attr(res, "condition")
        msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
        nc_n_try <- nc_n_try + 1
        if (nc_n_try > n_max_retries) {
            stop(msg)
        }
        else {
            message(msg, "\nRETRYing...")
            Sys.sleep(1)
        }
    }
    else {
        nc_retry <- F
    }
}
debug: res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
    url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
        bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
    time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
debug: if (inherits(res, "try-error")) {
    err <- attr(res, "condition")
    msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
    nc_n_try <- nc_n_try + 1
    if (nc_n_try > n_max_retries) {
        stop(msg)
    }
    else {
        message(msg, "\nRETRYing...")
        Sys.sleep(1)
    }
} else {
    nc_retry <- F
}
debug: nc_retry <- F
debug: (while) nc_retry
debug: i_req <- i_req + 1
debug: (while) i_req <= n_reqs
debug: ncs <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size > 
    0), nc)
debug: r <- terra::rast(ncs)
debug: stopifnot(all(class(terra::time(r)) %in% c("POSIXct", "POSIXt")))
debug: idx <- dplyr::pull(dplyr::filter(dplyr::arrange(dplyr::tibble(idx = 1:terra::nlyr(r), 
    time = terra::time(r)), time), !duplicated(time)), idx)
debug: r <- terra::subset(r, idx)
debug: stopifnot(terra::crs(r, proj = T) == wgs84)
debug: if (mask_tif) r <- terra::mask(r, sf_zones)
debug: lyrs <- glue("{var}|{terra::time(r)}")
debug: if (length(dims_other) > 0 && !all(length(dims[dims_other]) == 
    1)) stop(glue("Other dimensions not yet supported: {paste(dims_other, collapse = ',')}"))
debug: names(r) <- lyrs
debug: if (!is.null(rast_tif)) {
    if (fs::file_exists(rast_tif)) {
        r_tmp_tif <- tempfile(fileext = ".tif")
        r_tmp <- c(rast(rast_tif), r)
        r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
        terra::writeRaster(r_tmp, r_tmp_tif)
        fs::file_delete(rast_tif)
        fs::file_move(r_tmp_tif, rast_tif)
        rm(r)
        rm(r_tmp)
    }
    else {
        terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
    }
    r <- terra::rast(rast_tif)
}
debug: if (fs::file_exists(rast_tif)) {
    r_tmp_tif <- tempfile(fileext = ".tif")
    r_tmp <- c(rast(rast_tif), r)
    r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
    terra::writeRaster(r_tmp, r_tmp_tif)
    fs::file_delete(rast_tif)
    fs::file_move(r_tmp_tif, rast_tif)
    rm(r)
    rm(r_tmp)
} else {
    terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
}
debug: terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
debug: r <- terra::rast(rast_tif)
debug: d_r <- mutate(tidyr::pivot_longer(sf::st_drop_geometry(sf::st_as_sf(terra::zonal(x = r, 
    z = terra::vect(dplyr::select(sf_zones, dplyr::all_of(fld_zones))), 
    fun = zonal_fun, exact = T, na.rm = T, as.polygons = T))), 
    cols = -dplyr::any_of(fld_zones), names_to = "lyr", values_to = zonal_fun), 
    time = readr::parse_datetime(str_replace(lyr, glue("{var}\\|(.*)"), 
        "\\1")))
debug: if (!is.null(zonal_csv)) write_csv(d_r, zonal_csv)
debug: write_csv(d_r, zonal_csv)
debug: if (!keep_nc) unlink(dir_nc, recursive = T)
debug: unlink(dir_nc, recursive = T)
debug: return(d_r)
Downloading 1 requests, up to 111 time slices each
Called from: extractr::ed_extract(ed, var = v, sf_zones = ply, bbox = bb, 
    mask_tif = F, rast_tif = glue("{dir_out}/{nms}/{yr}.tif"), 
    zonal_fun = "mean", zonal_csv = glue("{dir_out}/{nms}/{yr}.csv"), 
    dir_nc = glue("{dir_out}/{nms}/{yr}_nc"), keep_nc = F, n_max_vals_per_req = 1e+05, 
    time_min = time_min, time_max = time_max, verbose = T)
debug: while (i_req <= n_reqs) {
    i_t_beg <- (i_req - 1) * n_t_per_req + 1
    i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
    t_req <- times_todo[c(i_t_beg, i_t_end)]
    t_req_str <- format_ISO8601(t_req, usetz = "Z")
    if (verbose) 
        message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
    ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
        ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
        0), nc)
    unlink(ncs0)
    nc_retry <- T
    nc_n_try <- 1
    n_max_retries
    while (nc_retry) {
        res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
            url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
                bbox[["xmax"]]), latitude = c(bbox[["ymin"]], 
                bbox[["ymax"]]), time = t_req_str, fmt = "nc", 
            store = rerddap::disk(path = dir_nc)))
        if (inherits(res, "try-error")) {
            err <- attr(res, "condition")
            msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
            nc_n_try <- nc_n_try + 1
            if (nc_n_try > n_max_retries) {
                stop(msg)
            }
            else {
                message(msg, "\nRETRYing...")
                Sys.sleep(1)
            }
        }
        else {
            nc_retry <- F
        }
    }
    i_req <- i_req + 1
}
debug: i_t_beg <- (i_req - 1) * n_t_per_req + 1
debug: i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
debug: t_req <- times_todo[c(i_t_beg, i_t_end)]
debug: t_req_str <- format_ISO8601(t_req, usetz = "Z")
debug: if (verbose) message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
debug: message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
Fetching request 1 of 1 (2013-01-01 to 2013-12-01) ~ 19:40:00 UTC
debug: ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
    0), nc)
debug: unlink(ncs0)
debug: nc_retry <- T
debug: nc_n_try <- 1
debug: n_max_retries
debug: while (nc_retry) {
    res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
        url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
            bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
        time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
    if (inherits(res, "try-error")) {
        err <- attr(res, "condition")
        msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
        nc_n_try <- nc_n_try + 1
        if (nc_n_try > n_max_retries) {
            stop(msg)
        }
        else {
            message(msg, "\nRETRYing...")
            Sys.sleep(1)
        }
    }
    else {
        nc_retry <- F
    }
}
debug: res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
    url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
        bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
    time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
debug: if (inherits(res, "try-error")) {
    err <- attr(res, "condition")
    msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
    nc_n_try <- nc_n_try + 1
    if (nc_n_try > n_max_retries) {
        stop(msg)
    }
    else {
        message(msg, "\nRETRYing...")
        Sys.sleep(1)
    }
} else {
    nc_retry <- F
}
debug: nc_retry <- F
debug: (while) nc_retry
debug: i_req <- i_req + 1
debug: (while) i_req <= n_reqs
debug: ncs <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size > 
    0), nc)
debug: r <- terra::rast(ncs)
debug: stopifnot(all(class(terra::time(r)) %in% c("POSIXct", "POSIXt")))
debug: idx <- dplyr::pull(dplyr::filter(dplyr::arrange(dplyr::tibble(idx = 1:terra::nlyr(r), 
    time = terra::time(r)), time), !duplicated(time)), idx)
debug: r <- terra::subset(r, idx)
debug: stopifnot(terra::crs(r, proj = T) == wgs84)
debug: if (mask_tif) r <- terra::mask(r, sf_zones)
debug: lyrs <- glue("{var}|{terra::time(r)}")
debug: if (length(dims_other) > 0 && !all(length(dims[dims_other]) == 
    1)) stop(glue("Other dimensions not yet supported: {paste(dims_other, collapse = ',')}"))
debug: names(r) <- lyrs
debug: if (!is.null(rast_tif)) {
    if (fs::file_exists(rast_tif)) {
        r_tmp_tif <- tempfile(fileext = ".tif")
        r_tmp <- c(rast(rast_tif), r)
        r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
        terra::writeRaster(r_tmp, r_tmp_tif)
        fs::file_delete(rast_tif)
        fs::file_move(r_tmp_tif, rast_tif)
        rm(r)
        rm(r_tmp)
    }
    else {
        terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
    }
    r <- terra::rast(rast_tif)
}
debug: if (fs::file_exists(rast_tif)) {
    r_tmp_tif <- tempfile(fileext = ".tif")
    r_tmp <- c(rast(rast_tif), r)
    r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
    terra::writeRaster(r_tmp, r_tmp_tif)
    fs::file_delete(rast_tif)
    fs::file_move(r_tmp_tif, rast_tif)
    rm(r)
    rm(r_tmp)
} else {
    terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
}
debug: terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
debug: r <- terra::rast(rast_tif)
debug: d_r <- mutate(tidyr::pivot_longer(sf::st_drop_geometry(sf::st_as_sf(terra::zonal(x = r, 
    z = terra::vect(dplyr::select(sf_zones, dplyr::all_of(fld_zones))), 
    fun = zonal_fun, exact = T, na.rm = T, as.polygons = T))), 
    cols = -dplyr::any_of(fld_zones), names_to = "lyr", values_to = zonal_fun), 
    time = readr::parse_datetime(str_replace(lyr, glue("{var}\\|(.*)"), 
        "\\1")))
debug: if (!is.null(zonal_csv)) write_csv(d_r, zonal_csv)
debug: write_csv(d_r, zonal_csv)
debug: if (!keep_nc) unlink(dir_nc, recursive = T)
debug: unlink(dir_nc, recursive = T)
debug: return(d_r)
Downloading 1 requests, up to 111 time slices each
Called from: extractr::ed_extract(ed, var = v, sf_zones = ply, bbox = bb, 
    mask_tif = F, rast_tif = glue("{dir_out}/{nms}/{yr}.tif"), 
    zonal_fun = "mean", zonal_csv = glue("{dir_out}/{nms}/{yr}.csv"), 
    dir_nc = glue("{dir_out}/{nms}/{yr}_nc"), keep_nc = F, n_max_vals_per_req = 1e+05, 
    time_min = time_min, time_max = time_max, verbose = T)
debug: while (i_req <= n_reqs) {
    i_t_beg <- (i_req - 1) * n_t_per_req + 1
    i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
    t_req <- times_todo[c(i_t_beg, i_t_end)]
    t_req_str <- format_ISO8601(t_req, usetz = "Z")
    if (verbose) 
        message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
    ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
        ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
        0), nc)
    unlink(ncs0)
    nc_retry <- T
    nc_n_try <- 1
    n_max_retries
    while (nc_retry) {
        res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
            url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
                bbox[["xmax"]]), latitude = c(bbox[["ymin"]], 
                bbox[["ymax"]]), time = t_req_str, fmt = "nc", 
            store = rerddap::disk(path = dir_nc)))
        if (inherits(res, "try-error")) {
            err <- attr(res, "condition")
            msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
            nc_n_try <- nc_n_try + 1
            if (nc_n_try > n_max_retries) {
                stop(msg)
            }
            else {
                message(msg, "\nRETRYing...")
                Sys.sleep(1)
            }
        }
        else {
            nc_retry <- F
        }
    }
    i_req <- i_req + 1
}
debug: i_t_beg <- (i_req - 1) * n_t_per_req + 1
debug: i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
debug: t_req <- times_todo[c(i_t_beg, i_t_end)]
debug: t_req_str <- format_ISO8601(t_req, usetz = "Z")
debug: if (verbose) message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
debug: message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
Fetching request 1 of 1 (2014-01-01 to 2014-12-01) ~ 19:40:02 UTC
debug: ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
    0), nc)
debug: unlink(ncs0)
debug: nc_retry <- T
debug: nc_n_try <- 1
debug: n_max_retries
debug: while (nc_retry) {
    res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
        url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
            bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
        time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
    if (inherits(res, "try-error")) {
        err <- attr(res, "condition")
        msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
        nc_n_try <- nc_n_try + 1
        if (nc_n_try > n_max_retries) {
            stop(msg)
        }
        else {
            message(msg, "\nRETRYing...")
            Sys.sleep(1)
        }
    }
    else {
        nc_retry <- F
    }
}
debug: res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
    url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
        bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
    time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
debug: if (inherits(res, "try-error")) {
    err <- attr(res, "condition")
    msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
    nc_n_try <- nc_n_try + 1
    if (nc_n_try > n_max_retries) {
        stop(msg)
    }
    else {
        message(msg, "\nRETRYing...")
        Sys.sleep(1)
    }
} else {
    nc_retry <- F
}
debug: nc_retry <- F
debug: (while) nc_retry
debug: i_req <- i_req + 1
debug: (while) i_req <= n_reqs
debug: ncs <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size > 
    0), nc)
debug: r <- terra::rast(ncs)
debug: stopifnot(all(class(terra::time(r)) %in% c("POSIXct", "POSIXt")))
debug: idx <- dplyr::pull(dplyr::filter(dplyr::arrange(dplyr::tibble(idx = 1:terra::nlyr(r), 
    time = terra::time(r)), time), !duplicated(time)), idx)
debug: r <- terra::subset(r, idx)
debug: stopifnot(terra::crs(r, proj = T) == wgs84)
debug: if (mask_tif) r <- terra::mask(r, sf_zones)
debug: lyrs <- glue("{var}|{terra::time(r)}")
debug: if (length(dims_other) > 0 && !all(length(dims[dims_other]) == 
    1)) stop(glue("Other dimensions not yet supported: {paste(dims_other, collapse = ',')}"))
debug: names(r) <- lyrs
debug: if (!is.null(rast_tif)) {
    if (fs::file_exists(rast_tif)) {
        r_tmp_tif <- tempfile(fileext = ".tif")
        r_tmp <- c(rast(rast_tif), r)
        r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
        terra::writeRaster(r_tmp, r_tmp_tif)
        fs::file_delete(rast_tif)
        fs::file_move(r_tmp_tif, rast_tif)
        rm(r)
        rm(r_tmp)
    }
    else {
        terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
    }
    r <- terra::rast(rast_tif)
}
debug: if (fs::file_exists(rast_tif)) {
    r_tmp_tif <- tempfile(fileext = ".tif")
    r_tmp <- c(rast(rast_tif), r)
    r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
    terra::writeRaster(r_tmp, r_tmp_tif)
    fs::file_delete(rast_tif)
    fs::file_move(r_tmp_tif, rast_tif)
    rm(r)
    rm(r_tmp)
} else {
    terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
}
debug: terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
debug: r <- terra::rast(rast_tif)
debug: d_r <- mutate(tidyr::pivot_longer(sf::st_drop_geometry(sf::st_as_sf(terra::zonal(x = r, 
    z = terra::vect(dplyr::select(sf_zones, dplyr::all_of(fld_zones))), 
    fun = zonal_fun, exact = T, na.rm = T, as.polygons = T))), 
    cols = -dplyr::any_of(fld_zones), names_to = "lyr", values_to = zonal_fun), 
    time = readr::parse_datetime(str_replace(lyr, glue("{var}\\|(.*)"), 
        "\\1")))
debug: if (!is.null(zonal_csv)) write_csv(d_r, zonal_csv)
debug: write_csv(d_r, zonal_csv)
debug: if (!keep_nc) unlink(dir_nc, recursive = T)
debug: unlink(dir_nc, recursive = T)
debug: return(d_r)
Downloading 1 requests, up to 111 time slices each
Called from: extractr::ed_extract(ed, var = v, sf_zones = ply, bbox = bb, 
    mask_tif = F, rast_tif = glue("{dir_out}/{nms}/{yr}.tif"), 
    zonal_fun = "mean", zonal_csv = glue("{dir_out}/{nms}/{yr}.csv"), 
    dir_nc = glue("{dir_out}/{nms}/{yr}_nc"), keep_nc = F, n_max_vals_per_req = 1e+05, 
    time_min = time_min, time_max = time_max, verbose = T)
debug: while (i_req <= n_reqs) {
    i_t_beg <- (i_req - 1) * n_t_per_req + 1
    i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
    t_req <- times_todo[c(i_t_beg, i_t_end)]
    t_req_str <- format_ISO8601(t_req, usetz = "Z")
    if (verbose) 
        message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
    ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
        ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
        0), nc)
    unlink(ncs0)
    nc_retry <- T
    nc_n_try <- 1
    n_max_retries
    while (nc_retry) {
        res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
            url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
                bbox[["xmax"]]), latitude = c(bbox[["ymin"]], 
                bbox[["ymax"]]), time = t_req_str, fmt = "nc", 
            store = rerddap::disk(path = dir_nc)))
        if (inherits(res, "try-error")) {
            err <- attr(res, "condition")
            msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
            nc_n_try <- nc_n_try + 1
            if (nc_n_try > n_max_retries) {
                stop(msg)
            }
            else {
                message(msg, "\nRETRYing...")
                Sys.sleep(1)
            }
        }
        else {
            nc_retry <- F
        }
    }
    i_req <- i_req + 1
}
debug: i_t_beg <- (i_req - 1) * n_t_per_req + 1
debug: i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
debug: t_req <- times_todo[c(i_t_beg, i_t_end)]
debug: t_req_str <- format_ISO8601(t_req, usetz = "Z")
debug: if (verbose) message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
debug: message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
Fetching request 1 of 1 (2015-01-01 to 2015-12-01) ~ 19:40:04 UTC
debug: ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
    0), nc)
debug: unlink(ncs0)
debug: nc_retry <- T
debug: nc_n_try <- 1
debug: n_max_retries
debug: while (nc_retry) {
    res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
        url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
            bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
        time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
    if (inherits(res, "try-error")) {
        err <- attr(res, "condition")
        msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
        nc_n_try <- nc_n_try + 1
        if (nc_n_try > n_max_retries) {
            stop(msg)
        }
        else {
            message(msg, "\nRETRYing...")
            Sys.sleep(1)
        }
    }
    else {
        nc_retry <- F
    }
}
debug: res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
    url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
        bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
    time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
debug: if (inherits(res, "try-error")) {
    err <- attr(res, "condition")
    msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
    nc_n_try <- nc_n_try + 1
    if (nc_n_try > n_max_retries) {
        stop(msg)
    }
    else {
        message(msg, "\nRETRYing...")
        Sys.sleep(1)
    }
} else {
    nc_retry <- F
}
debug: nc_retry <- F
debug: (while) nc_retry
debug: i_req <- i_req + 1
debug: (while) i_req <= n_reqs
debug: ncs <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size > 
    0), nc)
debug: r <- terra::rast(ncs)
debug: stopifnot(all(class(terra::time(r)) %in% c("POSIXct", "POSIXt")))
debug: idx <- dplyr::pull(dplyr::filter(dplyr::arrange(dplyr::tibble(idx = 1:terra::nlyr(r), 
    time = terra::time(r)), time), !duplicated(time)), idx)
debug: r <- terra::subset(r, idx)
debug: stopifnot(terra::crs(r, proj = T) == wgs84)
debug: if (mask_tif) r <- terra::mask(r, sf_zones)
debug: lyrs <- glue("{var}|{terra::time(r)}")
debug: if (length(dims_other) > 0 && !all(length(dims[dims_other]) == 
    1)) stop(glue("Other dimensions not yet supported: {paste(dims_other, collapse = ',')}"))
debug: names(r) <- lyrs
debug: if (!is.null(rast_tif)) {
    if (fs::file_exists(rast_tif)) {
        r_tmp_tif <- tempfile(fileext = ".tif")
        r_tmp <- c(rast(rast_tif), r)
        r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
        terra::writeRaster(r_tmp, r_tmp_tif)
        fs::file_delete(rast_tif)
        fs::file_move(r_tmp_tif, rast_tif)
        rm(r)
        rm(r_tmp)
    }
    else {
        terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
    }
    r <- terra::rast(rast_tif)
}
debug: if (fs::file_exists(rast_tif)) {
    r_tmp_tif <- tempfile(fileext = ".tif")
    r_tmp <- c(rast(rast_tif), r)
    r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
    terra::writeRaster(r_tmp, r_tmp_tif)
    fs::file_delete(rast_tif)
    fs::file_move(r_tmp_tif, rast_tif)
    rm(r)
    rm(r_tmp)
} else {
    terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
}
debug: terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
debug: r <- terra::rast(rast_tif)
debug: d_r <- mutate(tidyr::pivot_longer(sf::st_drop_geometry(sf::st_as_sf(terra::zonal(x = r, 
    z = terra::vect(dplyr::select(sf_zones, dplyr::all_of(fld_zones))), 
    fun = zonal_fun, exact = T, na.rm = T, as.polygons = T))), 
    cols = -dplyr::any_of(fld_zones), names_to = "lyr", values_to = zonal_fun), 
    time = readr::parse_datetime(str_replace(lyr, glue("{var}\\|(.*)"), 
        "\\1")))
debug: if (!is.null(zonal_csv)) write_csv(d_r, zonal_csv)
debug: write_csv(d_r, zonal_csv)
debug: if (!keep_nc) unlink(dir_nc, recursive = T)
debug: unlink(dir_nc, recursive = T)
debug: return(d_r)
Downloading 1 requests, up to 111 time slices each
Called from: extractr::ed_extract(ed, var = v, sf_zones = ply, bbox = bb, 
    mask_tif = F, rast_tif = glue("{dir_out}/{nms}/{yr}.tif"), 
    zonal_fun = "mean", zonal_csv = glue("{dir_out}/{nms}/{yr}.csv"), 
    dir_nc = glue("{dir_out}/{nms}/{yr}_nc"), keep_nc = F, n_max_vals_per_req = 1e+05, 
    time_min = time_min, time_max = time_max, verbose = T)
debug: while (i_req <= n_reqs) {
    i_t_beg <- (i_req - 1) * n_t_per_req + 1
    i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
    t_req <- times_todo[c(i_t_beg, i_t_end)]
    t_req_str <- format_ISO8601(t_req, usetz = "Z")
    if (verbose) 
        message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
    ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
        ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
        0), nc)
    unlink(ncs0)
    nc_retry <- T
    nc_n_try <- 1
    n_max_retries
    while (nc_retry) {
        res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
            url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
                bbox[["xmax"]]), latitude = c(bbox[["ymin"]], 
                bbox[["ymax"]]), time = t_req_str, fmt = "nc", 
            store = rerddap::disk(path = dir_nc)))
        if (inherits(res, "try-error")) {
            err <- attr(res, "condition")
            msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
            nc_n_try <- nc_n_try + 1
            if (nc_n_try > n_max_retries) {
                stop(msg)
            }
            else {
                message(msg, "\nRETRYing...")
                Sys.sleep(1)
            }
        }
        else {
            nc_retry <- F
        }
    }
    i_req <- i_req + 1
}
debug: i_t_beg <- (i_req - 1) * n_t_per_req + 1
debug: i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
debug: t_req <- times_todo[c(i_t_beg, i_t_end)]
debug: t_req_str <- format_ISO8601(t_req, usetz = "Z")
debug: if (verbose) message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
debug: message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
Fetching request 1 of 1 (2016-01-01 to 2016-12-01) ~ 19:40:06 UTC
debug: ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
    0), nc)
debug: unlink(ncs0)
debug: nc_retry <- T
debug: nc_n_try <- 1
debug: n_max_retries
debug: while (nc_retry) {
    res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
        url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
            bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
        time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
    if (inherits(res, "try-error")) {
        err <- attr(res, "condition")
        msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
        nc_n_try <- nc_n_try + 1
        if (nc_n_try > n_max_retries) {
            stop(msg)
        }
        else {
            message(msg, "\nRETRYing...")
            Sys.sleep(1)
        }
    }
    else {
        nc_retry <- F
    }
}
debug: res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
    url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
        bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
    time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
debug: if (inherits(res, "try-error")) {
    err <- attr(res, "condition")
    msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
    nc_n_try <- nc_n_try + 1
    if (nc_n_try > n_max_retries) {
        stop(msg)
    }
    else {
        message(msg, "\nRETRYing...")
        Sys.sleep(1)
    }
} else {
    nc_retry <- F
}
debug: nc_retry <- F
debug: (while) nc_retry
debug: i_req <- i_req + 1
debug: (while) i_req <= n_reqs
debug: ncs <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size > 
    0), nc)
debug: r <- terra::rast(ncs)
debug: stopifnot(all(class(terra::time(r)) %in% c("POSIXct", "POSIXt")))
debug: idx <- dplyr::pull(dplyr::filter(dplyr::arrange(dplyr::tibble(idx = 1:terra::nlyr(r), 
    time = terra::time(r)), time), !duplicated(time)), idx)
debug: r <- terra::subset(r, idx)
debug: stopifnot(terra::crs(r, proj = T) == wgs84)
debug: if (mask_tif) r <- terra::mask(r, sf_zones)
debug: lyrs <- glue("{var}|{terra::time(r)}")
debug: if (length(dims_other) > 0 && !all(length(dims[dims_other]) == 
    1)) stop(glue("Other dimensions not yet supported: {paste(dims_other, collapse = ',')}"))
debug: names(r) <- lyrs
debug: if (!is.null(rast_tif)) {
    if (fs::file_exists(rast_tif)) {
        r_tmp_tif <- tempfile(fileext = ".tif")
        r_tmp <- c(rast(rast_tif), r)
        r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
        terra::writeRaster(r_tmp, r_tmp_tif)
        fs::file_delete(rast_tif)
        fs::file_move(r_tmp_tif, rast_tif)
        rm(r)
        rm(r_tmp)
    }
    else {
        terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
    }
    r <- terra::rast(rast_tif)
}
debug: if (fs::file_exists(rast_tif)) {
    r_tmp_tif <- tempfile(fileext = ".tif")
    r_tmp <- c(rast(rast_tif), r)
    r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
    terra::writeRaster(r_tmp, r_tmp_tif)
    fs::file_delete(rast_tif)
    fs::file_move(r_tmp_tif, rast_tif)
    rm(r)
    rm(r_tmp)
} else {
    terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
}
debug: terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
debug: r <- terra::rast(rast_tif)
debug: d_r <- mutate(tidyr::pivot_longer(sf::st_drop_geometry(sf::st_as_sf(terra::zonal(x = r, 
    z = terra::vect(dplyr::select(sf_zones, dplyr::all_of(fld_zones))), 
    fun = zonal_fun, exact = T, na.rm = T, as.polygons = T))), 
    cols = -dplyr::any_of(fld_zones), names_to = "lyr", values_to = zonal_fun), 
    time = readr::parse_datetime(str_replace(lyr, glue("{var}\\|(.*)"), 
        "\\1")))
debug: if (!is.null(zonal_csv)) write_csv(d_r, zonal_csv)
debug: write_csv(d_r, zonal_csv)
debug: if (!keep_nc) unlink(dir_nc, recursive = T)
debug: unlink(dir_nc, recursive = T)
debug: return(d_r)
Downloading 1 requests, up to 111 time slices each
Called from: extractr::ed_extract(ed, var = v, sf_zones = ply, bbox = bb, 
    mask_tif = F, rast_tif = glue("{dir_out}/{nms}/{yr}.tif"), 
    zonal_fun = "mean", zonal_csv = glue("{dir_out}/{nms}/{yr}.csv"), 
    dir_nc = glue("{dir_out}/{nms}/{yr}_nc"), keep_nc = F, n_max_vals_per_req = 1e+05, 
    time_min = time_min, time_max = time_max, verbose = T)
debug: while (i_req <= n_reqs) {
    i_t_beg <- (i_req - 1) * n_t_per_req + 1
    i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
    t_req <- times_todo[c(i_t_beg, i_t_end)]
    t_req_str <- format_ISO8601(t_req, usetz = "Z")
    if (verbose) 
        message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
    ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
        ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
        0), nc)
    unlink(ncs0)
    nc_retry <- T
    nc_n_try <- 1
    n_max_retries
    while (nc_retry) {
        res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
            url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
                bbox[["xmax"]]), latitude = c(bbox[["ymin"]], 
                bbox[["ymax"]]), time = t_req_str, fmt = "nc", 
            store = rerddap::disk(path = dir_nc)))
        if (inherits(res, "try-error")) {
            err <- attr(res, "condition")
            msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
            nc_n_try <- nc_n_try + 1
            if (nc_n_try > n_max_retries) {
                stop(msg)
            }
            else {
                message(msg, "\nRETRYing...")
                Sys.sleep(1)
            }
        }
        else {
            nc_retry <- F
        }
    }
    i_req <- i_req + 1
}
debug: i_t_beg <- (i_req - 1) * n_t_per_req + 1
debug: i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
debug: t_req <- times_todo[c(i_t_beg, i_t_end)]
debug: t_req_str <- format_ISO8601(t_req, usetz = "Z")
debug: if (verbose) message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
debug: message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
Fetching request 1 of 1 (2017-01-01 to 2017-12-01) ~ 19:40:09 UTC
debug: ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
    0), nc)
debug: unlink(ncs0)
debug: nc_retry <- T
debug: nc_n_try <- 1
debug: n_max_retries
debug: while (nc_retry) {
    res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
        url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
            bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
        time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
    if (inherits(res, "try-error")) {
        err <- attr(res, "condition")
        msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
        nc_n_try <- nc_n_try + 1
        if (nc_n_try > n_max_retries) {
            stop(msg)
        }
        else {
            message(msg, "\nRETRYing...")
            Sys.sleep(1)
        }
    }
    else {
        nc_retry <- F
    }
}
debug: res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
    url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
        bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
    time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
debug: if (inherits(res, "try-error")) {
    err <- attr(res, "condition")
    msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
    nc_n_try <- nc_n_try + 1
    if (nc_n_try > n_max_retries) {
        stop(msg)
    }
    else {
        message(msg, "\nRETRYing...")
        Sys.sleep(1)
    }
} else {
    nc_retry <- F
}
debug: nc_retry <- F
debug: (while) nc_retry
debug: i_req <- i_req + 1
debug: (while) i_req <= n_reqs
debug: ncs <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size > 
    0), nc)
debug: r <- terra::rast(ncs)
debug: stopifnot(all(class(terra::time(r)) %in% c("POSIXct", "POSIXt")))
debug: idx <- dplyr::pull(dplyr::filter(dplyr::arrange(dplyr::tibble(idx = 1:terra::nlyr(r), 
    time = terra::time(r)), time), !duplicated(time)), idx)
debug: r <- terra::subset(r, idx)
debug: stopifnot(terra::crs(r, proj = T) == wgs84)
debug: if (mask_tif) r <- terra::mask(r, sf_zones)
debug: lyrs <- glue("{var}|{terra::time(r)}")
debug: if (length(dims_other) > 0 && !all(length(dims[dims_other]) == 
    1)) stop(glue("Other dimensions not yet supported: {paste(dims_other, collapse = ',')}"))
debug: names(r) <- lyrs
debug: if (!is.null(rast_tif)) {
    if (fs::file_exists(rast_tif)) {
        r_tmp_tif <- tempfile(fileext = ".tif")
        r_tmp <- c(rast(rast_tif), r)
        r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
        terra::writeRaster(r_tmp, r_tmp_tif)
        fs::file_delete(rast_tif)
        fs::file_move(r_tmp_tif, rast_tif)
        rm(r)
        rm(r_tmp)
    }
    else {
        terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
    }
    r <- terra::rast(rast_tif)
}
debug: if (fs::file_exists(rast_tif)) {
    r_tmp_tif <- tempfile(fileext = ".tif")
    r_tmp <- c(rast(rast_tif), r)
    r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
    terra::writeRaster(r_tmp, r_tmp_tif)
    fs::file_delete(rast_tif)
    fs::file_move(r_tmp_tif, rast_tif)
    rm(r)
    rm(r_tmp)
} else {
    terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
}
debug: terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
debug: r <- terra::rast(rast_tif)
debug: d_r <- mutate(tidyr::pivot_longer(sf::st_drop_geometry(sf::st_as_sf(terra::zonal(x = r, 
    z = terra::vect(dplyr::select(sf_zones, dplyr::all_of(fld_zones))), 
    fun = zonal_fun, exact = T, na.rm = T, as.polygons = T))), 
    cols = -dplyr::any_of(fld_zones), names_to = "lyr", values_to = zonal_fun), 
    time = readr::parse_datetime(str_replace(lyr, glue("{var}\\|(.*)"), 
        "\\1")))
debug: if (!is.null(zonal_csv)) write_csv(d_r, zonal_csv)
debug: write_csv(d_r, zonal_csv)
debug: if (!keep_nc) unlink(dir_nc, recursive = T)
debug: unlink(dir_nc, recursive = T)
debug: return(d_r)
Downloading 1 requests, up to 111 time slices each
Called from: extractr::ed_extract(ed, var = v, sf_zones = ply, bbox = bb, 
    mask_tif = F, rast_tif = glue("{dir_out}/{nms}/{yr}.tif"), 
    zonal_fun = "mean", zonal_csv = glue("{dir_out}/{nms}/{yr}.csv"), 
    dir_nc = glue("{dir_out}/{nms}/{yr}_nc"), keep_nc = F, n_max_vals_per_req = 1e+05, 
    time_min = time_min, time_max = time_max, verbose = T)
debug: while (i_req <= n_reqs) {
    i_t_beg <- (i_req - 1) * n_t_per_req + 1
    i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
    t_req <- times_todo[c(i_t_beg, i_t_end)]
    t_req_str <- format_ISO8601(t_req, usetz = "Z")
    if (verbose) 
        message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
    ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
        ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
        0), nc)
    unlink(ncs0)
    nc_retry <- T
    nc_n_try <- 1
    n_max_retries
    while (nc_retry) {
        res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
            url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
                bbox[["xmax"]]), latitude = c(bbox[["ymin"]], 
                bbox[["ymax"]]), time = t_req_str, fmt = "nc", 
            store = rerddap::disk(path = dir_nc)))
        if (inherits(res, "try-error")) {
            err <- attr(res, "condition")
            msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
            nc_n_try <- nc_n_try + 1
            if (nc_n_try > n_max_retries) {
                stop(msg)
            }
            else {
                message(msg, "\nRETRYing...")
                Sys.sleep(1)
            }
        }
        else {
            nc_retry <- F
        }
    }
    i_req <- i_req + 1
}
debug: i_t_beg <- (i_req - 1) * n_t_per_req + 1
debug: i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
debug: t_req <- times_todo[c(i_t_beg, i_t_end)]
debug: t_req_str <- format_ISO8601(t_req, usetz = "Z")
debug: if (verbose) message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
debug: message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
Fetching request 1 of 1 (2018-01-01 to 2018-12-01) ~ 19:40:11 UTC
debug: ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
    0), nc)
debug: unlink(ncs0)
debug: nc_retry <- T
debug: nc_n_try <- 1
debug: n_max_retries
debug: while (nc_retry) {
    res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
        url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
            bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
        time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
    if (inherits(res, "try-error")) {
        err <- attr(res, "condition")
        msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
        nc_n_try <- nc_n_try + 1
        if (nc_n_try > n_max_retries) {
            stop(msg)
        }
        else {
            message(msg, "\nRETRYing...")
            Sys.sleep(1)
        }
    }
    else {
        nc_retry <- F
    }
}
debug: res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
    url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
        bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
    time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
debug: if (inherits(res, "try-error")) {
    err <- attr(res, "condition")
    msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
    nc_n_try <- nc_n_try + 1
    if (nc_n_try > n_max_retries) {
        stop(msg)
    }
    else {
        message(msg, "\nRETRYing...")
        Sys.sleep(1)
    }
} else {
    nc_retry <- F
}
debug: nc_retry <- F
debug: (while) nc_retry
debug: i_req <- i_req + 1
debug: (while) i_req <= n_reqs
debug: ncs <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size > 
    0), nc)
debug: r <- terra::rast(ncs)
debug: stopifnot(all(class(terra::time(r)) %in% c("POSIXct", "POSIXt")))
debug: idx <- dplyr::pull(dplyr::filter(dplyr::arrange(dplyr::tibble(idx = 1:terra::nlyr(r), 
    time = terra::time(r)), time), !duplicated(time)), idx)
debug: r <- terra::subset(r, idx)
debug: stopifnot(terra::crs(r, proj = T) == wgs84)
debug: if (mask_tif) r <- terra::mask(r, sf_zones)
debug: lyrs <- glue("{var}|{terra::time(r)}")
debug: if (length(dims_other) > 0 && !all(length(dims[dims_other]) == 
    1)) stop(glue("Other dimensions not yet supported: {paste(dims_other, collapse = ',')}"))
debug: names(r) <- lyrs
debug: if (!is.null(rast_tif)) {
    if (fs::file_exists(rast_tif)) {
        r_tmp_tif <- tempfile(fileext = ".tif")
        r_tmp <- c(rast(rast_tif), r)
        r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
        terra::writeRaster(r_tmp, r_tmp_tif)
        fs::file_delete(rast_tif)
        fs::file_move(r_tmp_tif, rast_tif)
        rm(r)
        rm(r_tmp)
    }
    else {
        terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
    }
    r <- terra::rast(rast_tif)
}
debug: if (fs::file_exists(rast_tif)) {
    r_tmp_tif <- tempfile(fileext = ".tif")
    r_tmp <- c(rast(rast_tif), r)
    r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
    terra::writeRaster(r_tmp, r_tmp_tif)
    fs::file_delete(rast_tif)
    fs::file_move(r_tmp_tif, rast_tif)
    rm(r)
    rm(r_tmp)
} else {
    terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
}
debug: terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
debug: r <- terra::rast(rast_tif)
debug: d_r <- mutate(tidyr::pivot_longer(sf::st_drop_geometry(sf::st_as_sf(terra::zonal(x = r, 
    z = terra::vect(dplyr::select(sf_zones, dplyr::all_of(fld_zones))), 
    fun = zonal_fun, exact = T, na.rm = T, as.polygons = T))), 
    cols = -dplyr::any_of(fld_zones), names_to = "lyr", values_to = zonal_fun), 
    time = readr::parse_datetime(str_replace(lyr, glue("{var}\\|(.*)"), 
        "\\1")))
debug: if (!is.null(zonal_csv)) write_csv(d_r, zonal_csv)
debug: write_csv(d_r, zonal_csv)
debug: if (!keep_nc) unlink(dir_nc, recursive = T)
debug: unlink(dir_nc, recursive = T)
debug: return(d_r)
Downloading 1 requests, up to 111 time slices each
Called from: extractr::ed_extract(ed, var = v, sf_zones = ply, bbox = bb, 
    mask_tif = F, rast_tif = glue("{dir_out}/{nms}/{yr}.tif"), 
    zonal_fun = "mean", zonal_csv = glue("{dir_out}/{nms}/{yr}.csv"), 
    dir_nc = glue("{dir_out}/{nms}/{yr}_nc"), keep_nc = F, n_max_vals_per_req = 1e+05, 
    time_min = time_min, time_max = time_max, verbose = T)
debug: while (i_req <= n_reqs) {
    i_t_beg <- (i_req - 1) * n_t_per_req + 1
    i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
    t_req <- times_todo[c(i_t_beg, i_t_end)]
    t_req_str <- format_ISO8601(t_req, usetz = "Z")
    if (verbose) 
        message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
    ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
        ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
        0), nc)
    unlink(ncs0)
    nc_retry <- T
    nc_n_try <- 1
    n_max_retries
    while (nc_retry) {
        res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
            url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
                bbox[["xmax"]]), latitude = c(bbox[["ymin"]], 
                bbox[["ymax"]]), time = t_req_str, fmt = "nc", 
            store = rerddap::disk(path = dir_nc)))
        if (inherits(res, "try-error")) {
            err <- attr(res, "condition")
            msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
            nc_n_try <- nc_n_try + 1
            if (nc_n_try > n_max_retries) {
                stop(msg)
            }
            else {
                message(msg, "\nRETRYing...")
                Sys.sleep(1)
            }
        }
        else {
            nc_retry <- F
        }
    }
    i_req <- i_req + 1
}
debug: i_t_beg <- (i_req - 1) * n_t_per_req + 1
debug: i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
debug: t_req <- times_todo[c(i_t_beg, i_t_end)]
debug: t_req_str <- format_ISO8601(t_req, usetz = "Z")
debug: if (verbose) message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
debug: message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
Fetching request 1 of 1 (2019-01-01 to 2019-12-01) ~ 19:40:13 UTC
debug: ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
    0), nc)
debug: unlink(ncs0)
debug: nc_retry <- T
debug: nc_n_try <- 1
debug: n_max_retries
debug: while (nc_retry) {
    res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
        url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
            bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
        time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
    if (inherits(res, "try-error")) {
        err <- attr(res, "condition")
        msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
        nc_n_try <- nc_n_try + 1
        if (nc_n_try > n_max_retries) {
            stop(msg)
        }
        else {
            message(msg, "\nRETRYing...")
            Sys.sleep(1)
        }
    }
    else {
        nc_retry <- F
    }
}
debug: res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
    url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
        bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
    time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
debug: if (inherits(res, "try-error")) {
    err <- attr(res, "condition")
    msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
    nc_n_try <- nc_n_try + 1
    if (nc_n_try > n_max_retries) {
        stop(msg)
    }
    else {
        message(msg, "\nRETRYing...")
        Sys.sleep(1)
    }
} else {
    nc_retry <- F
}
debug: nc_retry <- F
debug: (while) nc_retry
debug: i_req <- i_req + 1
debug: (while) i_req <= n_reqs
debug: ncs <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size > 
    0), nc)
debug: r <- terra::rast(ncs)
debug: stopifnot(all(class(terra::time(r)) %in% c("POSIXct", "POSIXt")))
debug: idx <- dplyr::pull(dplyr::filter(dplyr::arrange(dplyr::tibble(idx = 1:terra::nlyr(r), 
    time = terra::time(r)), time), !duplicated(time)), idx)
debug: r <- terra::subset(r, idx)
debug: stopifnot(terra::crs(r, proj = T) == wgs84)
debug: if (mask_tif) r <- terra::mask(r, sf_zones)
debug: lyrs <- glue("{var}|{terra::time(r)}")
debug: if (length(dims_other) > 0 && !all(length(dims[dims_other]) == 
    1)) stop(glue("Other dimensions not yet supported: {paste(dims_other, collapse = ',')}"))
debug: names(r) <- lyrs
debug: if (!is.null(rast_tif)) {
    if (fs::file_exists(rast_tif)) {
        r_tmp_tif <- tempfile(fileext = ".tif")
        r_tmp <- c(rast(rast_tif), r)
        r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
        terra::writeRaster(r_tmp, r_tmp_tif)
        fs::file_delete(rast_tif)
        fs::file_move(r_tmp_tif, rast_tif)
        rm(r)
        rm(r_tmp)
    }
    else {
        terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
    }
    r <- terra::rast(rast_tif)
}
debug: if (fs::file_exists(rast_tif)) {
    r_tmp_tif <- tempfile(fileext = ".tif")
    r_tmp <- c(rast(rast_tif), r)
    r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
    terra::writeRaster(r_tmp, r_tmp_tif)
    fs::file_delete(rast_tif)
    fs::file_move(r_tmp_tif, rast_tif)
    rm(r)
    rm(r_tmp)
} else {
    terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
}
debug: terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
debug: r <- terra::rast(rast_tif)
debug: d_r <- mutate(tidyr::pivot_longer(sf::st_drop_geometry(sf::st_as_sf(terra::zonal(x = r, 
    z = terra::vect(dplyr::select(sf_zones, dplyr::all_of(fld_zones))), 
    fun = zonal_fun, exact = T, na.rm = T, as.polygons = T))), 
    cols = -dplyr::any_of(fld_zones), names_to = "lyr", values_to = zonal_fun), 
    time = readr::parse_datetime(str_replace(lyr, glue("{var}\\|(.*)"), 
        "\\1")))
debug: if (!is.null(zonal_csv)) write_csv(d_r, zonal_csv)
debug: write_csv(d_r, zonal_csv)
debug: if (!keep_nc) unlink(dir_nc, recursive = T)
debug: unlink(dir_nc, recursive = T)
debug: return(d_r)
Downloading 1 requests, up to 111 time slices each
Called from: extractr::ed_extract(ed, var = v, sf_zones = ply, bbox = bb, 
    mask_tif = F, rast_tif = glue("{dir_out}/{nms}/{yr}.tif"), 
    zonal_fun = "mean", zonal_csv = glue("{dir_out}/{nms}/{yr}.csv"), 
    dir_nc = glue("{dir_out}/{nms}/{yr}_nc"), keep_nc = F, n_max_vals_per_req = 1e+05, 
    time_min = time_min, time_max = time_max, verbose = T)
debug: while (i_req <= n_reqs) {
    i_t_beg <- (i_req - 1) * n_t_per_req + 1
    i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
    t_req <- times_todo[c(i_t_beg, i_t_end)]
    t_req_str <- format_ISO8601(t_req, usetz = "Z")
    if (verbose) 
        message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
    ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
        ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
        0), nc)
    unlink(ncs0)
    nc_retry <- T
    nc_n_try <- 1
    n_max_retries
    while (nc_retry) {
        res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
            url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
                bbox[["xmax"]]), latitude = c(bbox[["ymin"]], 
                bbox[["ymax"]]), time = t_req_str, fmt = "nc", 
            store = rerddap::disk(path = dir_nc)))
        if (inherits(res, "try-error")) {
            err <- attr(res, "condition")
            msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
            nc_n_try <- nc_n_try + 1
            if (nc_n_try > n_max_retries) {
                stop(msg)
            }
            else {
                message(msg, "\nRETRYing...")
                Sys.sleep(1)
            }
        }
        else {
            nc_retry <- F
        }
    }
    i_req <- i_req + 1
}
debug: i_t_beg <- (i_req - 1) * n_t_per_req + 1
debug: i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
debug: t_req <- times_todo[c(i_t_beg, i_t_end)]
debug: t_req_str <- format_ISO8601(t_req, usetz = "Z")
debug: if (verbose) message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
debug: message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
Fetching request 1 of 1 (2020-01-01 to 2020-12-01) ~ 19:40:15 UTC
debug: ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
    0), nc)
debug: unlink(ncs0)
debug: nc_retry <- T
debug: nc_n_try <- 1
debug: n_max_retries
debug: while (nc_retry) {
    res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
        url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
            bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
        time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
    if (inherits(res, "try-error")) {
        err <- attr(res, "condition")
        msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
        nc_n_try <- nc_n_try + 1
        if (nc_n_try > n_max_retries) {
            stop(msg)
        }
        else {
            message(msg, "\nRETRYing...")
            Sys.sleep(1)
        }
    }
    else {
        nc_retry <- F
    }
}
debug: res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
    url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
        bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
    time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
debug: if (inherits(res, "try-error")) {
    err <- attr(res, "condition")
    msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
    nc_n_try <- nc_n_try + 1
    if (nc_n_try > n_max_retries) {
        stop(msg)
    }
    else {
        message(msg, "\nRETRYing...")
        Sys.sleep(1)
    }
} else {
    nc_retry <- F
}
debug: nc_retry <- F
debug: (while) nc_retry
debug: i_req <- i_req + 1
debug: (while) i_req <= n_reqs
debug: ncs <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size > 
    0), nc)
debug: r <- terra::rast(ncs)
debug: stopifnot(all(class(terra::time(r)) %in% c("POSIXct", "POSIXt")))
debug: idx <- dplyr::pull(dplyr::filter(dplyr::arrange(dplyr::tibble(idx = 1:terra::nlyr(r), 
    time = terra::time(r)), time), !duplicated(time)), idx)
debug: r <- terra::subset(r, idx)
debug: stopifnot(terra::crs(r, proj = T) == wgs84)
debug: if (mask_tif) r <- terra::mask(r, sf_zones)
debug: lyrs <- glue("{var}|{terra::time(r)}")
debug: if (length(dims_other) > 0 && !all(length(dims[dims_other]) == 
    1)) stop(glue("Other dimensions not yet supported: {paste(dims_other, collapse = ',')}"))
debug: names(r) <- lyrs
debug: if (!is.null(rast_tif)) {
    if (fs::file_exists(rast_tif)) {
        r_tmp_tif <- tempfile(fileext = ".tif")
        r_tmp <- c(rast(rast_tif), r)
        r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
        terra::writeRaster(r_tmp, r_tmp_tif)
        fs::file_delete(rast_tif)
        fs::file_move(r_tmp_tif, rast_tif)
        rm(r)
        rm(r_tmp)
    }
    else {
        terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
    }
    r <- terra::rast(rast_tif)
}
debug: if (fs::file_exists(rast_tif)) {
    r_tmp_tif <- tempfile(fileext = ".tif")
    r_tmp <- c(rast(rast_tif), r)
    r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
    terra::writeRaster(r_tmp, r_tmp_tif)
    fs::file_delete(rast_tif)
    fs::file_move(r_tmp_tif, rast_tif)
    rm(r)
    rm(r_tmp)
} else {
    terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
}
debug: terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
debug: r <- terra::rast(rast_tif)
debug: d_r <- mutate(tidyr::pivot_longer(sf::st_drop_geometry(sf::st_as_sf(terra::zonal(x = r, 
    z = terra::vect(dplyr::select(sf_zones, dplyr::all_of(fld_zones))), 
    fun = zonal_fun, exact = T, na.rm = T, as.polygons = T))), 
    cols = -dplyr::any_of(fld_zones), names_to = "lyr", values_to = zonal_fun), 
    time = readr::parse_datetime(str_replace(lyr, glue("{var}\\|(.*)"), 
        "\\1")))
debug: if (!is.null(zonal_csv)) write_csv(d_r, zonal_csv)
debug: write_csv(d_r, zonal_csv)
debug: if (!keep_nc) unlink(dir_nc, recursive = T)
debug: unlink(dir_nc, recursive = T)
debug: return(d_r)
Downloading 1 requests, up to 111 time slices each
Called from: extractr::ed_extract(ed, var = v, sf_zones = ply, bbox = bb, 
    mask_tif = F, rast_tif = glue("{dir_out}/{nms}/{yr}.tif"), 
    zonal_fun = "mean", zonal_csv = glue("{dir_out}/{nms}/{yr}.csv"), 
    dir_nc = glue("{dir_out}/{nms}/{yr}_nc"), keep_nc = F, n_max_vals_per_req = 1e+05, 
    time_min = time_min, time_max = time_max, verbose = T)
debug: while (i_req <= n_reqs) {
    i_t_beg <- (i_req - 1) * n_t_per_req + 1
    i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
    t_req <- times_todo[c(i_t_beg, i_t_end)]
    t_req_str <- format_ISO8601(t_req, usetz = "Z")
    if (verbose) 
        message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
    ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
        ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
        0), nc)
    unlink(ncs0)
    nc_retry <- T
    nc_n_try <- 1
    n_max_retries
    while (nc_retry) {
        res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
            url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
                bbox[["xmax"]]), latitude = c(bbox[["ymin"]], 
                bbox[["ymax"]]), time = t_req_str, fmt = "nc", 
            store = rerddap::disk(path = dir_nc)))
        if (inherits(res, "try-error")) {
            err <- attr(res, "condition")
            msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
            nc_n_try <- nc_n_try + 1
            if (nc_n_try > n_max_retries) {
                stop(msg)
            }
            else {
                message(msg, "\nRETRYing...")
                Sys.sleep(1)
            }
        }
        else {
            nc_retry <- F
        }
    }
    i_req <- i_req + 1
}
debug: i_t_beg <- (i_req - 1) * n_t_per_req + 1
debug: i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
debug: t_req <- times_todo[c(i_t_beg, i_t_end)]
debug: t_req_str <- format_ISO8601(t_req, usetz = "Z")
debug: if (verbose) message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
debug: message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
Fetching request 1 of 1 (2021-01-01 to 2021-12-01) ~ 19:40:17 UTC
debug: ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
    0), nc)
debug: unlink(ncs0)
debug: nc_retry <- T
debug: nc_n_try <- 1
debug: n_max_retries
debug: while (nc_retry) {
    res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
        url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
            bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
        time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
    if (inherits(res, "try-error")) {
        err <- attr(res, "condition")
        msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
        nc_n_try <- nc_n_try + 1
        if (nc_n_try > n_max_retries) {
            stop(msg)
        }
        else {
            message(msg, "\nRETRYing...")
            Sys.sleep(1)
        }
    }
    else {
        nc_retry <- F
    }
}
debug: res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
    url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
        bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
    time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
debug: if (inherits(res, "try-error")) {
    err <- attr(res, "condition")
    msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
    nc_n_try <- nc_n_try + 1
    if (nc_n_try > n_max_retries) {
        stop(msg)
    }
    else {
        message(msg, "\nRETRYing...")
        Sys.sleep(1)
    }
} else {
    nc_retry <- F
}
debug: nc_retry <- F
debug: (while) nc_retry
debug: i_req <- i_req + 1
debug: (while) i_req <= n_reqs
debug: ncs <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size > 
    0), nc)
debug: r <- terra::rast(ncs)
debug: stopifnot(all(class(terra::time(r)) %in% c("POSIXct", "POSIXt")))
debug: idx <- dplyr::pull(dplyr::filter(dplyr::arrange(dplyr::tibble(idx = 1:terra::nlyr(r), 
    time = terra::time(r)), time), !duplicated(time)), idx)
debug: r <- terra::subset(r, idx)
debug: stopifnot(terra::crs(r, proj = T) == wgs84)
debug: if (mask_tif) r <- terra::mask(r, sf_zones)
debug: lyrs <- glue("{var}|{terra::time(r)}")
debug: if (length(dims_other) > 0 && !all(length(dims[dims_other]) == 
    1)) stop(glue("Other dimensions not yet supported: {paste(dims_other, collapse = ',')}"))
debug: names(r) <- lyrs
debug: if (!is.null(rast_tif)) {
    if (fs::file_exists(rast_tif)) {
        r_tmp_tif <- tempfile(fileext = ".tif")
        r_tmp <- c(rast(rast_tif), r)
        r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
        terra::writeRaster(r_tmp, r_tmp_tif)
        fs::file_delete(rast_tif)
        fs::file_move(r_tmp_tif, rast_tif)
        rm(r)
        rm(r_tmp)
    }
    else {
        terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
    }
    r <- terra::rast(rast_tif)
}
debug: if (fs::file_exists(rast_tif)) {
    r_tmp_tif <- tempfile(fileext = ".tif")
    r_tmp <- c(rast(rast_tif), r)
    r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
    terra::writeRaster(r_tmp, r_tmp_tif)
    fs::file_delete(rast_tif)
    fs::file_move(r_tmp_tif, rast_tif)
    rm(r)
    rm(r_tmp)
} else {
    terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
}
debug: terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
debug: r <- terra::rast(rast_tif)
debug: d_r <- mutate(tidyr::pivot_longer(sf::st_drop_geometry(sf::st_as_sf(terra::zonal(x = r, 
    z = terra::vect(dplyr::select(sf_zones, dplyr::all_of(fld_zones))), 
    fun = zonal_fun, exact = T, na.rm = T, as.polygons = T))), 
    cols = -dplyr::any_of(fld_zones), names_to = "lyr", values_to = zonal_fun), 
    time = readr::parse_datetime(str_replace(lyr, glue("{var}\\|(.*)"), 
        "\\1")))
debug: if (!is.null(zonal_csv)) write_csv(d_r, zonal_csv)
debug: write_csv(d_r, zonal_csv)
debug: if (!keep_nc) unlink(dir_nc, recursive = T)
debug: unlink(dir_nc, recursive = T)
debug: return(d_r)
Downloading 1 requests, up to 111 time slices each
Called from: extractr::ed_extract(ed, var = v, sf_zones = ply, bbox = bb, 
    mask_tif = F, rast_tif = glue("{dir_out}/{nms}/{yr}.tif"), 
    zonal_fun = "mean", zonal_csv = glue("{dir_out}/{nms}/{yr}.csv"), 
    dir_nc = glue("{dir_out}/{nms}/{yr}_nc"), keep_nc = F, n_max_vals_per_req = 1e+05, 
    time_min = time_min, time_max = time_max, verbose = T)
debug: while (i_req <= n_reqs) {
    i_t_beg <- (i_req - 1) * n_t_per_req + 1
    i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
    t_req <- times_todo[c(i_t_beg, i_t_end)]
    t_req_str <- format_ISO8601(t_req, usetz = "Z")
    if (verbose) 
        message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
    ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
        ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
        0), nc)
    unlink(ncs0)
    nc_retry <- T
    nc_n_try <- 1
    n_max_retries
    while (nc_retry) {
        res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
            url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
                bbox[["xmax"]]), latitude = c(bbox[["ymin"]], 
                bbox[["ymax"]]), time = t_req_str, fmt = "nc", 
            store = rerddap::disk(path = dir_nc)))
        if (inherits(res, "try-error")) {
            err <- attr(res, "condition")
            msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
            nc_n_try <- nc_n_try + 1
            if (nc_n_try > n_max_retries) {
                stop(msg)
            }
            else {
                message(msg, "\nRETRYing...")
                Sys.sleep(1)
            }
        }
        else {
            nc_retry <- F
        }
    }
    i_req <- i_req + 1
}
debug: i_t_beg <- (i_req - 1) * n_t_per_req + 1
debug: i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
debug: t_req <- times_todo[c(i_t_beg, i_t_end)]
debug: t_req_str <- format_ISO8601(t_req, usetz = "Z")
debug: if (verbose) message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
debug: message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
Fetching request 1 of 1 (2022-01-01 to 2022-12-01) ~ 19:40:19 UTC
debug: ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
    0), nc)
debug: unlink(ncs0)
debug: nc_retry <- T
debug: nc_n_try <- 1
debug: n_max_retries
debug: while (nc_retry) {
    res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
        url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
            bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
        time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
    if (inherits(res, "try-error")) {
        err <- attr(res, "condition")
        msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
        nc_n_try <- nc_n_try + 1
        if (nc_n_try > n_max_retries) {
            stop(msg)
        }
        else {
            message(msg, "\nRETRYing...")
            Sys.sleep(1)
        }
    }
    else {
        nc_retry <- F
    }
}
debug: res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
    url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
        bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
    time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
debug: if (inherits(res, "try-error")) {
    err <- attr(res, "condition")
    msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
    nc_n_try <- nc_n_try + 1
    if (nc_n_try > n_max_retries) {
        stop(msg)
    }
    else {
        message(msg, "\nRETRYing...")
        Sys.sleep(1)
    }
} else {
    nc_retry <- F
}
debug: nc_retry <- F
debug: (while) nc_retry
debug: i_req <- i_req + 1
debug: (while) i_req <= n_reqs
debug: ncs <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size > 
    0), nc)
debug: r <- terra::rast(ncs)
debug: stopifnot(all(class(terra::time(r)) %in% c("POSIXct", "POSIXt")))
debug: idx <- dplyr::pull(dplyr::filter(dplyr::arrange(dplyr::tibble(idx = 1:terra::nlyr(r), 
    time = terra::time(r)), time), !duplicated(time)), idx)
debug: r <- terra::subset(r, idx)
debug: stopifnot(terra::crs(r, proj = T) == wgs84)
debug: if (mask_tif) r <- terra::mask(r, sf_zones)
debug: lyrs <- glue("{var}|{terra::time(r)}")
debug: if (length(dims_other) > 0 && !all(length(dims[dims_other]) == 
    1)) stop(glue("Other dimensions not yet supported: {paste(dims_other, collapse = ',')}"))
debug: names(r) <- lyrs
debug: if (!is.null(rast_tif)) {
    if (fs::file_exists(rast_tif)) {
        r_tmp_tif <- tempfile(fileext = ".tif")
        r_tmp <- c(rast(rast_tif), r)
        r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
        terra::writeRaster(r_tmp, r_tmp_tif)
        fs::file_delete(rast_tif)
        fs::file_move(r_tmp_tif, rast_tif)
        rm(r)
        rm(r_tmp)
    }
    else {
        terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
    }
    r <- terra::rast(rast_tif)
}
debug: if (fs::file_exists(rast_tif)) {
    r_tmp_tif <- tempfile(fileext = ".tif")
    r_tmp <- c(rast(rast_tif), r)
    r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
    terra::writeRaster(r_tmp, r_tmp_tif)
    fs::file_delete(rast_tif)
    fs::file_move(r_tmp_tif, rast_tif)
    rm(r)
    rm(r_tmp)
} else {
    terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
}
debug: terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
debug: r <- terra::rast(rast_tif)
debug: d_r <- mutate(tidyr::pivot_longer(sf::st_drop_geometry(sf::st_as_sf(terra::zonal(x = r, 
    z = terra::vect(dplyr::select(sf_zones, dplyr::all_of(fld_zones))), 
    fun = zonal_fun, exact = T, na.rm = T, as.polygons = T))), 
    cols = -dplyr::any_of(fld_zones), names_to = "lyr", values_to = zonal_fun), 
    time = readr::parse_datetime(str_replace(lyr, glue("{var}\\|(.*)"), 
        "\\1")))
debug: if (!is.null(zonal_csv)) write_csv(d_r, zonal_csv)
debug: write_csv(d_r, zonal_csv)
debug: if (!keep_nc) unlink(dir_nc, recursive = T)
debug: unlink(dir_nc, recursive = T)
debug: return(d_r)
Downloading 1 requests, up to 111 time slices each
Called from: extractr::ed_extract(ed, var = v, sf_zones = ply, bbox = bb, 
    mask_tif = F, rast_tif = glue("{dir_out}/{nms}/{yr}.tif"), 
    zonal_fun = "mean", zonal_csv = glue("{dir_out}/{nms}/{yr}.csv"), 
    dir_nc = glue("{dir_out}/{nms}/{yr}_nc"), keep_nc = F, n_max_vals_per_req = 1e+05, 
    time_min = time_min, time_max = time_max, verbose = T)
debug: while (i_req <= n_reqs) {
    i_t_beg <- (i_req - 1) * n_t_per_req + 1
    i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
    t_req <- times_todo[c(i_t_beg, i_t_end)]
    t_req_str <- format_ISO8601(t_req, usetz = "Z")
    if (verbose) 
        message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
    ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
        ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
        0), nc)
    unlink(ncs0)
    nc_retry <- T
    nc_n_try <- 1
    n_max_retries
    while (nc_retry) {
        res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
            url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
                bbox[["xmax"]]), latitude = c(bbox[["ymin"]], 
                bbox[["ymax"]]), time = t_req_str, fmt = "nc", 
            store = rerddap::disk(path = dir_nc)))
        if (inherits(res, "try-error")) {
            err <- attr(res, "condition")
            msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
            nc_n_try <- nc_n_try + 1
            if (nc_n_try > n_max_retries) {
                stop(msg)
            }
            else {
                message(msg, "\nRETRYing...")
                Sys.sleep(1)
            }
        }
        else {
            nc_retry <- F
        }
    }
    i_req <- i_req + 1
}
debug: i_t_beg <- (i_req - 1) * n_t_per_req + 1
debug: i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
debug: t_req <- times_todo[c(i_t_beg, i_t_end)]
debug: t_req_str <- format_ISO8601(t_req, usetz = "Z")
debug: if (verbose) message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
debug: message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
Fetching request 1 of 1 (2023-01-01 to 2023-12-01) ~ 19:40:21 UTC
debug: ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
    0), nc)
debug: unlink(ncs0)
debug: nc_retry <- T
debug: nc_n_try <- 1
debug: n_max_retries
debug: while (nc_retry) {
    res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
        url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
            bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
        time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
    if (inherits(res, "try-error")) {
        err <- attr(res, "condition")
        msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
        nc_n_try <- nc_n_try + 1
        if (nc_n_try > n_max_retries) {
            stop(msg)
        }
        else {
            message(msg, "\nRETRYing...")
            Sys.sleep(1)
        }
    }
    else {
        nc_retry <- F
    }
}
debug: res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
    url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
        bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
    time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
debug: if (inherits(res, "try-error")) {
    err <- attr(res, "condition")
    msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
    nc_n_try <- nc_n_try + 1
    if (nc_n_try > n_max_retries) {
        stop(msg)
    }
    else {
        message(msg, "\nRETRYing...")
        Sys.sleep(1)
    }
} else {
    nc_retry <- F
}
debug: nc_retry <- F
debug: (while) nc_retry
debug: i_req <- i_req + 1
debug: (while) i_req <= n_reqs
debug: ncs <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size > 
    0), nc)
debug: r <- terra::rast(ncs)
debug: stopifnot(all(class(terra::time(r)) %in% c("POSIXct", "POSIXt")))
debug: idx <- dplyr::pull(dplyr::filter(dplyr::arrange(dplyr::tibble(idx = 1:terra::nlyr(r), 
    time = terra::time(r)), time), !duplicated(time)), idx)
debug: r <- terra::subset(r, idx)
debug: stopifnot(terra::crs(r, proj = T) == wgs84)
debug: if (mask_tif) r <- terra::mask(r, sf_zones)
debug: lyrs <- glue("{var}|{terra::time(r)}")
debug: if (length(dims_other) > 0 && !all(length(dims[dims_other]) == 
    1)) stop(glue("Other dimensions not yet supported: {paste(dims_other, collapse = ',')}"))
debug: names(r) <- lyrs
debug: if (!is.null(rast_tif)) {
    if (fs::file_exists(rast_tif)) {
        r_tmp_tif <- tempfile(fileext = ".tif")
        r_tmp <- c(rast(rast_tif), r)
        r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
        terra::writeRaster(r_tmp, r_tmp_tif)
        fs::file_delete(rast_tif)
        fs::file_move(r_tmp_tif, rast_tif)
        rm(r)
        rm(r_tmp)
    }
    else {
        terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
    }
    r <- terra::rast(rast_tif)
}
debug: if (fs::file_exists(rast_tif)) {
    r_tmp_tif <- tempfile(fileext = ".tif")
    r_tmp <- c(rast(rast_tif), r)
    r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
    terra::writeRaster(r_tmp, r_tmp_tif)
    fs::file_delete(rast_tif)
    fs::file_move(r_tmp_tif, rast_tif)
    rm(r)
    rm(r_tmp)
} else {
    terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
}
debug: terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
debug: r <- terra::rast(rast_tif)
debug: d_r <- mutate(tidyr::pivot_longer(sf::st_drop_geometry(sf::st_as_sf(terra::zonal(x = r, 
    z = terra::vect(dplyr::select(sf_zones, dplyr::all_of(fld_zones))), 
    fun = zonal_fun, exact = T, na.rm = T, as.polygons = T))), 
    cols = -dplyr::any_of(fld_zones), names_to = "lyr", values_to = zonal_fun), 
    time = readr::parse_datetime(str_replace(lyr, glue("{var}\\|(.*)"), 
        "\\1")))
debug: if (!is.null(zonal_csv)) write_csv(d_r, zonal_csv)
debug: write_csv(d_r, zonal_csv)
debug: if (!keep_nc) unlink(dir_nc, recursive = T)
debug: unlink(dir_nc, recursive = T)
debug: return(d_r)
Downloading 1 requests, up to 111 time slices each
Called from: extractr::ed_extract(ed, var = v, sf_zones = ply, bbox = bb, 
    mask_tif = F, rast_tif = glue("{dir_out}/{nms}/{yr}.tif"), 
    zonal_fun = "mean", zonal_csv = glue("{dir_out}/{nms}/{yr}.csv"), 
    dir_nc = glue("{dir_out}/{nms}/{yr}_nc"), keep_nc = F, n_max_vals_per_req = 1e+05, 
    time_min = time_min, time_max = time_max, verbose = T)
debug: while (i_req <= n_reqs) {
    i_t_beg <- (i_req - 1) * n_t_per_req + 1
    i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
    t_req <- times_todo[c(i_t_beg, i_t_end)]
    t_req_str <- format_ISO8601(t_req, usetz = "Z")
    if (verbose) 
        message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
    ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
        ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
        0), nc)
    unlink(ncs0)
    nc_retry <- T
    nc_n_try <- 1
    n_max_retries
    while (nc_retry) {
        res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
            url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
                bbox[["xmax"]]), latitude = c(bbox[["ymin"]], 
                bbox[["ymax"]]), time = t_req_str, fmt = "nc", 
            store = rerddap::disk(path = dir_nc)))
        if (inherits(res, "try-error")) {
            err <- attr(res, "condition")
            msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
            nc_n_try <- nc_n_try + 1
            if (nc_n_try > n_max_retries) {
                stop(msg)
            }
            else {
                message(msg, "\nRETRYing...")
                Sys.sleep(1)
            }
        }
        else {
            nc_retry <- F
        }
    }
    i_req <- i_req + 1
}
debug: i_t_beg <- (i_req - 1) * n_t_per_req + 1
debug: i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
debug: t_req <- times_todo[c(i_t_beg, i_t_end)]
debug: t_req_str <- format_ISO8601(t_req, usetz = "Z")
debug: if (verbose) message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
debug: message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
Fetching request 1 of 1 (2024-01-01 to 2024-12-01) ~ 19:40:23 UTC
debug: ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
    0), nc)
debug: unlink(ncs0)
debug: nc_retry <- T
debug: nc_n_try <- 1
debug: n_max_retries
debug: while (nc_retry) {
    res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
        url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
            bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
        time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
    if (inherits(res, "try-error")) {
        err <- attr(res, "condition")
        msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
        nc_n_try <- nc_n_try + 1
        if (nc_n_try > n_max_retries) {
            stop(msg)
        }
        else {
            message(msg, "\nRETRYing...")
            Sys.sleep(1)
        }
    }
    else {
        nc_retry <- F
    }
}
debug: res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
    url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
        bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
    time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
debug: if (inherits(res, "try-error")) {
    err <- attr(res, "condition")
    msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
    nc_n_try <- nc_n_try + 1
    if (nc_n_try > n_max_retries) {
        stop(msg)
    }
    else {
        message(msg, "\nRETRYing...")
        Sys.sleep(1)
    }
} else {
    nc_retry <- F
}
debug: nc_retry <- F
debug: (while) nc_retry
debug: i_req <- i_req + 1
debug: (while) i_req <= n_reqs
debug: ncs <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size > 
    0), nc)
debug: r <- terra::rast(ncs)
debug: stopifnot(all(class(terra::time(r)) %in% c("POSIXct", "POSIXt")))
debug: idx <- dplyr::pull(dplyr::filter(dplyr::arrange(dplyr::tibble(idx = 1:terra::nlyr(r), 
    time = terra::time(r)), time), !duplicated(time)), idx)
debug: r <- terra::subset(r, idx)
debug: stopifnot(terra::crs(r, proj = T) == wgs84)
debug: if (mask_tif) r <- terra::mask(r, sf_zones)
debug: lyrs <- glue("{var}|{terra::time(r)}")
debug: if (length(dims_other) > 0 && !all(length(dims[dims_other]) == 
    1)) stop(glue("Other dimensions not yet supported: {paste(dims_other, collapse = ',')}"))
debug: names(r) <- lyrs
debug: if (!is.null(rast_tif)) {
    if (fs::file_exists(rast_tif)) {
        r_tmp_tif <- tempfile(fileext = ".tif")
        r_tmp <- c(rast(rast_tif), r)
        r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
        terra::writeRaster(r_tmp, r_tmp_tif)
        fs::file_delete(rast_tif)
        fs::file_move(r_tmp_tif, rast_tif)
        rm(r)
        rm(r_tmp)
    }
    else {
        terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
    }
    r <- terra::rast(rast_tif)
}
debug: if (fs::file_exists(rast_tif)) {
    r_tmp_tif <- tempfile(fileext = ".tif")
    r_tmp <- c(rast(rast_tif), r)
    r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
    terra::writeRaster(r_tmp, r_tmp_tif)
    fs::file_delete(rast_tif)
    fs::file_move(r_tmp_tif, rast_tif)
    rm(r)
    rm(r_tmp)
} else {
    terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
}
debug: terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
debug: r <- terra::rast(rast_tif)
debug: d_r <- mutate(tidyr::pivot_longer(sf::st_drop_geometry(sf::st_as_sf(terra::zonal(x = r, 
    z = terra::vect(dplyr::select(sf_zones, dplyr::all_of(fld_zones))), 
    fun = zonal_fun, exact = T, na.rm = T, as.polygons = T))), 
    cols = -dplyr::any_of(fld_zones), names_to = "lyr", values_to = zonal_fun), 
    time = readr::parse_datetime(str_replace(lyr, glue("{var}\\|(.*)"), 
        "\\1")))
debug: if (!is.null(zonal_csv)) write_csv(d_r, zonal_csv)
debug: write_csv(d_r, zonal_csv)
debug: if (!keep_nc) unlink(dir_nc, recursive = T)
debug: unlink(dir_nc, recursive = T)
debug: return(d_r)
Downloading 1 requests, up to 111 time slices each
Called from: extractr::ed_extract(ed, var = v, sf_zones = ply, bbox = bb, 
    mask_tif = F, rast_tif = glue("{dir_out}/{nms}/{yr}.tif"), 
    zonal_fun = "mean", zonal_csv = glue("{dir_out}/{nms}/{yr}.csv"), 
    dir_nc = glue("{dir_out}/{nms}/{yr}_nc"), keep_nc = F, n_max_vals_per_req = 1e+05, 
    time_min = time_min, time_max = time_max, verbose = T)
debug: while (i_req <= n_reqs) {
    i_t_beg <- (i_req - 1) * n_t_per_req + 1
    i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
    t_req <- times_todo[c(i_t_beg, i_t_end)]
    t_req_str <- format_ISO8601(t_req, usetz = "Z")
    if (verbose) 
        message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
    ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
        ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
        0), nc)
    unlink(ncs0)
    nc_retry <- T
    nc_n_try <- 1
    n_max_retries
    while (nc_retry) {
        res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
            url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
                bbox[["xmax"]]), latitude = c(bbox[["ymin"]], 
                bbox[["ymax"]]), time = t_req_str, fmt = "nc", 
            store = rerddap::disk(path = dir_nc)))
        if (inherits(res, "try-error")) {
            err <- attr(res, "condition")
            msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
            nc_n_try <- nc_n_try + 1
            if (nc_n_try > n_max_retries) {
                stop(msg)
            }
            else {
                message(msg, "\nRETRYing...")
                Sys.sleep(1)
            }
        }
        else {
            nc_retry <- F
        }
    }
    i_req <- i_req + 1
}
debug: i_t_beg <- (i_req - 1) * n_t_per_req + 1
debug: i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
debug: t_req <- times_todo[c(i_t_beg, i_t_end)]
debug: t_req_str <- format_ISO8601(t_req, usetz = "Z")
debug: if (verbose) message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
debug: message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
Fetching request 1 of 1 (2025-01-01 to 2025-07-01) ~ 19:40:26 UTC
debug: ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
    0), nc)
debug: unlink(ncs0)
debug: nc_retry <- T
debug: nc_n_try <- 1
debug: n_max_retries
debug: while (nc_retry) {
    res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
        url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
            bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
        time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
    if (inherits(res, "try-error")) {
        err <- attr(res, "condition")
        msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
        nc_n_try <- nc_n_try + 1
        if (nc_n_try > n_max_retries) {
            stop(msg)
        }
        else {
            message(msg, "\nRETRYing...")
            Sys.sleep(1)
        }
    }
    else {
        nc_retry <- F
    }
}
debug: res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
    url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
        bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
    time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
debug: if (inherits(res, "try-error")) {
    err <- attr(res, "condition")
    msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
    nc_n_try <- nc_n_try + 1
    if (nc_n_try > n_max_retries) {
        stop(msg)
    }
    else {
        message(msg, "\nRETRYing...")
        Sys.sleep(1)
    }
} else {
    nc_retry <- F
}
debug: nc_retry <- F
debug: (while) nc_retry
debug: i_req <- i_req + 1
debug: (while) i_req <= n_reqs
debug: ncs <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size > 
    0), nc)
debug: r <- terra::rast(ncs)
debug: stopifnot(all(class(terra::time(r)) %in% c("POSIXct", "POSIXt")))
debug: idx <- dplyr::pull(dplyr::filter(dplyr::arrange(dplyr::tibble(idx = 1:terra::nlyr(r), 
    time = terra::time(r)), time), !duplicated(time)), idx)
debug: r <- terra::subset(r, idx)
debug: stopifnot(terra::crs(r, proj = T) == wgs84)
debug: if (mask_tif) r <- terra::mask(r, sf_zones)
debug: lyrs <- glue("{var}|{terra::time(r)}")
debug: if (length(dims_other) > 0 && !all(length(dims[dims_other]) == 
    1)) stop(glue("Other dimensions not yet supported: {paste(dims_other, collapse = ',')}"))
debug: names(r) <- lyrs
debug: if (!is.null(rast_tif)) {
    if (fs::file_exists(rast_tif)) {
        r_tmp_tif <- tempfile(fileext = ".tif")
        r_tmp <- c(rast(rast_tif), r)
        r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
        terra::writeRaster(r_tmp, r_tmp_tif)
        fs::file_delete(rast_tif)
        fs::file_move(r_tmp_tif, rast_tif)
        rm(r)
        rm(r_tmp)
    }
    else {
        terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
    }
    r <- terra::rast(rast_tif)
}
debug: if (fs::file_exists(rast_tif)) {
    r_tmp_tif <- tempfile(fileext = ".tif")
    r_tmp <- c(rast(rast_tif), r)
    r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
    terra::writeRaster(r_tmp, r_tmp_tif)
    fs::file_delete(rast_tif)
    fs::file_move(r_tmp_tif, rast_tif)
    rm(r)
    rm(r_tmp)
} else {
    terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
}
debug: terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
debug: r <- terra::rast(rast_tif)
debug: d_r <- mutate(tidyr::pivot_longer(sf::st_drop_geometry(sf::st_as_sf(terra::zonal(x = r, 
    z = terra::vect(dplyr::select(sf_zones, dplyr::all_of(fld_zones))), 
    fun = zonal_fun, exact = T, na.rm = T, as.polygons = T))), 
    cols = -dplyr::any_of(fld_zones), names_to = "lyr", values_to = zonal_fun), 
    time = readr::parse_datetime(str_replace(lyr, glue("{var}\\|(.*)"), 
        "\\1")))
debug: if (!is.null(zonal_csv)) write_csv(d_r, zonal_csv)
debug: write_csv(d_r, zonal_csv)
debug: if (!keep_nc) unlink(dir_nc, recursive = T)
debug: unlink(dir_nc, recursive = T)
debug: return(d_r)
Downloading 1 requests, up to 641 time slices each
Called from: extractr::ed_extract(ed, var = v, sf_zones = ply, bbox = bb, 
    mask_tif = F, rast_tif = glue("{dir_out}/{nms}/{yr}.tif"), 
    zonal_fun = "mean", zonal_csv = glue("{dir_out}/{nms}/{yr}.csv"), 
    dir_nc = glue("{dir_out}/{nms}/{yr}_nc"), keep_nc = F, n_max_vals_per_req = 1e+05, 
    time_min = time_min, time_max = time_max, verbose = T)
debug: while (i_req <= n_reqs) {
    i_t_beg <- (i_req - 1) * n_t_per_req + 1
    i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
    t_req <- times_todo[c(i_t_beg, i_t_end)]
    t_req_str <- format_ISO8601(t_req, usetz = "Z")
    if (verbose) 
        message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
    ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
        ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
        0), nc)
    unlink(ncs0)
    nc_retry <- T
    nc_n_try <- 1
    n_max_retries
    while (nc_retry) {
        res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
            url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
                bbox[["xmax"]]), latitude = c(bbox[["ymin"]], 
                bbox[["ymax"]]), time = t_req_str, fmt = "nc", 
            store = rerddap::disk(path = dir_nc)))
        if (inherits(res, "try-error")) {
            err <- attr(res, "condition")
            msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
            nc_n_try <- nc_n_try + 1
            if (nc_n_try > n_max_retries) {
                stop(msg)
            }
            else {
                message(msg, "\nRETRYing...")
                Sys.sleep(1)
            }
        }
        else {
            nc_retry <- F
        }
    }
    i_req <- i_req + 1
}
debug: i_t_beg <- (i_req - 1) * n_t_per_req + 1
debug: i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
debug: t_req <- times_todo[c(i_t_beg, i_t_end)]
debug: t_req_str <- format_ISO8601(t_req, usetz = "Z")
debug: if (verbose) message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
debug: message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
Fetching request 1 of 1 (1998-01-01 to 1998-12-01) ~ 19:40:27 UTC
debug: ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
    0), nc)
debug: unlink(ncs0)
debug: nc_retry <- T
debug: nc_n_try <- 1
debug: n_max_retries
debug: while (nc_retry) {
    res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
        url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
            bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
        time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
    if (inherits(res, "try-error")) {
        err <- attr(res, "condition")
        msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
        nc_n_try <- nc_n_try + 1
        if (nc_n_try > n_max_retries) {
            stop(msg)
        }
        else {
            message(msg, "\nRETRYing...")
            Sys.sleep(1)
        }
    }
    else {
        nc_retry <- F
    }
}
debug: res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
    url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
        bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
    time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
debug: if (inherits(res, "try-error")) {
    err <- attr(res, "condition")
    msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
    nc_n_try <- nc_n_try + 1
    if (nc_n_try > n_max_retries) {
        stop(msg)
    }
    else {
        message(msg, "\nRETRYing...")
        Sys.sleep(1)
    }
} else {
    nc_retry <- F
}
debug: nc_retry <- F
debug: (while) nc_retry
debug: i_req <- i_req + 1
debug: (while) i_req <= n_reqs
debug: ncs <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size > 
    0), nc)
debug: r <- terra::rast(ncs)
debug: stopifnot(all(class(terra::time(r)) %in% c("POSIXct", "POSIXt")))
debug: idx <- dplyr::pull(dplyr::filter(dplyr::arrange(dplyr::tibble(idx = 1:terra::nlyr(r), 
    time = terra::time(r)), time), !duplicated(time)), idx)
debug: r <- terra::subset(r, idx)
debug: stopifnot(terra::crs(r, proj = T) == wgs84)
debug: if (mask_tif) r <- terra::mask(r, sf_zones)
debug: lyrs <- glue("{var}|{terra::time(r)}")
debug: if (length(dims_other) > 0 && !all(length(dims[dims_other]) == 
    1)) stop(glue("Other dimensions not yet supported: {paste(dims_other, collapse = ',')}"))
debug: names(r) <- lyrs
debug: if (!is.null(rast_tif)) {
    if (fs::file_exists(rast_tif)) {
        r_tmp_tif <- tempfile(fileext = ".tif")
        r_tmp <- c(rast(rast_tif), r)
        r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
        terra::writeRaster(r_tmp, r_tmp_tif)
        fs::file_delete(rast_tif)
        fs::file_move(r_tmp_tif, rast_tif)
        rm(r)
        rm(r_tmp)
    }
    else {
        terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
    }
    r <- terra::rast(rast_tif)
}
debug: if (fs::file_exists(rast_tif)) {
    r_tmp_tif <- tempfile(fileext = ".tif")
    r_tmp <- c(rast(rast_tif), r)
    r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
    terra::writeRaster(r_tmp, r_tmp_tif)
    fs::file_delete(rast_tif)
    fs::file_move(r_tmp_tif, rast_tif)
    rm(r)
    rm(r_tmp)
} else {
    terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
}
debug: terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
debug: r <- terra::rast(rast_tif)
debug: d_r <- mutate(tidyr::pivot_longer(sf::st_drop_geometry(sf::st_as_sf(terra::zonal(x = r, 
    z = terra::vect(dplyr::select(sf_zones, dplyr::all_of(fld_zones))), 
    fun = zonal_fun, exact = T, na.rm = T, as.polygons = T))), 
    cols = -dplyr::any_of(fld_zones), names_to = "lyr", values_to = zonal_fun), 
    time = readr::parse_datetime(str_replace(lyr, glue("{var}\\|(.*)"), 
        "\\1")))
debug: if (!is.null(zonal_csv)) write_csv(d_r, zonal_csv)
debug: write_csv(d_r, zonal_csv)
debug: if (!keep_nc) unlink(dir_nc, recursive = T)
debug: unlink(dir_nc, recursive = T)
debug: return(d_r)
Downloading 1 requests, up to 641 time slices each
Called from: extractr::ed_extract(ed, var = v, sf_zones = ply, bbox = bb, 
    mask_tif = F, rast_tif = glue("{dir_out}/{nms}/{yr}.tif"), 
    zonal_fun = "mean", zonal_csv = glue("{dir_out}/{nms}/{yr}.csv"), 
    dir_nc = glue("{dir_out}/{nms}/{yr}_nc"), keep_nc = F, n_max_vals_per_req = 1e+05, 
    time_min = time_min, time_max = time_max, verbose = T)
debug: while (i_req <= n_reqs) {
    i_t_beg <- (i_req - 1) * n_t_per_req + 1
    i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
    t_req <- times_todo[c(i_t_beg, i_t_end)]
    t_req_str <- format_ISO8601(t_req, usetz = "Z")
    if (verbose) 
        message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
    ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
        ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
        0), nc)
    unlink(ncs0)
    nc_retry <- T
    nc_n_try <- 1
    n_max_retries
    while (nc_retry) {
        res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
            url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
                bbox[["xmax"]]), latitude = c(bbox[["ymin"]], 
                bbox[["ymax"]]), time = t_req_str, fmt = "nc", 
            store = rerddap::disk(path = dir_nc)))
        if (inherits(res, "try-error")) {
            err <- attr(res, "condition")
            msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
            nc_n_try <- nc_n_try + 1
            if (nc_n_try > n_max_retries) {
                stop(msg)
            }
            else {
                message(msg, "\nRETRYing...")
                Sys.sleep(1)
            }
        }
        else {
            nc_retry <- F
        }
    }
    i_req <- i_req + 1
}
debug: i_t_beg <- (i_req - 1) * n_t_per_req + 1
debug: i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
debug: t_req <- times_todo[c(i_t_beg, i_t_end)]
debug: t_req_str <- format_ISO8601(t_req, usetz = "Z")
debug: if (verbose) message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
debug: message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
Fetching request 1 of 1 (1999-01-01 to 1999-12-01) ~ 19:40:29 UTC
debug: ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
    0), nc)
debug: unlink(ncs0)
debug: nc_retry <- T
debug: nc_n_try <- 1
debug: n_max_retries
debug: while (nc_retry) {
    res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
        url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
            bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
        time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
    if (inherits(res, "try-error")) {
        err <- attr(res, "condition")
        msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
        nc_n_try <- nc_n_try + 1
        if (nc_n_try > n_max_retries) {
            stop(msg)
        }
        else {
            message(msg, "\nRETRYing...")
            Sys.sleep(1)
        }
    }
    else {
        nc_retry <- F
    }
}
debug: res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
    url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
        bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
    time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
debug: if (inherits(res, "try-error")) {
    err <- attr(res, "condition")
    msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
    nc_n_try <- nc_n_try + 1
    if (nc_n_try > n_max_retries) {
        stop(msg)
    }
    else {
        message(msg, "\nRETRYing...")
        Sys.sleep(1)
    }
} else {
    nc_retry <- F
}
debug: nc_retry <- F
debug: (while) nc_retry
debug: i_req <- i_req + 1
debug: (while) i_req <= n_reqs
debug: ncs <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size > 
    0), nc)
debug: r <- terra::rast(ncs)
debug: stopifnot(all(class(terra::time(r)) %in% c("POSIXct", "POSIXt")))
debug: idx <- dplyr::pull(dplyr::filter(dplyr::arrange(dplyr::tibble(idx = 1:terra::nlyr(r), 
    time = terra::time(r)), time), !duplicated(time)), idx)
debug: r <- terra::subset(r, idx)
debug: stopifnot(terra::crs(r, proj = T) == wgs84)
debug: if (mask_tif) r <- terra::mask(r, sf_zones)
debug: lyrs <- glue("{var}|{terra::time(r)}")
debug: if (length(dims_other) > 0 && !all(length(dims[dims_other]) == 
    1)) stop(glue("Other dimensions not yet supported: {paste(dims_other, collapse = ',')}"))
debug: names(r) <- lyrs
debug: if (!is.null(rast_tif)) {
    if (fs::file_exists(rast_tif)) {
        r_tmp_tif <- tempfile(fileext = ".tif")
        r_tmp <- c(rast(rast_tif), r)
        r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
        terra::writeRaster(r_tmp, r_tmp_tif)
        fs::file_delete(rast_tif)
        fs::file_move(r_tmp_tif, rast_tif)
        rm(r)
        rm(r_tmp)
    }
    else {
        terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
    }
    r <- terra::rast(rast_tif)
}
debug: if (fs::file_exists(rast_tif)) {
    r_tmp_tif <- tempfile(fileext = ".tif")
    r_tmp <- c(rast(rast_tif), r)
    r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
    terra::writeRaster(r_tmp, r_tmp_tif)
    fs::file_delete(rast_tif)
    fs::file_move(r_tmp_tif, rast_tif)
    rm(r)
    rm(r_tmp)
} else {
    terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
}
debug: terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
debug: r <- terra::rast(rast_tif)
debug: d_r <- mutate(tidyr::pivot_longer(sf::st_drop_geometry(sf::st_as_sf(terra::zonal(x = r, 
    z = terra::vect(dplyr::select(sf_zones, dplyr::all_of(fld_zones))), 
    fun = zonal_fun, exact = T, na.rm = T, as.polygons = T))), 
    cols = -dplyr::any_of(fld_zones), names_to = "lyr", values_to = zonal_fun), 
    time = readr::parse_datetime(str_replace(lyr, glue("{var}\\|(.*)"), 
        "\\1")))
debug: if (!is.null(zonal_csv)) write_csv(d_r, zonal_csv)
debug: write_csv(d_r, zonal_csv)
debug: if (!keep_nc) unlink(dir_nc, recursive = T)
debug: unlink(dir_nc, recursive = T)
debug: return(d_r)
Downloading 1 requests, up to 641 time slices each
Called from: extractr::ed_extract(ed, var = v, sf_zones = ply, bbox = bb, 
    mask_tif = F, rast_tif = glue("{dir_out}/{nms}/{yr}.tif"), 
    zonal_fun = "mean", zonal_csv = glue("{dir_out}/{nms}/{yr}.csv"), 
    dir_nc = glue("{dir_out}/{nms}/{yr}_nc"), keep_nc = F, n_max_vals_per_req = 1e+05, 
    time_min = time_min, time_max = time_max, verbose = T)
debug: while (i_req <= n_reqs) {
    i_t_beg <- (i_req - 1) * n_t_per_req + 1
    i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
    t_req <- times_todo[c(i_t_beg, i_t_end)]
    t_req_str <- format_ISO8601(t_req, usetz = "Z")
    if (verbose) 
        message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
    ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
        ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
        0), nc)
    unlink(ncs0)
    nc_retry <- T
    nc_n_try <- 1
    n_max_retries
    while (nc_retry) {
        res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
            url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
                bbox[["xmax"]]), latitude = c(bbox[["ymin"]], 
                bbox[["ymax"]]), time = t_req_str, fmt = "nc", 
            store = rerddap::disk(path = dir_nc)))
        if (inherits(res, "try-error")) {
            err <- attr(res, "condition")
            msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
            nc_n_try <- nc_n_try + 1
            if (nc_n_try > n_max_retries) {
                stop(msg)
            }
            else {
                message(msg, "\nRETRYing...")
                Sys.sleep(1)
            }
        }
        else {
            nc_retry <- F
        }
    }
    i_req <- i_req + 1
}
debug: i_t_beg <- (i_req - 1) * n_t_per_req + 1
debug: i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
debug: t_req <- times_todo[c(i_t_beg, i_t_end)]
debug: t_req_str <- format_ISO8601(t_req, usetz = "Z")
debug: if (verbose) message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
debug: message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
Fetching request 1 of 1 (2000-01-01 to 2000-12-01) ~ 19:40:31 UTC
debug: ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
    0), nc)
debug: unlink(ncs0)
debug: nc_retry <- T
debug: nc_n_try <- 1
debug: n_max_retries
debug: while (nc_retry) {
    res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
        url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
            bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
        time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
    if (inherits(res, "try-error")) {
        err <- attr(res, "condition")
        msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
        nc_n_try <- nc_n_try + 1
        if (nc_n_try > n_max_retries) {
            stop(msg)
        }
        else {
            message(msg, "\nRETRYing...")
            Sys.sleep(1)
        }
    }
    else {
        nc_retry <- F
    }
}
debug: res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
    url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
        bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
    time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
debug: if (inherits(res, "try-error")) {
    err <- attr(res, "condition")
    msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
    nc_n_try <- nc_n_try + 1
    if (nc_n_try > n_max_retries) {
        stop(msg)
    }
    else {
        message(msg, "\nRETRYing...")
        Sys.sleep(1)
    }
} else {
    nc_retry <- F
}
debug: nc_retry <- F
debug: (while) nc_retry
debug: i_req <- i_req + 1
debug: (while) i_req <= n_reqs
debug: ncs <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size > 
    0), nc)
debug: r <- terra::rast(ncs)
debug: stopifnot(all(class(terra::time(r)) %in% c("POSIXct", "POSIXt")))
debug: idx <- dplyr::pull(dplyr::filter(dplyr::arrange(dplyr::tibble(idx = 1:terra::nlyr(r), 
    time = terra::time(r)), time), !duplicated(time)), idx)
debug: r <- terra::subset(r, idx)
debug: stopifnot(terra::crs(r, proj = T) == wgs84)
debug: if (mask_tif) r <- terra::mask(r, sf_zones)
debug: lyrs <- glue("{var}|{terra::time(r)}")
debug: if (length(dims_other) > 0 && !all(length(dims[dims_other]) == 
    1)) stop(glue("Other dimensions not yet supported: {paste(dims_other, collapse = ',')}"))
debug: names(r) <- lyrs
debug: if (!is.null(rast_tif)) {
    if (fs::file_exists(rast_tif)) {
        r_tmp_tif <- tempfile(fileext = ".tif")
        r_tmp <- c(rast(rast_tif), r)
        r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
        terra::writeRaster(r_tmp, r_tmp_tif)
        fs::file_delete(rast_tif)
        fs::file_move(r_tmp_tif, rast_tif)
        rm(r)
        rm(r_tmp)
    }
    else {
        terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
    }
    r <- terra::rast(rast_tif)
}
debug: if (fs::file_exists(rast_tif)) {
    r_tmp_tif <- tempfile(fileext = ".tif")
    r_tmp <- c(rast(rast_tif), r)
    r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
    terra::writeRaster(r_tmp, r_tmp_tif)
    fs::file_delete(rast_tif)
    fs::file_move(r_tmp_tif, rast_tif)
    rm(r)
    rm(r_tmp)
} else {
    terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
}
debug: terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
debug: r <- terra::rast(rast_tif)
debug: d_r <- mutate(tidyr::pivot_longer(sf::st_drop_geometry(sf::st_as_sf(terra::zonal(x = r, 
    z = terra::vect(dplyr::select(sf_zones, dplyr::all_of(fld_zones))), 
    fun = zonal_fun, exact = T, na.rm = T, as.polygons = T))), 
    cols = -dplyr::any_of(fld_zones), names_to = "lyr", values_to = zonal_fun), 
    time = readr::parse_datetime(str_replace(lyr, glue("{var}\\|(.*)"), 
        "\\1")))
debug: if (!is.null(zonal_csv)) write_csv(d_r, zonal_csv)
debug: write_csv(d_r, zonal_csv)
debug: if (!keep_nc) unlink(dir_nc, recursive = T)
debug: unlink(dir_nc, recursive = T)
debug: return(d_r)
Downloading 1 requests, up to 641 time slices each
Called from: extractr::ed_extract(ed, var = v, sf_zones = ply, bbox = bb, 
    mask_tif = F, rast_tif = glue("{dir_out}/{nms}/{yr}.tif"), 
    zonal_fun = "mean", zonal_csv = glue("{dir_out}/{nms}/{yr}.csv"), 
    dir_nc = glue("{dir_out}/{nms}/{yr}_nc"), keep_nc = F, n_max_vals_per_req = 1e+05, 
    time_min = time_min, time_max = time_max, verbose = T)
debug: while (i_req <= n_reqs) {
    i_t_beg <- (i_req - 1) * n_t_per_req + 1
    i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
    t_req <- times_todo[c(i_t_beg, i_t_end)]
    t_req_str <- format_ISO8601(t_req, usetz = "Z")
    if (verbose) 
        message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
    ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
        ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
        0), nc)
    unlink(ncs0)
    nc_retry <- T
    nc_n_try <- 1
    n_max_retries
    while (nc_retry) {
        res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
            url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
                bbox[["xmax"]]), latitude = c(bbox[["ymin"]], 
                bbox[["ymax"]]), time = t_req_str, fmt = "nc", 
            store = rerddap::disk(path = dir_nc)))
        if (inherits(res, "try-error")) {
            err <- attr(res, "condition")
            msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
            nc_n_try <- nc_n_try + 1
            if (nc_n_try > n_max_retries) {
                stop(msg)
            }
            else {
                message(msg, "\nRETRYing...")
                Sys.sleep(1)
            }
        }
        else {
            nc_retry <- F
        }
    }
    i_req <- i_req + 1
}
debug: i_t_beg <- (i_req - 1) * n_t_per_req + 1
debug: i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
debug: t_req <- times_todo[c(i_t_beg, i_t_end)]
debug: t_req_str <- format_ISO8601(t_req, usetz = "Z")
debug: if (verbose) message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
debug: message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
Fetching request 1 of 1 (2001-01-01 to 2001-12-01) ~ 19:40:32 UTC
debug: ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
    0), nc)
debug: unlink(ncs0)
debug: nc_retry <- T
debug: nc_n_try <- 1
debug: n_max_retries
debug: while (nc_retry) {
    res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
        url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
            bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
        time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
    if (inherits(res, "try-error")) {
        err <- attr(res, "condition")
        msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
        nc_n_try <- nc_n_try + 1
        if (nc_n_try > n_max_retries) {
            stop(msg)
        }
        else {
            message(msg, "\nRETRYing...")
            Sys.sleep(1)
        }
    }
    else {
        nc_retry <- F
    }
}
debug: res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
    url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
        bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
    time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
debug: if (inherits(res, "try-error")) {
    err <- attr(res, "condition")
    msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
    nc_n_try <- nc_n_try + 1
    if (nc_n_try > n_max_retries) {
        stop(msg)
    }
    else {
        message(msg, "\nRETRYing...")
        Sys.sleep(1)
    }
} else {
    nc_retry <- F
}
debug: nc_retry <- F
debug: (while) nc_retry
debug: i_req <- i_req + 1
debug: (while) i_req <= n_reqs
debug: ncs <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size > 
    0), nc)
debug: r <- terra::rast(ncs)
debug: stopifnot(all(class(terra::time(r)) %in% c("POSIXct", "POSIXt")))
debug: idx <- dplyr::pull(dplyr::filter(dplyr::arrange(dplyr::tibble(idx = 1:terra::nlyr(r), 
    time = terra::time(r)), time), !duplicated(time)), idx)
debug: r <- terra::subset(r, idx)
debug: stopifnot(terra::crs(r, proj = T) == wgs84)
debug: if (mask_tif) r <- terra::mask(r, sf_zones)
debug: lyrs <- glue("{var}|{terra::time(r)}")
debug: if (length(dims_other) > 0 && !all(length(dims[dims_other]) == 
    1)) stop(glue("Other dimensions not yet supported: {paste(dims_other, collapse = ',')}"))
debug: names(r) <- lyrs
debug: if (!is.null(rast_tif)) {
    if (fs::file_exists(rast_tif)) {
        r_tmp_tif <- tempfile(fileext = ".tif")
        r_tmp <- c(rast(rast_tif), r)
        r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
        terra::writeRaster(r_tmp, r_tmp_tif)
        fs::file_delete(rast_tif)
        fs::file_move(r_tmp_tif, rast_tif)
        rm(r)
        rm(r_tmp)
    }
    else {
        terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
    }
    r <- terra::rast(rast_tif)
}
debug: if (fs::file_exists(rast_tif)) {
    r_tmp_tif <- tempfile(fileext = ".tif")
    r_tmp <- c(rast(rast_tif), r)
    r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
    terra::writeRaster(r_tmp, r_tmp_tif)
    fs::file_delete(rast_tif)
    fs::file_move(r_tmp_tif, rast_tif)
    rm(r)
    rm(r_tmp)
} else {
    terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
}
debug: terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
debug: r <- terra::rast(rast_tif)
debug: d_r <- mutate(tidyr::pivot_longer(sf::st_drop_geometry(sf::st_as_sf(terra::zonal(x = r, 
    z = terra::vect(dplyr::select(sf_zones, dplyr::all_of(fld_zones))), 
    fun = zonal_fun, exact = T, na.rm = T, as.polygons = T))), 
    cols = -dplyr::any_of(fld_zones), names_to = "lyr", values_to = zonal_fun), 
    time = readr::parse_datetime(str_replace(lyr, glue("{var}\\|(.*)"), 
        "\\1")))
debug: if (!is.null(zonal_csv)) write_csv(d_r, zonal_csv)
debug: write_csv(d_r, zonal_csv)
debug: if (!keep_nc) unlink(dir_nc, recursive = T)
debug: unlink(dir_nc, recursive = T)
debug: return(d_r)
Downloading 1 requests, up to 641 time slices each
Called from: extractr::ed_extract(ed, var = v, sf_zones = ply, bbox = bb, 
    mask_tif = F, rast_tif = glue("{dir_out}/{nms}/{yr}.tif"), 
    zonal_fun = "mean", zonal_csv = glue("{dir_out}/{nms}/{yr}.csv"), 
    dir_nc = glue("{dir_out}/{nms}/{yr}_nc"), keep_nc = F, n_max_vals_per_req = 1e+05, 
    time_min = time_min, time_max = time_max, verbose = T)
debug: while (i_req <= n_reqs) {
    i_t_beg <- (i_req - 1) * n_t_per_req + 1
    i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
    t_req <- times_todo[c(i_t_beg, i_t_end)]
    t_req_str <- format_ISO8601(t_req, usetz = "Z")
    if (verbose) 
        message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
    ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
        ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
        0), nc)
    unlink(ncs0)
    nc_retry <- T
    nc_n_try <- 1
    n_max_retries
    while (nc_retry) {
        res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
            url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
                bbox[["xmax"]]), latitude = c(bbox[["ymin"]], 
                bbox[["ymax"]]), time = t_req_str, fmt = "nc", 
            store = rerddap::disk(path = dir_nc)))
        if (inherits(res, "try-error")) {
            err <- attr(res, "condition")
            msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
            nc_n_try <- nc_n_try + 1
            if (nc_n_try > n_max_retries) {
                stop(msg)
            }
            else {
                message(msg, "\nRETRYing...")
                Sys.sleep(1)
            }
        }
        else {
            nc_retry <- F
        }
    }
    i_req <- i_req + 1
}
debug: i_t_beg <- (i_req - 1) * n_t_per_req + 1
debug: i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
debug: t_req <- times_todo[c(i_t_beg, i_t_end)]
debug: t_req_str <- format_ISO8601(t_req, usetz = "Z")
debug: if (verbose) message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
debug: message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
Fetching request 1 of 1 (2002-01-01 to 2002-12-01) ~ 19:40:34 UTC
debug: ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
    0), nc)
debug: unlink(ncs0)
debug: nc_retry <- T
debug: nc_n_try <- 1
debug: n_max_retries
debug: while (nc_retry) {
    res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
        url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
            bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
        time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
    if (inherits(res, "try-error")) {
        err <- attr(res, "condition")
        msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
        nc_n_try <- nc_n_try + 1
        if (nc_n_try > n_max_retries) {
            stop(msg)
        }
        else {
            message(msg, "\nRETRYing...")
            Sys.sleep(1)
        }
    }
    else {
        nc_retry <- F
    }
}
debug: res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
    url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
        bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
    time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
debug: if (inherits(res, "try-error")) {
    err <- attr(res, "condition")
    msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
    nc_n_try <- nc_n_try + 1
    if (nc_n_try > n_max_retries) {
        stop(msg)
    }
    else {
        message(msg, "\nRETRYing...")
        Sys.sleep(1)
    }
} else {
    nc_retry <- F
}
debug: nc_retry <- F
debug: (while) nc_retry
debug: i_req <- i_req + 1
debug: (while) i_req <= n_reqs
debug: ncs <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size > 
    0), nc)
debug: r <- terra::rast(ncs)
debug: stopifnot(all(class(terra::time(r)) %in% c("POSIXct", "POSIXt")))
debug: idx <- dplyr::pull(dplyr::filter(dplyr::arrange(dplyr::tibble(idx = 1:terra::nlyr(r), 
    time = terra::time(r)), time), !duplicated(time)), idx)
debug: r <- terra::subset(r, idx)
debug: stopifnot(terra::crs(r, proj = T) == wgs84)
debug: if (mask_tif) r <- terra::mask(r, sf_zones)
debug: lyrs <- glue("{var}|{terra::time(r)}")
debug: if (length(dims_other) > 0 && !all(length(dims[dims_other]) == 
    1)) stop(glue("Other dimensions not yet supported: {paste(dims_other, collapse = ',')}"))
debug: names(r) <- lyrs
debug: if (!is.null(rast_tif)) {
    if (fs::file_exists(rast_tif)) {
        r_tmp_tif <- tempfile(fileext = ".tif")
        r_tmp <- c(rast(rast_tif), r)
        r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
        terra::writeRaster(r_tmp, r_tmp_tif)
        fs::file_delete(rast_tif)
        fs::file_move(r_tmp_tif, rast_tif)
        rm(r)
        rm(r_tmp)
    }
    else {
        terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
    }
    r <- terra::rast(rast_tif)
}
debug: if (fs::file_exists(rast_tif)) {
    r_tmp_tif <- tempfile(fileext = ".tif")
    r_tmp <- c(rast(rast_tif), r)
    r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
    terra::writeRaster(r_tmp, r_tmp_tif)
    fs::file_delete(rast_tif)
    fs::file_move(r_tmp_tif, rast_tif)
    rm(r)
    rm(r_tmp)
} else {
    terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
}
debug: terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
debug: r <- terra::rast(rast_tif)
debug: d_r <- mutate(tidyr::pivot_longer(sf::st_drop_geometry(sf::st_as_sf(terra::zonal(x = r, 
    z = terra::vect(dplyr::select(sf_zones, dplyr::all_of(fld_zones))), 
    fun = zonal_fun, exact = T, na.rm = T, as.polygons = T))), 
    cols = -dplyr::any_of(fld_zones), names_to = "lyr", values_to = zonal_fun), 
    time = readr::parse_datetime(str_replace(lyr, glue("{var}\\|(.*)"), 
        "\\1")))
debug: if (!is.null(zonal_csv)) write_csv(d_r, zonal_csv)
debug: write_csv(d_r, zonal_csv)
debug: if (!keep_nc) unlink(dir_nc, recursive = T)
debug: unlink(dir_nc, recursive = T)
debug: return(d_r)
Downloading 1 requests, up to 641 time slices each
Called from: extractr::ed_extract(ed, var = v, sf_zones = ply, bbox = bb, 
    mask_tif = F, rast_tif = glue("{dir_out}/{nms}/{yr}.tif"), 
    zonal_fun = "mean", zonal_csv = glue("{dir_out}/{nms}/{yr}.csv"), 
    dir_nc = glue("{dir_out}/{nms}/{yr}_nc"), keep_nc = F, n_max_vals_per_req = 1e+05, 
    time_min = time_min, time_max = time_max, verbose = T)
debug: while (i_req <= n_reqs) {
    i_t_beg <- (i_req - 1) * n_t_per_req + 1
    i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
    t_req <- times_todo[c(i_t_beg, i_t_end)]
    t_req_str <- format_ISO8601(t_req, usetz = "Z")
    if (verbose) 
        message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
    ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
        ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
        0), nc)
    unlink(ncs0)
    nc_retry <- T
    nc_n_try <- 1
    n_max_retries
    while (nc_retry) {
        res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
            url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
                bbox[["xmax"]]), latitude = c(bbox[["ymin"]], 
                bbox[["ymax"]]), time = t_req_str, fmt = "nc", 
            store = rerddap::disk(path = dir_nc)))
        if (inherits(res, "try-error")) {
            err <- attr(res, "condition")
            msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
            nc_n_try <- nc_n_try + 1
            if (nc_n_try > n_max_retries) {
                stop(msg)
            }
            else {
                message(msg, "\nRETRYing...")
                Sys.sleep(1)
            }
        }
        else {
            nc_retry <- F
        }
    }
    i_req <- i_req + 1
}
debug: i_t_beg <- (i_req - 1) * n_t_per_req + 1
debug: i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
debug: t_req <- times_todo[c(i_t_beg, i_t_end)]
debug: t_req_str <- format_ISO8601(t_req, usetz = "Z")
debug: if (verbose) message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
debug: message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
Fetching request 1 of 1 (2003-01-01 to 2003-12-01) ~ 19:40:36 UTC
debug: ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
    0), nc)
debug: unlink(ncs0)
debug: nc_retry <- T
debug: nc_n_try <- 1
debug: n_max_retries
debug: while (nc_retry) {
    res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
        url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
            bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
        time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
    if (inherits(res, "try-error")) {
        err <- attr(res, "condition")
        msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
        nc_n_try <- nc_n_try + 1
        if (nc_n_try > n_max_retries) {
            stop(msg)
        }
        else {
            message(msg, "\nRETRYing...")
            Sys.sleep(1)
        }
    }
    else {
        nc_retry <- F
    }
}
debug: res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
    url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
        bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
    time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
debug: if (inherits(res, "try-error")) {
    err <- attr(res, "condition")
    msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
    nc_n_try <- nc_n_try + 1
    if (nc_n_try > n_max_retries) {
        stop(msg)
    }
    else {
        message(msg, "\nRETRYing...")
        Sys.sleep(1)
    }
} else {
    nc_retry <- F
}
debug: nc_retry <- F
debug: (while) nc_retry
debug: i_req <- i_req + 1
debug: (while) i_req <= n_reqs
debug: ncs <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size > 
    0), nc)
debug: r <- terra::rast(ncs)
debug: stopifnot(all(class(terra::time(r)) %in% c("POSIXct", "POSIXt")))
debug: idx <- dplyr::pull(dplyr::filter(dplyr::arrange(dplyr::tibble(idx = 1:terra::nlyr(r), 
    time = terra::time(r)), time), !duplicated(time)), idx)
debug: r <- terra::subset(r, idx)
debug: stopifnot(terra::crs(r, proj = T) == wgs84)
debug: if (mask_tif) r <- terra::mask(r, sf_zones)
debug: lyrs <- glue("{var}|{terra::time(r)}")
debug: if (length(dims_other) > 0 && !all(length(dims[dims_other]) == 
    1)) stop(glue("Other dimensions not yet supported: {paste(dims_other, collapse = ',')}"))
debug: names(r) <- lyrs
debug: if (!is.null(rast_tif)) {
    if (fs::file_exists(rast_tif)) {
        r_tmp_tif <- tempfile(fileext = ".tif")
        r_tmp <- c(rast(rast_tif), r)
        r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
        terra::writeRaster(r_tmp, r_tmp_tif)
        fs::file_delete(rast_tif)
        fs::file_move(r_tmp_tif, rast_tif)
        rm(r)
        rm(r_tmp)
    }
    else {
        terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
    }
    r <- terra::rast(rast_tif)
}
debug: if (fs::file_exists(rast_tif)) {
    r_tmp_tif <- tempfile(fileext = ".tif")
    r_tmp <- c(rast(rast_tif), r)
    r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
    terra::writeRaster(r_tmp, r_tmp_tif)
    fs::file_delete(rast_tif)
    fs::file_move(r_tmp_tif, rast_tif)
    rm(r)
    rm(r_tmp)
} else {
    terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
}
debug: terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
debug: r <- terra::rast(rast_tif)
debug: d_r <- mutate(tidyr::pivot_longer(sf::st_drop_geometry(sf::st_as_sf(terra::zonal(x = r, 
    z = terra::vect(dplyr::select(sf_zones, dplyr::all_of(fld_zones))), 
    fun = zonal_fun, exact = T, na.rm = T, as.polygons = T))), 
    cols = -dplyr::any_of(fld_zones), names_to = "lyr", values_to = zonal_fun), 
    time = readr::parse_datetime(str_replace(lyr, glue("{var}\\|(.*)"), 
        "\\1")))
debug: if (!is.null(zonal_csv)) write_csv(d_r, zonal_csv)
debug: write_csv(d_r, zonal_csv)
debug: if (!keep_nc) unlink(dir_nc, recursive = T)
debug: unlink(dir_nc, recursive = T)
debug: return(d_r)
Downloading 1 requests, up to 641 time slices each
Called from: extractr::ed_extract(ed, var = v, sf_zones = ply, bbox = bb, 
    mask_tif = F, rast_tif = glue("{dir_out}/{nms}/{yr}.tif"), 
    zonal_fun = "mean", zonal_csv = glue("{dir_out}/{nms}/{yr}.csv"), 
    dir_nc = glue("{dir_out}/{nms}/{yr}_nc"), keep_nc = F, n_max_vals_per_req = 1e+05, 
    time_min = time_min, time_max = time_max, verbose = T)
debug: while (i_req <= n_reqs) {
    i_t_beg <- (i_req - 1) * n_t_per_req + 1
    i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
    t_req <- times_todo[c(i_t_beg, i_t_end)]
    t_req_str <- format_ISO8601(t_req, usetz = "Z")
    if (verbose) 
        message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
    ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
        ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
        0), nc)
    unlink(ncs0)
    nc_retry <- T
    nc_n_try <- 1
    n_max_retries
    while (nc_retry) {
        res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
            url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
                bbox[["xmax"]]), latitude = c(bbox[["ymin"]], 
                bbox[["ymax"]]), time = t_req_str, fmt = "nc", 
            store = rerddap::disk(path = dir_nc)))
        if (inherits(res, "try-error")) {
            err <- attr(res, "condition")
            msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
            nc_n_try <- nc_n_try + 1
            if (nc_n_try > n_max_retries) {
                stop(msg)
            }
            else {
                message(msg, "\nRETRYing...")
                Sys.sleep(1)
            }
        }
        else {
            nc_retry <- F
        }
    }
    i_req <- i_req + 1
}
debug: i_t_beg <- (i_req - 1) * n_t_per_req + 1
debug: i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
debug: t_req <- times_todo[c(i_t_beg, i_t_end)]
debug: t_req_str <- format_ISO8601(t_req, usetz = "Z")
debug: if (verbose) message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
debug: message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
Fetching request 1 of 1 (2004-01-01 to 2004-12-01) ~ 19:40:37 UTC
debug: ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
    0), nc)
debug: unlink(ncs0)
debug: nc_retry <- T
debug: nc_n_try <- 1
debug: n_max_retries
debug: while (nc_retry) {
    res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
        url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
            bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
        time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
    if (inherits(res, "try-error")) {
        err <- attr(res, "condition")
        msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
        nc_n_try <- nc_n_try + 1
        if (nc_n_try > n_max_retries) {
            stop(msg)
        }
        else {
            message(msg, "\nRETRYing...")
            Sys.sleep(1)
        }
    }
    else {
        nc_retry <- F
    }
}
debug: res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
    url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
        bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
    time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
debug: if (inherits(res, "try-error")) {
    err <- attr(res, "condition")
    msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
    nc_n_try <- nc_n_try + 1
    if (nc_n_try > n_max_retries) {
        stop(msg)
    }
    else {
        message(msg, "\nRETRYing...")
        Sys.sleep(1)
    }
} else {
    nc_retry <- F
}
debug: nc_retry <- F
debug: (while) nc_retry
debug: i_req <- i_req + 1
debug: (while) i_req <= n_reqs
debug: ncs <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size > 
    0), nc)
debug: r <- terra::rast(ncs)
debug: stopifnot(all(class(terra::time(r)) %in% c("POSIXct", "POSIXt")))
debug: idx <- dplyr::pull(dplyr::filter(dplyr::arrange(dplyr::tibble(idx = 1:terra::nlyr(r), 
    time = terra::time(r)), time), !duplicated(time)), idx)
debug: r <- terra::subset(r, idx)
debug: stopifnot(terra::crs(r, proj = T) == wgs84)
debug: if (mask_tif) r <- terra::mask(r, sf_zones)
debug: lyrs <- glue("{var}|{terra::time(r)}")
debug: if (length(dims_other) > 0 && !all(length(dims[dims_other]) == 
    1)) stop(glue("Other dimensions not yet supported: {paste(dims_other, collapse = ',')}"))
debug: names(r) <- lyrs
debug: if (!is.null(rast_tif)) {
    if (fs::file_exists(rast_tif)) {
        r_tmp_tif <- tempfile(fileext = ".tif")
        r_tmp <- c(rast(rast_tif), r)
        r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
        terra::writeRaster(r_tmp, r_tmp_tif)
        fs::file_delete(rast_tif)
        fs::file_move(r_tmp_tif, rast_tif)
        rm(r)
        rm(r_tmp)
    }
    else {
        terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
    }
    r <- terra::rast(rast_tif)
}
debug: if (fs::file_exists(rast_tif)) {
    r_tmp_tif <- tempfile(fileext = ".tif")
    r_tmp <- c(rast(rast_tif), r)
    r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
    terra::writeRaster(r_tmp, r_tmp_tif)
    fs::file_delete(rast_tif)
    fs::file_move(r_tmp_tif, rast_tif)
    rm(r)
    rm(r_tmp)
} else {
    terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
}
debug: terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
debug: r <- terra::rast(rast_tif)
debug: d_r <- mutate(tidyr::pivot_longer(sf::st_drop_geometry(sf::st_as_sf(terra::zonal(x = r, 
    z = terra::vect(dplyr::select(sf_zones, dplyr::all_of(fld_zones))), 
    fun = zonal_fun, exact = T, na.rm = T, as.polygons = T))), 
    cols = -dplyr::any_of(fld_zones), names_to = "lyr", values_to = zonal_fun), 
    time = readr::parse_datetime(str_replace(lyr, glue("{var}\\|(.*)"), 
        "\\1")))
debug: if (!is.null(zonal_csv)) write_csv(d_r, zonal_csv)
debug: write_csv(d_r, zonal_csv)
debug: if (!keep_nc) unlink(dir_nc, recursive = T)
debug: unlink(dir_nc, recursive = T)
debug: return(d_r)
Downloading 1 requests, up to 641 time slices each
Called from: extractr::ed_extract(ed, var = v, sf_zones = ply, bbox = bb, 
    mask_tif = F, rast_tif = glue("{dir_out}/{nms}/{yr}.tif"), 
    zonal_fun = "mean", zonal_csv = glue("{dir_out}/{nms}/{yr}.csv"), 
    dir_nc = glue("{dir_out}/{nms}/{yr}_nc"), keep_nc = F, n_max_vals_per_req = 1e+05, 
    time_min = time_min, time_max = time_max, verbose = T)
debug: while (i_req <= n_reqs) {
    i_t_beg <- (i_req - 1) * n_t_per_req + 1
    i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
    t_req <- times_todo[c(i_t_beg, i_t_end)]
    t_req_str <- format_ISO8601(t_req, usetz = "Z")
    if (verbose) 
        message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
    ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
        ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
        0), nc)
    unlink(ncs0)
    nc_retry <- T
    nc_n_try <- 1
    n_max_retries
    while (nc_retry) {
        res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
            url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
                bbox[["xmax"]]), latitude = c(bbox[["ymin"]], 
                bbox[["ymax"]]), time = t_req_str, fmt = "nc", 
            store = rerddap::disk(path = dir_nc)))
        if (inherits(res, "try-error")) {
            err <- attr(res, "condition")
            msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
            nc_n_try <- nc_n_try + 1
            if (nc_n_try > n_max_retries) {
                stop(msg)
            }
            else {
                message(msg, "\nRETRYing...")
                Sys.sleep(1)
            }
        }
        else {
            nc_retry <- F
        }
    }
    i_req <- i_req + 1
}
debug: i_t_beg <- (i_req - 1) * n_t_per_req + 1
debug: i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
debug: t_req <- times_todo[c(i_t_beg, i_t_end)]
debug: t_req_str <- format_ISO8601(t_req, usetz = "Z")
debug: if (verbose) message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
debug: message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
Fetching request 1 of 1 (2005-01-01 to 2005-12-01) ~ 19:40:39 UTC
debug: ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
    0), nc)
debug: unlink(ncs0)
debug: nc_retry <- T
debug: nc_n_try <- 1
debug: n_max_retries
debug: while (nc_retry) {
    res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
        url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
            bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
        time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
    if (inherits(res, "try-error")) {
        err <- attr(res, "condition")
        msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
        nc_n_try <- nc_n_try + 1
        if (nc_n_try > n_max_retries) {
            stop(msg)
        }
        else {
            message(msg, "\nRETRYing...")
            Sys.sleep(1)
        }
    }
    else {
        nc_retry <- F
    }
}
debug: res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
    url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
        bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
    time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
debug: if (inherits(res, "try-error")) {
    err <- attr(res, "condition")
    msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
    nc_n_try <- nc_n_try + 1
    if (nc_n_try > n_max_retries) {
        stop(msg)
    }
    else {
        message(msg, "\nRETRYing...")
        Sys.sleep(1)
    }
} else {
    nc_retry <- F
}
debug: nc_retry <- F
debug: (while) nc_retry
debug: i_req <- i_req + 1
debug: (while) i_req <= n_reqs
debug: ncs <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size > 
    0), nc)
debug: r <- terra::rast(ncs)
debug: stopifnot(all(class(terra::time(r)) %in% c("POSIXct", "POSIXt")))
debug: idx <- dplyr::pull(dplyr::filter(dplyr::arrange(dplyr::tibble(idx = 1:terra::nlyr(r), 
    time = terra::time(r)), time), !duplicated(time)), idx)
debug: r <- terra::subset(r, idx)
debug: stopifnot(terra::crs(r, proj = T) == wgs84)
debug: if (mask_tif) r <- terra::mask(r, sf_zones)
debug: lyrs <- glue("{var}|{terra::time(r)}")
debug: if (length(dims_other) > 0 && !all(length(dims[dims_other]) == 
    1)) stop(glue("Other dimensions not yet supported: {paste(dims_other, collapse = ',')}"))
debug: names(r) <- lyrs
debug: if (!is.null(rast_tif)) {
    if (fs::file_exists(rast_tif)) {
        r_tmp_tif <- tempfile(fileext = ".tif")
        r_tmp <- c(rast(rast_tif), r)
        r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
        terra::writeRaster(r_tmp, r_tmp_tif)
        fs::file_delete(rast_tif)
        fs::file_move(r_tmp_tif, rast_tif)
        rm(r)
        rm(r_tmp)
    }
    else {
        terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
    }
    r <- terra::rast(rast_tif)
}
debug: if (fs::file_exists(rast_tif)) {
    r_tmp_tif <- tempfile(fileext = ".tif")
    r_tmp <- c(rast(rast_tif), r)
    r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
    terra::writeRaster(r_tmp, r_tmp_tif)
    fs::file_delete(rast_tif)
    fs::file_move(r_tmp_tif, rast_tif)
    rm(r)
    rm(r_tmp)
} else {
    terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
}
debug: terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
debug: r <- terra::rast(rast_tif)
debug: d_r <- mutate(tidyr::pivot_longer(sf::st_drop_geometry(sf::st_as_sf(terra::zonal(x = r, 
    z = terra::vect(dplyr::select(sf_zones, dplyr::all_of(fld_zones))), 
    fun = zonal_fun, exact = T, na.rm = T, as.polygons = T))), 
    cols = -dplyr::any_of(fld_zones), names_to = "lyr", values_to = zonal_fun), 
    time = readr::parse_datetime(str_replace(lyr, glue("{var}\\|(.*)"), 
        "\\1")))
debug: if (!is.null(zonal_csv)) write_csv(d_r, zonal_csv)
debug: write_csv(d_r, zonal_csv)
debug: if (!keep_nc) unlink(dir_nc, recursive = T)
debug: unlink(dir_nc, recursive = T)
debug: return(d_r)
Downloading 1 requests, up to 641 time slices each
Called from: extractr::ed_extract(ed, var = v, sf_zones = ply, bbox = bb, 
    mask_tif = F, rast_tif = glue("{dir_out}/{nms}/{yr}.tif"), 
    zonal_fun = "mean", zonal_csv = glue("{dir_out}/{nms}/{yr}.csv"), 
    dir_nc = glue("{dir_out}/{nms}/{yr}_nc"), keep_nc = F, n_max_vals_per_req = 1e+05, 
    time_min = time_min, time_max = time_max, verbose = T)
debug: while (i_req <= n_reqs) {
    i_t_beg <- (i_req - 1) * n_t_per_req + 1
    i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
    t_req <- times_todo[c(i_t_beg, i_t_end)]
    t_req_str <- format_ISO8601(t_req, usetz = "Z")
    if (verbose) 
        message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
    ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
        ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
        0), nc)
    unlink(ncs0)
    nc_retry <- T
    nc_n_try <- 1
    n_max_retries
    while (nc_retry) {
        res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
            url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
                bbox[["xmax"]]), latitude = c(bbox[["ymin"]], 
                bbox[["ymax"]]), time = t_req_str, fmt = "nc", 
            store = rerddap::disk(path = dir_nc)))
        if (inherits(res, "try-error")) {
            err <- attr(res, "condition")
            msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
            nc_n_try <- nc_n_try + 1
            if (nc_n_try > n_max_retries) {
                stop(msg)
            }
            else {
                message(msg, "\nRETRYing...")
                Sys.sleep(1)
            }
        }
        else {
            nc_retry <- F
        }
    }
    i_req <- i_req + 1
}
debug: i_t_beg <- (i_req - 1) * n_t_per_req + 1
debug: i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
debug: t_req <- times_todo[c(i_t_beg, i_t_end)]
debug: t_req_str <- format_ISO8601(t_req, usetz = "Z")
debug: if (verbose) message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
debug: message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
Fetching request 1 of 1 (2006-01-01 to 2006-12-01) ~ 19:40:40 UTC
debug: ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
    0), nc)
debug: unlink(ncs0)
debug: nc_retry <- T
debug: nc_n_try <- 1
debug: n_max_retries
debug: while (nc_retry) {
    res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
        url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
            bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
        time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
    if (inherits(res, "try-error")) {
        err <- attr(res, "condition")
        msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
        nc_n_try <- nc_n_try + 1
        if (nc_n_try > n_max_retries) {
            stop(msg)
        }
        else {
            message(msg, "\nRETRYing...")
            Sys.sleep(1)
        }
    }
    else {
        nc_retry <- F
    }
}
debug: res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
    url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
        bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
    time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
debug: if (inherits(res, "try-error")) {
    err <- attr(res, "condition")
    msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
    nc_n_try <- nc_n_try + 1
    if (nc_n_try > n_max_retries) {
        stop(msg)
    }
    else {
        message(msg, "\nRETRYing...")
        Sys.sleep(1)
    }
} else {
    nc_retry <- F
}
debug: nc_retry <- F
debug: (while) nc_retry
debug: i_req <- i_req + 1
debug: (while) i_req <= n_reqs
debug: ncs <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size > 
    0), nc)
debug: r <- terra::rast(ncs)
debug: stopifnot(all(class(terra::time(r)) %in% c("POSIXct", "POSIXt")))
debug: idx <- dplyr::pull(dplyr::filter(dplyr::arrange(dplyr::tibble(idx = 1:terra::nlyr(r), 
    time = terra::time(r)), time), !duplicated(time)), idx)
debug: r <- terra::subset(r, idx)
debug: stopifnot(terra::crs(r, proj = T) == wgs84)
debug: if (mask_tif) r <- terra::mask(r, sf_zones)
debug: lyrs <- glue("{var}|{terra::time(r)}")
debug: if (length(dims_other) > 0 && !all(length(dims[dims_other]) == 
    1)) stop(glue("Other dimensions not yet supported: {paste(dims_other, collapse = ',')}"))
debug: names(r) <- lyrs
debug: if (!is.null(rast_tif)) {
    if (fs::file_exists(rast_tif)) {
        r_tmp_tif <- tempfile(fileext = ".tif")
        r_tmp <- c(rast(rast_tif), r)
        r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
        terra::writeRaster(r_tmp, r_tmp_tif)
        fs::file_delete(rast_tif)
        fs::file_move(r_tmp_tif, rast_tif)
        rm(r)
        rm(r_tmp)
    }
    else {
        terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
    }
    r <- terra::rast(rast_tif)
}
debug: if (fs::file_exists(rast_tif)) {
    r_tmp_tif <- tempfile(fileext = ".tif")
    r_tmp <- c(rast(rast_tif), r)
    r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
    terra::writeRaster(r_tmp, r_tmp_tif)
    fs::file_delete(rast_tif)
    fs::file_move(r_tmp_tif, rast_tif)
    rm(r)
    rm(r_tmp)
} else {
    terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
}
debug: terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
debug: r <- terra::rast(rast_tif)
debug: d_r <- mutate(tidyr::pivot_longer(sf::st_drop_geometry(sf::st_as_sf(terra::zonal(x = r, 
    z = terra::vect(dplyr::select(sf_zones, dplyr::all_of(fld_zones))), 
    fun = zonal_fun, exact = T, na.rm = T, as.polygons = T))), 
    cols = -dplyr::any_of(fld_zones), names_to = "lyr", values_to = zonal_fun), 
    time = readr::parse_datetime(str_replace(lyr, glue("{var}\\|(.*)"), 
        "\\1")))
debug: if (!is.null(zonal_csv)) write_csv(d_r, zonal_csv)
debug: write_csv(d_r, zonal_csv)
debug: if (!keep_nc) unlink(dir_nc, recursive = T)
debug: unlink(dir_nc, recursive = T)
debug: return(d_r)
Downloading 1 requests, up to 641 time slices each
Called from: extractr::ed_extract(ed, var = v, sf_zones = ply, bbox = bb, 
    mask_tif = F, rast_tif = glue("{dir_out}/{nms}/{yr}.tif"), 
    zonal_fun = "mean", zonal_csv = glue("{dir_out}/{nms}/{yr}.csv"), 
    dir_nc = glue("{dir_out}/{nms}/{yr}_nc"), keep_nc = F, n_max_vals_per_req = 1e+05, 
    time_min = time_min, time_max = time_max, verbose = T)
debug: while (i_req <= n_reqs) {
    i_t_beg <- (i_req - 1) * n_t_per_req + 1
    i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
    t_req <- times_todo[c(i_t_beg, i_t_end)]
    t_req_str <- format_ISO8601(t_req, usetz = "Z")
    if (verbose) 
        message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
    ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
        ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
        0), nc)
    unlink(ncs0)
    nc_retry <- T
    nc_n_try <- 1
    n_max_retries
    while (nc_retry) {
        res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
            url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
                bbox[["xmax"]]), latitude = c(bbox[["ymin"]], 
                bbox[["ymax"]]), time = t_req_str, fmt = "nc", 
            store = rerddap::disk(path = dir_nc)))
        if (inherits(res, "try-error")) {
            err <- attr(res, "condition")
            msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
            nc_n_try <- nc_n_try + 1
            if (nc_n_try > n_max_retries) {
                stop(msg)
            }
            else {
                message(msg, "\nRETRYing...")
                Sys.sleep(1)
            }
        }
        else {
            nc_retry <- F
        }
    }
    i_req <- i_req + 1
}
debug: i_t_beg <- (i_req - 1) * n_t_per_req + 1
debug: i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
debug: t_req <- times_todo[c(i_t_beg, i_t_end)]
debug: t_req_str <- format_ISO8601(t_req, usetz = "Z")
debug: if (verbose) message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
debug: message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
Fetching request 1 of 1 (2007-01-01 to 2007-12-01) ~ 19:40:42 UTC
debug: ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
    0), nc)
debug: unlink(ncs0)
debug: nc_retry <- T
debug: nc_n_try <- 1
debug: n_max_retries
debug: while (nc_retry) {
    res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
        url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
            bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
        time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
    if (inherits(res, "try-error")) {
        err <- attr(res, "condition")
        msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
        nc_n_try <- nc_n_try + 1
        if (nc_n_try > n_max_retries) {
            stop(msg)
        }
        else {
            message(msg, "\nRETRYing...")
            Sys.sleep(1)
        }
    }
    else {
        nc_retry <- F
    }
}
debug: res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
    url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
        bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
    time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
debug: if (inherits(res, "try-error")) {
    err <- attr(res, "condition")
    msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
    nc_n_try <- nc_n_try + 1
    if (nc_n_try > n_max_retries) {
        stop(msg)
    }
    else {
        message(msg, "\nRETRYing...")
        Sys.sleep(1)
    }
} else {
    nc_retry <- F
}
debug: nc_retry <- F
debug: (while) nc_retry
debug: i_req <- i_req + 1
debug: (while) i_req <= n_reqs
debug: ncs <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size > 
    0), nc)
debug: r <- terra::rast(ncs)
debug: stopifnot(all(class(terra::time(r)) %in% c("POSIXct", "POSIXt")))
debug: idx <- dplyr::pull(dplyr::filter(dplyr::arrange(dplyr::tibble(idx = 1:terra::nlyr(r), 
    time = terra::time(r)), time), !duplicated(time)), idx)
debug: r <- terra::subset(r, idx)
debug: stopifnot(terra::crs(r, proj = T) == wgs84)
debug: if (mask_tif) r <- terra::mask(r, sf_zones)
debug: lyrs <- glue("{var}|{terra::time(r)}")
debug: if (length(dims_other) > 0 && !all(length(dims[dims_other]) == 
    1)) stop(glue("Other dimensions not yet supported: {paste(dims_other, collapse = ',')}"))
debug: names(r) <- lyrs
debug: if (!is.null(rast_tif)) {
    if (fs::file_exists(rast_tif)) {
        r_tmp_tif <- tempfile(fileext = ".tif")
        r_tmp <- c(rast(rast_tif), r)
        r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
        terra::writeRaster(r_tmp, r_tmp_tif)
        fs::file_delete(rast_tif)
        fs::file_move(r_tmp_tif, rast_tif)
        rm(r)
        rm(r_tmp)
    }
    else {
        terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
    }
    r <- terra::rast(rast_tif)
}
debug: if (fs::file_exists(rast_tif)) {
    r_tmp_tif <- tempfile(fileext = ".tif")
    r_tmp <- c(rast(rast_tif), r)
    r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
    terra::writeRaster(r_tmp, r_tmp_tif)
    fs::file_delete(rast_tif)
    fs::file_move(r_tmp_tif, rast_tif)
    rm(r)
    rm(r_tmp)
} else {
    terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
}
debug: terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
debug: r <- terra::rast(rast_tif)
debug: d_r <- mutate(tidyr::pivot_longer(sf::st_drop_geometry(sf::st_as_sf(terra::zonal(x = r, 
    z = terra::vect(dplyr::select(sf_zones, dplyr::all_of(fld_zones))), 
    fun = zonal_fun, exact = T, na.rm = T, as.polygons = T))), 
    cols = -dplyr::any_of(fld_zones), names_to = "lyr", values_to = zonal_fun), 
    time = readr::parse_datetime(str_replace(lyr, glue("{var}\\|(.*)"), 
        "\\1")))
debug: if (!is.null(zonal_csv)) write_csv(d_r, zonal_csv)
debug: write_csv(d_r, zonal_csv)
debug: if (!keep_nc) unlink(dir_nc, recursive = T)
debug: unlink(dir_nc, recursive = T)
debug: return(d_r)
Downloading 1 requests, up to 641 time slices each
Called from: extractr::ed_extract(ed, var = v, sf_zones = ply, bbox = bb, 
    mask_tif = F, rast_tif = glue("{dir_out}/{nms}/{yr}.tif"), 
    zonal_fun = "mean", zonal_csv = glue("{dir_out}/{nms}/{yr}.csv"), 
    dir_nc = glue("{dir_out}/{nms}/{yr}_nc"), keep_nc = F, n_max_vals_per_req = 1e+05, 
    time_min = time_min, time_max = time_max, verbose = T)
debug: while (i_req <= n_reqs) {
    i_t_beg <- (i_req - 1) * n_t_per_req + 1
    i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
    t_req <- times_todo[c(i_t_beg, i_t_end)]
    t_req_str <- format_ISO8601(t_req, usetz = "Z")
    if (verbose) 
        message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
    ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
        ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
        0), nc)
    unlink(ncs0)
    nc_retry <- T
    nc_n_try <- 1
    n_max_retries
    while (nc_retry) {
        res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
            url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
                bbox[["xmax"]]), latitude = c(bbox[["ymin"]], 
                bbox[["ymax"]]), time = t_req_str, fmt = "nc", 
            store = rerddap::disk(path = dir_nc)))
        if (inherits(res, "try-error")) {
            err <- attr(res, "condition")
            msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
            nc_n_try <- nc_n_try + 1
            if (nc_n_try > n_max_retries) {
                stop(msg)
            }
            else {
                message(msg, "\nRETRYing...")
                Sys.sleep(1)
            }
        }
        else {
            nc_retry <- F
        }
    }
    i_req <- i_req + 1
}
debug: i_t_beg <- (i_req - 1) * n_t_per_req + 1
debug: i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
debug: t_req <- times_todo[c(i_t_beg, i_t_end)]
debug: t_req_str <- format_ISO8601(t_req, usetz = "Z")
debug: if (verbose) message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
debug: message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
Fetching request 1 of 1 (2008-01-01 to 2008-12-01) ~ 19:40:44 UTC
debug: ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
    0), nc)
debug: unlink(ncs0)
debug: nc_retry <- T
debug: nc_n_try <- 1
debug: n_max_retries
debug: while (nc_retry) {
    res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
        url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
            bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
        time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
    if (inherits(res, "try-error")) {
        err <- attr(res, "condition")
        msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
        nc_n_try <- nc_n_try + 1
        if (nc_n_try > n_max_retries) {
            stop(msg)
        }
        else {
            message(msg, "\nRETRYing...")
            Sys.sleep(1)
        }
    }
    else {
        nc_retry <- F
    }
}
debug: res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
    url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
        bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
    time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
debug: if (inherits(res, "try-error")) {
    err <- attr(res, "condition")
    msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
    nc_n_try <- nc_n_try + 1
    if (nc_n_try > n_max_retries) {
        stop(msg)
    }
    else {
        message(msg, "\nRETRYing...")
        Sys.sleep(1)
    }
} else {
    nc_retry <- F
}
debug: nc_retry <- F
debug: (while) nc_retry
debug: i_req <- i_req + 1
debug: (while) i_req <= n_reqs
debug: ncs <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size > 
    0), nc)
debug: r <- terra::rast(ncs)
debug: stopifnot(all(class(terra::time(r)) %in% c("POSIXct", "POSIXt")))
debug: idx <- dplyr::pull(dplyr::filter(dplyr::arrange(dplyr::tibble(idx = 1:terra::nlyr(r), 
    time = terra::time(r)), time), !duplicated(time)), idx)
debug: r <- terra::subset(r, idx)
debug: stopifnot(terra::crs(r, proj = T) == wgs84)
debug: if (mask_tif) r <- terra::mask(r, sf_zones)
debug: lyrs <- glue("{var}|{terra::time(r)}")
debug: if (length(dims_other) > 0 && !all(length(dims[dims_other]) == 
    1)) stop(glue("Other dimensions not yet supported: {paste(dims_other, collapse = ',')}"))
debug: names(r) <- lyrs
debug: if (!is.null(rast_tif)) {
    if (fs::file_exists(rast_tif)) {
        r_tmp_tif <- tempfile(fileext = ".tif")
        r_tmp <- c(rast(rast_tif), r)
        r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
        terra::writeRaster(r_tmp, r_tmp_tif)
        fs::file_delete(rast_tif)
        fs::file_move(r_tmp_tif, rast_tif)
        rm(r)
        rm(r_tmp)
    }
    else {
        terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
    }
    r <- terra::rast(rast_tif)
}
debug: if (fs::file_exists(rast_tif)) {
    r_tmp_tif <- tempfile(fileext = ".tif")
    r_tmp <- c(rast(rast_tif), r)
    r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
    terra::writeRaster(r_tmp, r_tmp_tif)
    fs::file_delete(rast_tif)
    fs::file_move(r_tmp_tif, rast_tif)
    rm(r)
    rm(r_tmp)
} else {
    terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
}
debug: terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
debug: r <- terra::rast(rast_tif)
debug: d_r <- mutate(tidyr::pivot_longer(sf::st_drop_geometry(sf::st_as_sf(terra::zonal(x = r, 
    z = terra::vect(dplyr::select(sf_zones, dplyr::all_of(fld_zones))), 
    fun = zonal_fun, exact = T, na.rm = T, as.polygons = T))), 
    cols = -dplyr::any_of(fld_zones), names_to = "lyr", values_to = zonal_fun), 
    time = readr::parse_datetime(str_replace(lyr, glue("{var}\\|(.*)"), 
        "\\1")))
debug: if (!is.null(zonal_csv)) write_csv(d_r, zonal_csv)
debug: write_csv(d_r, zonal_csv)
debug: if (!keep_nc) unlink(dir_nc, recursive = T)
debug: unlink(dir_nc, recursive = T)
debug: return(d_r)
Downloading 1 requests, up to 641 time slices each
Called from: extractr::ed_extract(ed, var = v, sf_zones = ply, bbox = bb, 
    mask_tif = F, rast_tif = glue("{dir_out}/{nms}/{yr}.tif"), 
    zonal_fun = "mean", zonal_csv = glue("{dir_out}/{nms}/{yr}.csv"), 
    dir_nc = glue("{dir_out}/{nms}/{yr}_nc"), keep_nc = F, n_max_vals_per_req = 1e+05, 
    time_min = time_min, time_max = time_max, verbose = T)
debug: while (i_req <= n_reqs) {
    i_t_beg <- (i_req - 1) * n_t_per_req + 1
    i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
    t_req <- times_todo[c(i_t_beg, i_t_end)]
    t_req_str <- format_ISO8601(t_req, usetz = "Z")
    if (verbose) 
        message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
    ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
        ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
        0), nc)
    unlink(ncs0)
    nc_retry <- T
    nc_n_try <- 1
    n_max_retries
    while (nc_retry) {
        res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
            url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
                bbox[["xmax"]]), latitude = c(bbox[["ymin"]], 
                bbox[["ymax"]]), time = t_req_str, fmt = "nc", 
            store = rerddap::disk(path = dir_nc)))
        if (inherits(res, "try-error")) {
            err <- attr(res, "condition")
            msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
            nc_n_try <- nc_n_try + 1
            if (nc_n_try > n_max_retries) {
                stop(msg)
            }
            else {
                message(msg, "\nRETRYing...")
                Sys.sleep(1)
            }
        }
        else {
            nc_retry <- F
        }
    }
    i_req <- i_req + 1
}
debug: i_t_beg <- (i_req - 1) * n_t_per_req + 1
debug: i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
debug: t_req <- times_todo[c(i_t_beg, i_t_end)]
debug: t_req_str <- format_ISO8601(t_req, usetz = "Z")
debug: if (verbose) message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
debug: message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
Fetching request 1 of 1 (2009-01-01 to 2009-12-01) ~ 19:40:45 UTC
debug: ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
    0), nc)
debug: unlink(ncs0)
debug: nc_retry <- T
debug: nc_n_try <- 1
debug: n_max_retries
debug: while (nc_retry) {
    res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
        url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
            bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
        time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
    if (inherits(res, "try-error")) {
        err <- attr(res, "condition")
        msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
        nc_n_try <- nc_n_try + 1
        if (nc_n_try > n_max_retries) {
            stop(msg)
        }
        else {
            message(msg, "\nRETRYing...")
            Sys.sleep(1)
        }
    }
    else {
        nc_retry <- F
    }
}
debug: res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
    url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
        bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
    time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
debug: if (inherits(res, "try-error")) {
    err <- attr(res, "condition")
    msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
    nc_n_try <- nc_n_try + 1
    if (nc_n_try > n_max_retries) {
        stop(msg)
    }
    else {
        message(msg, "\nRETRYing...")
        Sys.sleep(1)
    }
} else {
    nc_retry <- F
}
debug: nc_retry <- F
debug: (while) nc_retry
debug: i_req <- i_req + 1
debug: (while) i_req <= n_reqs
debug: ncs <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size > 
    0), nc)
debug: r <- terra::rast(ncs)
debug: stopifnot(all(class(terra::time(r)) %in% c("POSIXct", "POSIXt")))
debug: idx <- dplyr::pull(dplyr::filter(dplyr::arrange(dplyr::tibble(idx = 1:terra::nlyr(r), 
    time = terra::time(r)), time), !duplicated(time)), idx)
debug: r <- terra::subset(r, idx)
debug: stopifnot(terra::crs(r, proj = T) == wgs84)
debug: if (mask_tif) r <- terra::mask(r, sf_zones)
debug: lyrs <- glue("{var}|{terra::time(r)}")
debug: if (length(dims_other) > 0 && !all(length(dims[dims_other]) == 
    1)) stop(glue("Other dimensions not yet supported: {paste(dims_other, collapse = ',')}"))
debug: names(r) <- lyrs
debug: if (!is.null(rast_tif)) {
    if (fs::file_exists(rast_tif)) {
        r_tmp_tif <- tempfile(fileext = ".tif")
        r_tmp <- c(rast(rast_tif), r)
        r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
        terra::writeRaster(r_tmp, r_tmp_tif)
        fs::file_delete(rast_tif)
        fs::file_move(r_tmp_tif, rast_tif)
        rm(r)
        rm(r_tmp)
    }
    else {
        terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
    }
    r <- terra::rast(rast_tif)
}
debug: if (fs::file_exists(rast_tif)) {
    r_tmp_tif <- tempfile(fileext = ".tif")
    r_tmp <- c(rast(rast_tif), r)
    r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
    terra::writeRaster(r_tmp, r_tmp_tif)
    fs::file_delete(rast_tif)
    fs::file_move(r_tmp_tif, rast_tif)
    rm(r)
    rm(r_tmp)
} else {
    terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
}
debug: terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
debug: r <- terra::rast(rast_tif)
debug: d_r <- mutate(tidyr::pivot_longer(sf::st_drop_geometry(sf::st_as_sf(terra::zonal(x = r, 
    z = terra::vect(dplyr::select(sf_zones, dplyr::all_of(fld_zones))), 
    fun = zonal_fun, exact = T, na.rm = T, as.polygons = T))), 
    cols = -dplyr::any_of(fld_zones), names_to = "lyr", values_to = zonal_fun), 
    time = readr::parse_datetime(str_replace(lyr, glue("{var}\\|(.*)"), 
        "\\1")))
debug: if (!is.null(zonal_csv)) write_csv(d_r, zonal_csv)
debug: write_csv(d_r, zonal_csv)
debug: if (!keep_nc) unlink(dir_nc, recursive = T)
debug: unlink(dir_nc, recursive = T)
debug: return(d_r)
Downloading 1 requests, up to 641 time slices each
Called from: extractr::ed_extract(ed, var = v, sf_zones = ply, bbox = bb, 
    mask_tif = F, rast_tif = glue("{dir_out}/{nms}/{yr}.tif"), 
    zonal_fun = "mean", zonal_csv = glue("{dir_out}/{nms}/{yr}.csv"), 
    dir_nc = glue("{dir_out}/{nms}/{yr}_nc"), keep_nc = F, n_max_vals_per_req = 1e+05, 
    time_min = time_min, time_max = time_max, verbose = T)
debug: while (i_req <= n_reqs) {
    i_t_beg <- (i_req - 1) * n_t_per_req + 1
    i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
    t_req <- times_todo[c(i_t_beg, i_t_end)]
    t_req_str <- format_ISO8601(t_req, usetz = "Z")
    if (verbose) 
        message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
    ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
        ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
        0), nc)
    unlink(ncs0)
    nc_retry <- T
    nc_n_try <- 1
    n_max_retries
    while (nc_retry) {
        res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
            url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
                bbox[["xmax"]]), latitude = c(bbox[["ymin"]], 
                bbox[["ymax"]]), time = t_req_str, fmt = "nc", 
            store = rerddap::disk(path = dir_nc)))
        if (inherits(res, "try-error")) {
            err <- attr(res, "condition")
            msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
            nc_n_try <- nc_n_try + 1
            if (nc_n_try > n_max_retries) {
                stop(msg)
            }
            else {
                message(msg, "\nRETRYing...")
                Sys.sleep(1)
            }
        }
        else {
            nc_retry <- F
        }
    }
    i_req <- i_req + 1
}
debug: i_t_beg <- (i_req - 1) * n_t_per_req + 1
debug: i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
debug: t_req <- times_todo[c(i_t_beg, i_t_end)]
debug: t_req_str <- format_ISO8601(t_req, usetz = "Z")
debug: if (verbose) message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
debug: message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
Fetching request 1 of 1 (2010-01-01 to 2010-12-01) ~ 19:40:47 UTC
debug: ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
    0), nc)
debug: unlink(ncs0)
debug: nc_retry <- T
debug: nc_n_try <- 1
debug: n_max_retries
debug: while (nc_retry) {
    res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
        url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
            bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
        time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
    if (inherits(res, "try-error")) {
        err <- attr(res, "condition")
        msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
        nc_n_try <- nc_n_try + 1
        if (nc_n_try > n_max_retries) {
            stop(msg)
        }
        else {
            message(msg, "\nRETRYing...")
            Sys.sleep(1)
        }
    }
    else {
        nc_retry <- F
    }
}
debug: res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
    url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
        bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
    time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
debug: if (inherits(res, "try-error")) {
    err <- attr(res, "condition")
    msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
    nc_n_try <- nc_n_try + 1
    if (nc_n_try > n_max_retries) {
        stop(msg)
    }
    else {
        message(msg, "\nRETRYing...")
        Sys.sleep(1)
    }
} else {
    nc_retry <- F
}
debug: nc_retry <- F
debug: (while) nc_retry
debug: i_req <- i_req + 1
debug: (while) i_req <= n_reqs
debug: ncs <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size > 
    0), nc)
debug: r <- terra::rast(ncs)
debug: stopifnot(all(class(terra::time(r)) %in% c("POSIXct", "POSIXt")))
debug: idx <- dplyr::pull(dplyr::filter(dplyr::arrange(dplyr::tibble(idx = 1:terra::nlyr(r), 
    time = terra::time(r)), time), !duplicated(time)), idx)
debug: r <- terra::subset(r, idx)
debug: stopifnot(terra::crs(r, proj = T) == wgs84)
debug: if (mask_tif) r <- terra::mask(r, sf_zones)
debug: lyrs <- glue("{var}|{terra::time(r)}")
debug: if (length(dims_other) > 0 && !all(length(dims[dims_other]) == 
    1)) stop(glue("Other dimensions not yet supported: {paste(dims_other, collapse = ',')}"))
debug: names(r) <- lyrs
debug: if (!is.null(rast_tif)) {
    if (fs::file_exists(rast_tif)) {
        r_tmp_tif <- tempfile(fileext = ".tif")
        r_tmp <- c(rast(rast_tif), r)
        r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
        terra::writeRaster(r_tmp, r_tmp_tif)
        fs::file_delete(rast_tif)
        fs::file_move(r_tmp_tif, rast_tif)
        rm(r)
        rm(r_tmp)
    }
    else {
        terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
    }
    r <- terra::rast(rast_tif)
}
debug: if (fs::file_exists(rast_tif)) {
    r_tmp_tif <- tempfile(fileext = ".tif")
    r_tmp <- c(rast(rast_tif), r)
    r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
    terra::writeRaster(r_tmp, r_tmp_tif)
    fs::file_delete(rast_tif)
    fs::file_move(r_tmp_tif, rast_tif)
    rm(r)
    rm(r_tmp)
} else {
    terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
}
debug: terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
debug: r <- terra::rast(rast_tif)
debug: d_r <- mutate(tidyr::pivot_longer(sf::st_drop_geometry(sf::st_as_sf(terra::zonal(x = r, 
    z = terra::vect(dplyr::select(sf_zones, dplyr::all_of(fld_zones))), 
    fun = zonal_fun, exact = T, na.rm = T, as.polygons = T))), 
    cols = -dplyr::any_of(fld_zones), names_to = "lyr", values_to = zonal_fun), 
    time = readr::parse_datetime(str_replace(lyr, glue("{var}\\|(.*)"), 
        "\\1")))
debug: if (!is.null(zonal_csv)) write_csv(d_r, zonal_csv)
debug: write_csv(d_r, zonal_csv)
debug: if (!keep_nc) unlink(dir_nc, recursive = T)
debug: unlink(dir_nc, recursive = T)
debug: return(d_r)
Downloading 1 requests, up to 641 time slices each
Called from: extractr::ed_extract(ed, var = v, sf_zones = ply, bbox = bb, 
    mask_tif = F, rast_tif = glue("{dir_out}/{nms}/{yr}.tif"), 
    zonal_fun = "mean", zonal_csv = glue("{dir_out}/{nms}/{yr}.csv"), 
    dir_nc = glue("{dir_out}/{nms}/{yr}_nc"), keep_nc = F, n_max_vals_per_req = 1e+05, 
    time_min = time_min, time_max = time_max, verbose = T)
debug: while (i_req <= n_reqs) {
    i_t_beg <- (i_req - 1) * n_t_per_req + 1
    i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
    t_req <- times_todo[c(i_t_beg, i_t_end)]
    t_req_str <- format_ISO8601(t_req, usetz = "Z")
    if (verbose) 
        message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
    ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
        ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
        0), nc)
    unlink(ncs0)
    nc_retry <- T
    nc_n_try <- 1
    n_max_retries
    while (nc_retry) {
        res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
            url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
                bbox[["xmax"]]), latitude = c(bbox[["ymin"]], 
                bbox[["ymax"]]), time = t_req_str, fmt = "nc", 
            store = rerddap::disk(path = dir_nc)))
        if (inherits(res, "try-error")) {
            err <- attr(res, "condition")
            msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
            nc_n_try <- nc_n_try + 1
            if (nc_n_try > n_max_retries) {
                stop(msg)
            }
            else {
                message(msg, "\nRETRYing...")
                Sys.sleep(1)
            }
        }
        else {
            nc_retry <- F
        }
    }
    i_req <- i_req + 1
}
debug: i_t_beg <- (i_req - 1) * n_t_per_req + 1
debug: i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
debug: t_req <- times_todo[c(i_t_beg, i_t_end)]
debug: t_req_str <- format_ISO8601(t_req, usetz = "Z")
debug: if (verbose) message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
debug: message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
Fetching request 1 of 1 (2011-01-01 to 2011-12-01) ~ 19:40:49 UTC
debug: ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
    0), nc)
debug: unlink(ncs0)
debug: nc_retry <- T
debug: nc_n_try <- 1
debug: n_max_retries
debug: while (nc_retry) {
    res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
        url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
            bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
        time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
    if (inherits(res, "try-error")) {
        err <- attr(res, "condition")
        msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
        nc_n_try <- nc_n_try + 1
        if (nc_n_try > n_max_retries) {
            stop(msg)
        }
        else {
            message(msg, "\nRETRYing...")
            Sys.sleep(1)
        }
    }
    else {
        nc_retry <- F
    }
}
debug: res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
    url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
        bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
    time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
debug: if (inherits(res, "try-error")) {
    err <- attr(res, "condition")
    msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
    nc_n_try <- nc_n_try + 1
    if (nc_n_try > n_max_retries) {
        stop(msg)
    }
    else {
        message(msg, "\nRETRYing...")
        Sys.sleep(1)
    }
} else {
    nc_retry <- F
}
debug: nc_retry <- F
debug: (while) nc_retry
debug: i_req <- i_req + 1
debug: (while) i_req <= n_reqs
debug: ncs <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size > 
    0), nc)
debug: r <- terra::rast(ncs)
debug: stopifnot(all(class(terra::time(r)) %in% c("POSIXct", "POSIXt")))
debug: idx <- dplyr::pull(dplyr::filter(dplyr::arrange(dplyr::tibble(idx = 1:terra::nlyr(r), 
    time = terra::time(r)), time), !duplicated(time)), idx)
debug: r <- terra::subset(r, idx)
debug: stopifnot(terra::crs(r, proj = T) == wgs84)
debug: if (mask_tif) r <- terra::mask(r, sf_zones)
debug: lyrs <- glue("{var}|{terra::time(r)}")
debug: if (length(dims_other) > 0 && !all(length(dims[dims_other]) == 
    1)) stop(glue("Other dimensions not yet supported: {paste(dims_other, collapse = ',')}"))
debug: names(r) <- lyrs
debug: if (!is.null(rast_tif)) {
    if (fs::file_exists(rast_tif)) {
        r_tmp_tif <- tempfile(fileext = ".tif")
        r_tmp <- c(rast(rast_tif), r)
        r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
        terra::writeRaster(r_tmp, r_tmp_tif)
        fs::file_delete(rast_tif)
        fs::file_move(r_tmp_tif, rast_tif)
        rm(r)
        rm(r_tmp)
    }
    else {
        terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
    }
    r <- terra::rast(rast_tif)
}
debug: if (fs::file_exists(rast_tif)) {
    r_tmp_tif <- tempfile(fileext = ".tif")
    r_tmp <- c(rast(rast_tif), r)
    r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
    terra::writeRaster(r_tmp, r_tmp_tif)
    fs::file_delete(rast_tif)
    fs::file_move(r_tmp_tif, rast_tif)
    rm(r)
    rm(r_tmp)
} else {
    terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
}
debug: terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
debug: r <- terra::rast(rast_tif)
debug: d_r <- mutate(tidyr::pivot_longer(sf::st_drop_geometry(sf::st_as_sf(terra::zonal(x = r, 
    z = terra::vect(dplyr::select(sf_zones, dplyr::all_of(fld_zones))), 
    fun = zonal_fun, exact = T, na.rm = T, as.polygons = T))), 
    cols = -dplyr::any_of(fld_zones), names_to = "lyr", values_to = zonal_fun), 
    time = readr::parse_datetime(str_replace(lyr, glue("{var}\\|(.*)"), 
        "\\1")))
debug: if (!is.null(zonal_csv)) write_csv(d_r, zonal_csv)
debug: write_csv(d_r, zonal_csv)
debug: if (!keep_nc) unlink(dir_nc, recursive = T)
debug: unlink(dir_nc, recursive = T)
debug: return(d_r)
Downloading 1 requests, up to 641 time slices each
Called from: extractr::ed_extract(ed, var = v, sf_zones = ply, bbox = bb, 
    mask_tif = F, rast_tif = glue("{dir_out}/{nms}/{yr}.tif"), 
    zonal_fun = "mean", zonal_csv = glue("{dir_out}/{nms}/{yr}.csv"), 
    dir_nc = glue("{dir_out}/{nms}/{yr}_nc"), keep_nc = F, n_max_vals_per_req = 1e+05, 
    time_min = time_min, time_max = time_max, verbose = T)
debug: while (i_req <= n_reqs) {
    i_t_beg <- (i_req - 1) * n_t_per_req + 1
    i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
    t_req <- times_todo[c(i_t_beg, i_t_end)]
    t_req_str <- format_ISO8601(t_req, usetz = "Z")
    if (verbose) 
        message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
    ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
        ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
        0), nc)
    unlink(ncs0)
    nc_retry <- T
    nc_n_try <- 1
    n_max_retries
    while (nc_retry) {
        res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
            url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
                bbox[["xmax"]]), latitude = c(bbox[["ymin"]], 
                bbox[["ymax"]]), time = t_req_str, fmt = "nc", 
            store = rerddap::disk(path = dir_nc)))
        if (inherits(res, "try-error")) {
            err <- attr(res, "condition")
            msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
            nc_n_try <- nc_n_try + 1
            if (nc_n_try > n_max_retries) {
                stop(msg)
            }
            else {
                message(msg, "\nRETRYing...")
                Sys.sleep(1)
            }
        }
        else {
            nc_retry <- F
        }
    }
    i_req <- i_req + 1
}
debug: i_t_beg <- (i_req - 1) * n_t_per_req + 1
debug: i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
debug: t_req <- times_todo[c(i_t_beg, i_t_end)]
debug: t_req_str <- format_ISO8601(t_req, usetz = "Z")
debug: if (verbose) message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
debug: message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
Fetching request 1 of 1 (2012-01-01 to 2012-12-01) ~ 19:40:50 UTC
debug: ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
    0), nc)
debug: unlink(ncs0)
debug: nc_retry <- T
debug: nc_n_try <- 1
debug: n_max_retries
debug: while (nc_retry) {
    res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
        url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
            bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
        time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
    if (inherits(res, "try-error")) {
        err <- attr(res, "condition")
        msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
        nc_n_try <- nc_n_try + 1
        if (nc_n_try > n_max_retries) {
            stop(msg)
        }
        else {
            message(msg, "\nRETRYing...")
            Sys.sleep(1)
        }
    }
    else {
        nc_retry <- F
    }
}
debug: res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
    url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
        bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
    time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
debug: if (inherits(res, "try-error")) {
    err <- attr(res, "condition")
    msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
    nc_n_try <- nc_n_try + 1
    if (nc_n_try > n_max_retries) {
        stop(msg)
    }
    else {
        message(msg, "\nRETRYing...")
        Sys.sleep(1)
    }
} else {
    nc_retry <- F
}
debug: nc_retry <- F
debug: (while) nc_retry
debug: i_req <- i_req + 1
debug: (while) i_req <= n_reqs
debug: ncs <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size > 
    0), nc)
debug: r <- terra::rast(ncs)
debug: stopifnot(all(class(terra::time(r)) %in% c("POSIXct", "POSIXt")))
debug: idx <- dplyr::pull(dplyr::filter(dplyr::arrange(dplyr::tibble(idx = 1:terra::nlyr(r), 
    time = terra::time(r)), time), !duplicated(time)), idx)
debug: r <- terra::subset(r, idx)
debug: stopifnot(terra::crs(r, proj = T) == wgs84)
debug: if (mask_tif) r <- terra::mask(r, sf_zones)
debug: lyrs <- glue("{var}|{terra::time(r)}")
debug: if (length(dims_other) > 0 && !all(length(dims[dims_other]) == 
    1)) stop(glue("Other dimensions not yet supported: {paste(dims_other, collapse = ',')}"))
debug: names(r) <- lyrs
debug: if (!is.null(rast_tif)) {
    if (fs::file_exists(rast_tif)) {
        r_tmp_tif <- tempfile(fileext = ".tif")
        r_tmp <- c(rast(rast_tif), r)
        r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
        terra::writeRaster(r_tmp, r_tmp_tif)
        fs::file_delete(rast_tif)
        fs::file_move(r_tmp_tif, rast_tif)
        rm(r)
        rm(r_tmp)
    }
    else {
        terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
    }
    r <- terra::rast(rast_tif)
}
debug: if (fs::file_exists(rast_tif)) {
    r_tmp_tif <- tempfile(fileext = ".tif")
    r_tmp <- c(rast(rast_tif), r)
    r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
    terra::writeRaster(r_tmp, r_tmp_tif)
    fs::file_delete(rast_tif)
    fs::file_move(r_tmp_tif, rast_tif)
    rm(r)
    rm(r_tmp)
} else {
    terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
}
debug: terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
debug: r <- terra::rast(rast_tif)
debug: d_r <- mutate(tidyr::pivot_longer(sf::st_drop_geometry(sf::st_as_sf(terra::zonal(x = r, 
    z = terra::vect(dplyr::select(sf_zones, dplyr::all_of(fld_zones))), 
    fun = zonal_fun, exact = T, na.rm = T, as.polygons = T))), 
    cols = -dplyr::any_of(fld_zones), names_to = "lyr", values_to = zonal_fun), 
    time = readr::parse_datetime(str_replace(lyr, glue("{var}\\|(.*)"), 
        "\\1")))
debug: if (!is.null(zonal_csv)) write_csv(d_r, zonal_csv)
debug: write_csv(d_r, zonal_csv)
debug: if (!keep_nc) unlink(dir_nc, recursive = T)
debug: unlink(dir_nc, recursive = T)
debug: return(d_r)
Downloading 1 requests, up to 641 time slices each
Called from: extractr::ed_extract(ed, var = v, sf_zones = ply, bbox = bb, 
    mask_tif = F, rast_tif = glue("{dir_out}/{nms}/{yr}.tif"), 
    zonal_fun = "mean", zonal_csv = glue("{dir_out}/{nms}/{yr}.csv"), 
    dir_nc = glue("{dir_out}/{nms}/{yr}_nc"), keep_nc = F, n_max_vals_per_req = 1e+05, 
    time_min = time_min, time_max = time_max, verbose = T)
debug: while (i_req <= n_reqs) {
    i_t_beg <- (i_req - 1) * n_t_per_req + 1
    i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
    t_req <- times_todo[c(i_t_beg, i_t_end)]
    t_req_str <- format_ISO8601(t_req, usetz = "Z")
    if (verbose) 
        message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
    ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
        ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
        0), nc)
    unlink(ncs0)
    nc_retry <- T
    nc_n_try <- 1
    n_max_retries
    while (nc_retry) {
        res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
            url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
                bbox[["xmax"]]), latitude = c(bbox[["ymin"]], 
                bbox[["ymax"]]), time = t_req_str, fmt = "nc", 
            store = rerddap::disk(path = dir_nc)))
        if (inherits(res, "try-error")) {
            err <- attr(res, "condition")
            msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
            nc_n_try <- nc_n_try + 1
            if (nc_n_try > n_max_retries) {
                stop(msg)
            }
            else {
                message(msg, "\nRETRYing...")
                Sys.sleep(1)
            }
        }
        else {
            nc_retry <- F
        }
    }
    i_req <- i_req + 1
}
debug: i_t_beg <- (i_req - 1) * n_t_per_req + 1
debug: i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
debug: t_req <- times_todo[c(i_t_beg, i_t_end)]
debug: t_req_str <- format_ISO8601(t_req, usetz = "Z")
debug: if (verbose) message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
debug: message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
Fetching request 1 of 1 (2013-01-01 to 2013-12-01) ~ 19:40:52 UTC
debug: ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
    0), nc)
debug: unlink(ncs0)
debug: nc_retry <- T
debug: nc_n_try <- 1
debug: n_max_retries
debug: while (nc_retry) {
    res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
        url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
            bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
        time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
    if (inherits(res, "try-error")) {
        err <- attr(res, "condition")
        msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
        nc_n_try <- nc_n_try + 1
        if (nc_n_try > n_max_retries) {
            stop(msg)
        }
        else {
            message(msg, "\nRETRYing...")
            Sys.sleep(1)
        }
    }
    else {
        nc_retry <- F
    }
}
debug: res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
    url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
        bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
    time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
debug: if (inherits(res, "try-error")) {
    err <- attr(res, "condition")
    msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
    nc_n_try <- nc_n_try + 1
    if (nc_n_try > n_max_retries) {
        stop(msg)
    }
    else {
        message(msg, "\nRETRYing...")
        Sys.sleep(1)
    }
} else {
    nc_retry <- F
}
debug: nc_retry <- F
debug: (while) nc_retry
debug: i_req <- i_req + 1
debug: (while) i_req <= n_reqs
debug: ncs <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size > 
    0), nc)
debug: r <- terra::rast(ncs)
debug: stopifnot(all(class(terra::time(r)) %in% c("POSIXct", "POSIXt")))
debug: idx <- dplyr::pull(dplyr::filter(dplyr::arrange(dplyr::tibble(idx = 1:terra::nlyr(r), 
    time = terra::time(r)), time), !duplicated(time)), idx)
debug: r <- terra::subset(r, idx)
debug: stopifnot(terra::crs(r, proj = T) == wgs84)
debug: if (mask_tif) r <- terra::mask(r, sf_zones)
debug: lyrs <- glue("{var}|{terra::time(r)}")
debug: if (length(dims_other) > 0 && !all(length(dims[dims_other]) == 
    1)) stop(glue("Other dimensions not yet supported: {paste(dims_other, collapse = ',')}"))
debug: names(r) <- lyrs
debug: if (!is.null(rast_tif)) {
    if (fs::file_exists(rast_tif)) {
        r_tmp_tif <- tempfile(fileext = ".tif")
        r_tmp <- c(rast(rast_tif), r)
        r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
        terra::writeRaster(r_tmp, r_tmp_tif)
        fs::file_delete(rast_tif)
        fs::file_move(r_tmp_tif, rast_tif)
        rm(r)
        rm(r_tmp)
    }
    else {
        terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
    }
    r <- terra::rast(rast_tif)
}
debug: if (fs::file_exists(rast_tif)) {
    r_tmp_tif <- tempfile(fileext = ".tif")
    r_tmp <- c(rast(rast_tif), r)
    r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
    terra::writeRaster(r_tmp, r_tmp_tif)
    fs::file_delete(rast_tif)
    fs::file_move(r_tmp_tif, rast_tif)
    rm(r)
    rm(r_tmp)
} else {
    terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
}
debug: terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
debug: r <- terra::rast(rast_tif)
debug: d_r <- mutate(tidyr::pivot_longer(sf::st_drop_geometry(sf::st_as_sf(terra::zonal(x = r, 
    z = terra::vect(dplyr::select(sf_zones, dplyr::all_of(fld_zones))), 
    fun = zonal_fun, exact = T, na.rm = T, as.polygons = T))), 
    cols = -dplyr::any_of(fld_zones), names_to = "lyr", values_to = zonal_fun), 
    time = readr::parse_datetime(str_replace(lyr, glue("{var}\\|(.*)"), 
        "\\1")))
debug: if (!is.null(zonal_csv)) write_csv(d_r, zonal_csv)
debug: write_csv(d_r, zonal_csv)
debug: if (!keep_nc) unlink(dir_nc, recursive = T)
debug: unlink(dir_nc, recursive = T)
debug: return(d_r)
Downloading 1 requests, up to 641 time slices each
Called from: extractr::ed_extract(ed, var = v, sf_zones = ply, bbox = bb, 
    mask_tif = F, rast_tif = glue("{dir_out}/{nms}/{yr}.tif"), 
    zonal_fun = "mean", zonal_csv = glue("{dir_out}/{nms}/{yr}.csv"), 
    dir_nc = glue("{dir_out}/{nms}/{yr}_nc"), keep_nc = F, n_max_vals_per_req = 1e+05, 
    time_min = time_min, time_max = time_max, verbose = T)
debug: while (i_req <= n_reqs) {
    i_t_beg <- (i_req - 1) * n_t_per_req + 1
    i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
    t_req <- times_todo[c(i_t_beg, i_t_end)]
    t_req_str <- format_ISO8601(t_req, usetz = "Z")
    if (verbose) 
        message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
    ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
        ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
        0), nc)
    unlink(ncs0)
    nc_retry <- T
    nc_n_try <- 1
    n_max_retries
    while (nc_retry) {
        res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
            url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
                bbox[["xmax"]]), latitude = c(bbox[["ymin"]], 
                bbox[["ymax"]]), time = t_req_str, fmt = "nc", 
            store = rerddap::disk(path = dir_nc)))
        if (inherits(res, "try-error")) {
            err <- attr(res, "condition")
            msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
            nc_n_try <- nc_n_try + 1
            if (nc_n_try > n_max_retries) {
                stop(msg)
            }
            else {
                message(msg, "\nRETRYing...")
                Sys.sleep(1)
            }
        }
        else {
            nc_retry <- F
        }
    }
    i_req <- i_req + 1
}
debug: i_t_beg <- (i_req - 1) * n_t_per_req + 1
debug: i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
debug: t_req <- times_todo[c(i_t_beg, i_t_end)]
debug: t_req_str <- format_ISO8601(t_req, usetz = "Z")
debug: if (verbose) message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
debug: message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
Fetching request 1 of 1 (2014-01-01 to 2014-12-01) ~ 19:40:53 UTC
debug: ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
    0), nc)
debug: unlink(ncs0)
debug: nc_retry <- T
debug: nc_n_try <- 1
debug: n_max_retries
debug: while (nc_retry) {
    res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
        url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
            bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
        time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
    if (inherits(res, "try-error")) {
        err <- attr(res, "condition")
        msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
        nc_n_try <- nc_n_try + 1
        if (nc_n_try > n_max_retries) {
            stop(msg)
        }
        else {
            message(msg, "\nRETRYing...")
            Sys.sleep(1)
        }
    }
    else {
        nc_retry <- F
    }
}
debug: res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
    url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
        bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
    time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
debug: if (inherits(res, "try-error")) {
    err <- attr(res, "condition")
    msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
    nc_n_try <- nc_n_try + 1
    if (nc_n_try > n_max_retries) {
        stop(msg)
    }
    else {
        message(msg, "\nRETRYing...")
        Sys.sleep(1)
    }
} else {
    nc_retry <- F
}
debug: nc_retry <- F
debug: (while) nc_retry
debug: i_req <- i_req + 1
debug: (while) i_req <= n_reqs
debug: ncs <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size > 
    0), nc)
debug: r <- terra::rast(ncs)
debug: stopifnot(all(class(terra::time(r)) %in% c("POSIXct", "POSIXt")))
debug: idx <- dplyr::pull(dplyr::filter(dplyr::arrange(dplyr::tibble(idx = 1:terra::nlyr(r), 
    time = terra::time(r)), time), !duplicated(time)), idx)
debug: r <- terra::subset(r, idx)
debug: stopifnot(terra::crs(r, proj = T) == wgs84)
debug: if (mask_tif) r <- terra::mask(r, sf_zones)
debug: lyrs <- glue("{var}|{terra::time(r)}")
debug: if (length(dims_other) > 0 && !all(length(dims[dims_other]) == 
    1)) stop(glue("Other dimensions not yet supported: {paste(dims_other, collapse = ',')}"))
debug: names(r) <- lyrs
debug: if (!is.null(rast_tif)) {
    if (fs::file_exists(rast_tif)) {
        r_tmp_tif <- tempfile(fileext = ".tif")
        r_tmp <- c(rast(rast_tif), r)
        r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
        terra::writeRaster(r_tmp, r_tmp_tif)
        fs::file_delete(rast_tif)
        fs::file_move(r_tmp_tif, rast_tif)
        rm(r)
        rm(r_tmp)
    }
    else {
        terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
    }
    r <- terra::rast(rast_tif)
}
debug: if (fs::file_exists(rast_tif)) {
    r_tmp_tif <- tempfile(fileext = ".tif")
    r_tmp <- c(rast(rast_tif), r)
    r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
    terra::writeRaster(r_tmp, r_tmp_tif)
    fs::file_delete(rast_tif)
    fs::file_move(r_tmp_tif, rast_tif)
    rm(r)
    rm(r_tmp)
} else {
    terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
}
debug: terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
debug: r <- terra::rast(rast_tif)
debug: d_r <- mutate(tidyr::pivot_longer(sf::st_drop_geometry(sf::st_as_sf(terra::zonal(x = r, 
    z = terra::vect(dplyr::select(sf_zones, dplyr::all_of(fld_zones))), 
    fun = zonal_fun, exact = T, na.rm = T, as.polygons = T))), 
    cols = -dplyr::any_of(fld_zones), names_to = "lyr", values_to = zonal_fun), 
    time = readr::parse_datetime(str_replace(lyr, glue("{var}\\|(.*)"), 
        "\\1")))
debug: if (!is.null(zonal_csv)) write_csv(d_r, zonal_csv)
debug: write_csv(d_r, zonal_csv)
debug: if (!keep_nc) unlink(dir_nc, recursive = T)
debug: unlink(dir_nc, recursive = T)
debug: return(d_r)
Downloading 1 requests, up to 641 time slices each
Called from: extractr::ed_extract(ed, var = v, sf_zones = ply, bbox = bb, 
    mask_tif = F, rast_tif = glue("{dir_out}/{nms}/{yr}.tif"), 
    zonal_fun = "mean", zonal_csv = glue("{dir_out}/{nms}/{yr}.csv"), 
    dir_nc = glue("{dir_out}/{nms}/{yr}_nc"), keep_nc = F, n_max_vals_per_req = 1e+05, 
    time_min = time_min, time_max = time_max, verbose = T)
debug: while (i_req <= n_reqs) {
    i_t_beg <- (i_req - 1) * n_t_per_req + 1
    i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
    t_req <- times_todo[c(i_t_beg, i_t_end)]
    t_req_str <- format_ISO8601(t_req, usetz = "Z")
    if (verbose) 
        message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
    ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
        ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
        0), nc)
    unlink(ncs0)
    nc_retry <- T
    nc_n_try <- 1
    n_max_retries
    while (nc_retry) {
        res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
            url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
                bbox[["xmax"]]), latitude = c(bbox[["ymin"]], 
                bbox[["ymax"]]), time = t_req_str, fmt = "nc", 
            store = rerddap::disk(path = dir_nc)))
        if (inherits(res, "try-error")) {
            err <- attr(res, "condition")
            msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
            nc_n_try <- nc_n_try + 1
            if (nc_n_try > n_max_retries) {
                stop(msg)
            }
            else {
                message(msg, "\nRETRYing...")
                Sys.sleep(1)
            }
        }
        else {
            nc_retry <- F
        }
    }
    i_req <- i_req + 1
}
debug: i_t_beg <- (i_req - 1) * n_t_per_req + 1
debug: i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
debug: t_req <- times_todo[c(i_t_beg, i_t_end)]
debug: t_req_str <- format_ISO8601(t_req, usetz = "Z")
debug: if (verbose) message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
debug: message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
Fetching request 1 of 1 (2015-01-01 to 2015-12-01) ~ 19:40:55 UTC
debug: ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
    0), nc)
debug: unlink(ncs0)
debug: nc_retry <- T
debug: nc_n_try <- 1
debug: n_max_retries
debug: while (nc_retry) {
    res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
        url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
            bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
        time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
    if (inherits(res, "try-error")) {
        err <- attr(res, "condition")
        msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
        nc_n_try <- nc_n_try + 1
        if (nc_n_try > n_max_retries) {
            stop(msg)
        }
        else {
            message(msg, "\nRETRYing...")
            Sys.sleep(1)
        }
    }
    else {
        nc_retry <- F
    }
}
debug: res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
    url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
        bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
    time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
debug: if (inherits(res, "try-error")) {
    err <- attr(res, "condition")
    msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
    nc_n_try <- nc_n_try + 1
    if (nc_n_try > n_max_retries) {
        stop(msg)
    }
    else {
        message(msg, "\nRETRYing...")
        Sys.sleep(1)
    }
} else {
    nc_retry <- F
}
debug: nc_retry <- F
debug: (while) nc_retry
debug: i_req <- i_req + 1
debug: (while) i_req <= n_reqs
debug: ncs <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size > 
    0), nc)
debug: r <- terra::rast(ncs)
debug: stopifnot(all(class(terra::time(r)) %in% c("POSIXct", "POSIXt")))
debug: idx <- dplyr::pull(dplyr::filter(dplyr::arrange(dplyr::tibble(idx = 1:terra::nlyr(r), 
    time = terra::time(r)), time), !duplicated(time)), idx)
debug: r <- terra::subset(r, idx)
debug: stopifnot(terra::crs(r, proj = T) == wgs84)
debug: if (mask_tif) r <- terra::mask(r, sf_zones)
debug: lyrs <- glue("{var}|{terra::time(r)}")
debug: if (length(dims_other) > 0 && !all(length(dims[dims_other]) == 
    1)) stop(glue("Other dimensions not yet supported: {paste(dims_other, collapse = ',')}"))
debug: names(r) <- lyrs
debug: if (!is.null(rast_tif)) {
    if (fs::file_exists(rast_tif)) {
        r_tmp_tif <- tempfile(fileext = ".tif")
        r_tmp <- c(rast(rast_tif), r)
        r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
        terra::writeRaster(r_tmp, r_tmp_tif)
        fs::file_delete(rast_tif)
        fs::file_move(r_tmp_tif, rast_tif)
        rm(r)
        rm(r_tmp)
    }
    else {
        terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
    }
    r <- terra::rast(rast_tif)
}
debug: if (fs::file_exists(rast_tif)) {
    r_tmp_tif <- tempfile(fileext = ".tif")
    r_tmp <- c(rast(rast_tif), r)
    r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
    terra::writeRaster(r_tmp, r_tmp_tif)
    fs::file_delete(rast_tif)
    fs::file_move(r_tmp_tif, rast_tif)
    rm(r)
    rm(r_tmp)
} else {
    terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
}
debug: terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
debug: r <- terra::rast(rast_tif)
debug: d_r <- mutate(tidyr::pivot_longer(sf::st_drop_geometry(sf::st_as_sf(terra::zonal(x = r, 
    z = terra::vect(dplyr::select(sf_zones, dplyr::all_of(fld_zones))), 
    fun = zonal_fun, exact = T, na.rm = T, as.polygons = T))), 
    cols = -dplyr::any_of(fld_zones), names_to = "lyr", values_to = zonal_fun), 
    time = readr::parse_datetime(str_replace(lyr, glue("{var}\\|(.*)"), 
        "\\1")))
debug: if (!is.null(zonal_csv)) write_csv(d_r, zonal_csv)
debug: write_csv(d_r, zonal_csv)
debug: if (!keep_nc) unlink(dir_nc, recursive = T)
debug: unlink(dir_nc, recursive = T)
debug: return(d_r)
Downloading 1 requests, up to 641 time slices each
Called from: extractr::ed_extract(ed, var = v, sf_zones = ply, bbox = bb, 
    mask_tif = F, rast_tif = glue("{dir_out}/{nms}/{yr}.tif"), 
    zonal_fun = "mean", zonal_csv = glue("{dir_out}/{nms}/{yr}.csv"), 
    dir_nc = glue("{dir_out}/{nms}/{yr}_nc"), keep_nc = F, n_max_vals_per_req = 1e+05, 
    time_min = time_min, time_max = time_max, verbose = T)
debug: while (i_req <= n_reqs) {
    i_t_beg <- (i_req - 1) * n_t_per_req + 1
    i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
    t_req <- times_todo[c(i_t_beg, i_t_end)]
    t_req_str <- format_ISO8601(t_req, usetz = "Z")
    if (verbose) 
        message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
    ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
        ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
        0), nc)
    unlink(ncs0)
    nc_retry <- T
    nc_n_try <- 1
    n_max_retries
    while (nc_retry) {
        res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
            url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
                bbox[["xmax"]]), latitude = c(bbox[["ymin"]], 
                bbox[["ymax"]]), time = t_req_str, fmt = "nc", 
            store = rerddap::disk(path = dir_nc)))
        if (inherits(res, "try-error")) {
            err <- attr(res, "condition")
            msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
            nc_n_try <- nc_n_try + 1
            if (nc_n_try > n_max_retries) {
                stop(msg)
            }
            else {
                message(msg, "\nRETRYing...")
                Sys.sleep(1)
            }
        }
        else {
            nc_retry <- F
        }
    }
    i_req <- i_req + 1
}
debug: i_t_beg <- (i_req - 1) * n_t_per_req + 1
debug: i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
debug: t_req <- times_todo[c(i_t_beg, i_t_end)]
debug: t_req_str <- format_ISO8601(t_req, usetz = "Z")
debug: if (verbose) message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
debug: message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
Fetching request 1 of 1 (2016-01-01 to 2016-12-01) ~ 19:40:57 UTC
debug: ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
    0), nc)
debug: unlink(ncs0)
debug: nc_retry <- T
debug: nc_n_try <- 1
debug: n_max_retries
debug: while (nc_retry) {
    res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
        url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
            bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
        time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
    if (inherits(res, "try-error")) {
        err <- attr(res, "condition")
        msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
        nc_n_try <- nc_n_try + 1
        if (nc_n_try > n_max_retries) {
            stop(msg)
        }
        else {
            message(msg, "\nRETRYing...")
            Sys.sleep(1)
        }
    }
    else {
        nc_retry <- F
    }
}
debug: res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
    url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
        bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
    time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
debug: if (inherits(res, "try-error")) {
    err <- attr(res, "condition")
    msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
    nc_n_try <- nc_n_try + 1
    if (nc_n_try > n_max_retries) {
        stop(msg)
    }
    else {
        message(msg, "\nRETRYing...")
        Sys.sleep(1)
    }
} else {
    nc_retry <- F
}
debug: nc_retry <- F
debug: (while) nc_retry
debug: i_req <- i_req + 1
debug: (while) i_req <= n_reqs
debug: ncs <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size > 
    0), nc)
debug: r <- terra::rast(ncs)
debug: stopifnot(all(class(terra::time(r)) %in% c("POSIXct", "POSIXt")))
debug: idx <- dplyr::pull(dplyr::filter(dplyr::arrange(dplyr::tibble(idx = 1:terra::nlyr(r), 
    time = terra::time(r)), time), !duplicated(time)), idx)
debug: r <- terra::subset(r, idx)
debug: stopifnot(terra::crs(r, proj = T) == wgs84)
debug: if (mask_tif) r <- terra::mask(r, sf_zones)
debug: lyrs <- glue("{var}|{terra::time(r)}")
debug: if (length(dims_other) > 0 && !all(length(dims[dims_other]) == 
    1)) stop(glue("Other dimensions not yet supported: {paste(dims_other, collapse = ',')}"))
debug: names(r) <- lyrs
debug: if (!is.null(rast_tif)) {
    if (fs::file_exists(rast_tif)) {
        r_tmp_tif <- tempfile(fileext = ".tif")
        r_tmp <- c(rast(rast_tif), r)
        r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
        terra::writeRaster(r_tmp, r_tmp_tif)
        fs::file_delete(rast_tif)
        fs::file_move(r_tmp_tif, rast_tif)
        rm(r)
        rm(r_tmp)
    }
    else {
        terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
    }
    r <- terra::rast(rast_tif)
}
debug: if (fs::file_exists(rast_tif)) {
    r_tmp_tif <- tempfile(fileext = ".tif")
    r_tmp <- c(rast(rast_tif), r)
    r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
    terra::writeRaster(r_tmp, r_tmp_tif)
    fs::file_delete(rast_tif)
    fs::file_move(r_tmp_tif, rast_tif)
    rm(r)
    rm(r_tmp)
} else {
    terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
}
debug: terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
debug: r <- terra::rast(rast_tif)
debug: d_r <- mutate(tidyr::pivot_longer(sf::st_drop_geometry(sf::st_as_sf(terra::zonal(x = r, 
    z = terra::vect(dplyr::select(sf_zones, dplyr::all_of(fld_zones))), 
    fun = zonal_fun, exact = T, na.rm = T, as.polygons = T))), 
    cols = -dplyr::any_of(fld_zones), names_to = "lyr", values_to = zonal_fun), 
    time = readr::parse_datetime(str_replace(lyr, glue("{var}\\|(.*)"), 
        "\\1")))
debug: if (!is.null(zonal_csv)) write_csv(d_r, zonal_csv)
debug: write_csv(d_r, zonal_csv)
debug: if (!keep_nc) unlink(dir_nc, recursive = T)
debug: unlink(dir_nc, recursive = T)
debug: return(d_r)
Downloading 1 requests, up to 641 time slices each
Called from: extractr::ed_extract(ed, var = v, sf_zones = ply, bbox = bb, 
    mask_tif = F, rast_tif = glue("{dir_out}/{nms}/{yr}.tif"), 
    zonal_fun = "mean", zonal_csv = glue("{dir_out}/{nms}/{yr}.csv"), 
    dir_nc = glue("{dir_out}/{nms}/{yr}_nc"), keep_nc = F, n_max_vals_per_req = 1e+05, 
    time_min = time_min, time_max = time_max, verbose = T)
debug: while (i_req <= n_reqs) {
    i_t_beg <- (i_req - 1) * n_t_per_req + 1
    i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
    t_req <- times_todo[c(i_t_beg, i_t_end)]
    t_req_str <- format_ISO8601(t_req, usetz = "Z")
    if (verbose) 
        message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
    ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
        ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
        0), nc)
    unlink(ncs0)
    nc_retry <- T
    nc_n_try <- 1
    n_max_retries
    while (nc_retry) {
        res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
            url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
                bbox[["xmax"]]), latitude = c(bbox[["ymin"]], 
                bbox[["ymax"]]), time = t_req_str, fmt = "nc", 
            store = rerddap::disk(path = dir_nc)))
        if (inherits(res, "try-error")) {
            err <- attr(res, "condition")
            msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
            nc_n_try <- nc_n_try + 1
            if (nc_n_try > n_max_retries) {
                stop(msg)
            }
            else {
                message(msg, "\nRETRYing...")
                Sys.sleep(1)
            }
        }
        else {
            nc_retry <- F
        }
    }
    i_req <- i_req + 1
}
debug: i_t_beg <- (i_req - 1) * n_t_per_req + 1
debug: i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
debug: t_req <- times_todo[c(i_t_beg, i_t_end)]
debug: t_req_str <- format_ISO8601(t_req, usetz = "Z")
debug: if (verbose) message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
debug: message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
Fetching request 1 of 1 (2017-01-01 to 2017-12-01) ~ 19:40:58 UTC
debug: ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
    0), nc)
debug: unlink(ncs0)
debug: nc_retry <- T
debug: nc_n_try <- 1
debug: n_max_retries
debug: while (nc_retry) {
    res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
        url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
            bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
        time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
    if (inherits(res, "try-error")) {
        err <- attr(res, "condition")
        msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
        nc_n_try <- nc_n_try + 1
        if (nc_n_try > n_max_retries) {
            stop(msg)
        }
        else {
            message(msg, "\nRETRYing...")
            Sys.sleep(1)
        }
    }
    else {
        nc_retry <- F
    }
}
debug: res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
    url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
        bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
    time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
debug: if (inherits(res, "try-error")) {
    err <- attr(res, "condition")
    msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
    nc_n_try <- nc_n_try + 1
    if (nc_n_try > n_max_retries) {
        stop(msg)
    }
    else {
        message(msg, "\nRETRYing...")
        Sys.sleep(1)
    }
} else {
    nc_retry <- F
}
debug: nc_retry <- F
debug: (while) nc_retry
debug: i_req <- i_req + 1
debug: (while) i_req <= n_reqs
debug: ncs <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size > 
    0), nc)
debug: r <- terra::rast(ncs)
debug: stopifnot(all(class(terra::time(r)) %in% c("POSIXct", "POSIXt")))
debug: idx <- dplyr::pull(dplyr::filter(dplyr::arrange(dplyr::tibble(idx = 1:terra::nlyr(r), 
    time = terra::time(r)), time), !duplicated(time)), idx)
debug: r <- terra::subset(r, idx)
debug: stopifnot(terra::crs(r, proj = T) == wgs84)
debug: if (mask_tif) r <- terra::mask(r, sf_zones)
debug: lyrs <- glue("{var}|{terra::time(r)}")
debug: if (length(dims_other) > 0 && !all(length(dims[dims_other]) == 
    1)) stop(glue("Other dimensions not yet supported: {paste(dims_other, collapse = ',')}"))
debug: names(r) <- lyrs
debug: if (!is.null(rast_tif)) {
    if (fs::file_exists(rast_tif)) {
        r_tmp_tif <- tempfile(fileext = ".tif")
        r_tmp <- c(rast(rast_tif), r)
        r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
        terra::writeRaster(r_tmp, r_tmp_tif)
        fs::file_delete(rast_tif)
        fs::file_move(r_tmp_tif, rast_tif)
        rm(r)
        rm(r_tmp)
    }
    else {
        terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
    }
    r <- terra::rast(rast_tif)
}
debug: if (fs::file_exists(rast_tif)) {
    r_tmp_tif <- tempfile(fileext = ".tif")
    r_tmp <- c(rast(rast_tif), r)
    r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
    terra::writeRaster(r_tmp, r_tmp_tif)
    fs::file_delete(rast_tif)
    fs::file_move(r_tmp_tif, rast_tif)
    rm(r)
    rm(r_tmp)
} else {
    terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
}
debug: terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
debug: r <- terra::rast(rast_tif)
debug: d_r <- mutate(tidyr::pivot_longer(sf::st_drop_geometry(sf::st_as_sf(terra::zonal(x = r, 
    z = terra::vect(dplyr::select(sf_zones, dplyr::all_of(fld_zones))), 
    fun = zonal_fun, exact = T, na.rm = T, as.polygons = T))), 
    cols = -dplyr::any_of(fld_zones), names_to = "lyr", values_to = zonal_fun), 
    time = readr::parse_datetime(str_replace(lyr, glue("{var}\\|(.*)"), 
        "\\1")))
debug: if (!is.null(zonal_csv)) write_csv(d_r, zonal_csv)
debug: write_csv(d_r, zonal_csv)
debug: if (!keep_nc) unlink(dir_nc, recursive = T)
debug: unlink(dir_nc, recursive = T)
debug: return(d_r)
Downloading 1 requests, up to 641 time slices each
Called from: extractr::ed_extract(ed, var = v, sf_zones = ply, bbox = bb, 
    mask_tif = F, rast_tif = glue("{dir_out}/{nms}/{yr}.tif"), 
    zonal_fun = "mean", zonal_csv = glue("{dir_out}/{nms}/{yr}.csv"), 
    dir_nc = glue("{dir_out}/{nms}/{yr}_nc"), keep_nc = F, n_max_vals_per_req = 1e+05, 
    time_min = time_min, time_max = time_max, verbose = T)
debug: while (i_req <= n_reqs) {
    i_t_beg <- (i_req - 1) * n_t_per_req + 1
    i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
    t_req <- times_todo[c(i_t_beg, i_t_end)]
    t_req_str <- format_ISO8601(t_req, usetz = "Z")
    if (verbose) 
        message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
    ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
        ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
        0), nc)
    unlink(ncs0)
    nc_retry <- T
    nc_n_try <- 1
    n_max_retries
    while (nc_retry) {
        res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
            url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
                bbox[["xmax"]]), latitude = c(bbox[["ymin"]], 
                bbox[["ymax"]]), time = t_req_str, fmt = "nc", 
            store = rerddap::disk(path = dir_nc)))
        if (inherits(res, "try-error")) {
            err <- attr(res, "condition")
            msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
            nc_n_try <- nc_n_try + 1
            if (nc_n_try > n_max_retries) {
                stop(msg)
            }
            else {
                message(msg, "\nRETRYing...")
                Sys.sleep(1)
            }
        }
        else {
            nc_retry <- F
        }
    }
    i_req <- i_req + 1
}
debug: i_t_beg <- (i_req - 1) * n_t_per_req + 1
debug: i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
debug: t_req <- times_todo[c(i_t_beg, i_t_end)]
debug: t_req_str <- format_ISO8601(t_req, usetz = "Z")
debug: if (verbose) message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
debug: message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
Fetching request 1 of 1 (2018-01-01 to 2018-12-01) ~ 19:41:00 UTC
debug: ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
    0), nc)
debug: unlink(ncs0)
debug: nc_retry <- T
debug: nc_n_try <- 1
debug: n_max_retries
debug: while (nc_retry) {
    res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
        url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
            bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
        time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
    if (inherits(res, "try-error")) {
        err <- attr(res, "condition")
        msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
        nc_n_try <- nc_n_try + 1
        if (nc_n_try > n_max_retries) {
            stop(msg)
        }
        else {
            message(msg, "\nRETRYing...")
            Sys.sleep(1)
        }
    }
    else {
        nc_retry <- F
    }
}
debug: res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
    url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
        bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
    time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
debug: if (inherits(res, "try-error")) {
    err <- attr(res, "condition")
    msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
    nc_n_try <- nc_n_try + 1
    if (nc_n_try > n_max_retries) {
        stop(msg)
    }
    else {
        message(msg, "\nRETRYing...")
        Sys.sleep(1)
    }
} else {
    nc_retry <- F
}
debug: nc_retry <- F
debug: (while) nc_retry
debug: i_req <- i_req + 1
debug: (while) i_req <= n_reqs
debug: ncs <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size > 
    0), nc)
debug: r <- terra::rast(ncs)
debug: stopifnot(all(class(terra::time(r)) %in% c("POSIXct", "POSIXt")))
debug: idx <- dplyr::pull(dplyr::filter(dplyr::arrange(dplyr::tibble(idx = 1:terra::nlyr(r), 
    time = terra::time(r)), time), !duplicated(time)), idx)
debug: r <- terra::subset(r, idx)
debug: stopifnot(terra::crs(r, proj = T) == wgs84)
debug: if (mask_tif) r <- terra::mask(r, sf_zones)
debug: lyrs <- glue("{var}|{terra::time(r)}")
debug: if (length(dims_other) > 0 && !all(length(dims[dims_other]) == 
    1)) stop(glue("Other dimensions not yet supported: {paste(dims_other, collapse = ',')}"))
debug: names(r) <- lyrs
debug: if (!is.null(rast_tif)) {
    if (fs::file_exists(rast_tif)) {
        r_tmp_tif <- tempfile(fileext = ".tif")
        r_tmp <- c(rast(rast_tif), r)
        r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
        terra::writeRaster(r_tmp, r_tmp_tif)
        fs::file_delete(rast_tif)
        fs::file_move(r_tmp_tif, rast_tif)
        rm(r)
        rm(r_tmp)
    }
    else {
        terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
    }
    r <- terra::rast(rast_tif)
}
debug: if (fs::file_exists(rast_tif)) {
    r_tmp_tif <- tempfile(fileext = ".tif")
    r_tmp <- c(rast(rast_tif), r)
    r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
    terra::writeRaster(r_tmp, r_tmp_tif)
    fs::file_delete(rast_tif)
    fs::file_move(r_tmp_tif, rast_tif)
    rm(r)
    rm(r_tmp)
} else {
    terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
}
debug: terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
debug: r <- terra::rast(rast_tif)
debug: d_r <- mutate(tidyr::pivot_longer(sf::st_drop_geometry(sf::st_as_sf(terra::zonal(x = r, 
    z = terra::vect(dplyr::select(sf_zones, dplyr::all_of(fld_zones))), 
    fun = zonal_fun, exact = T, na.rm = T, as.polygons = T))), 
    cols = -dplyr::any_of(fld_zones), names_to = "lyr", values_to = zonal_fun), 
    time = readr::parse_datetime(str_replace(lyr, glue("{var}\\|(.*)"), 
        "\\1")))
debug: if (!is.null(zonal_csv)) write_csv(d_r, zonal_csv)
debug: write_csv(d_r, zonal_csv)
debug: if (!keep_nc) unlink(dir_nc, recursive = T)
debug: unlink(dir_nc, recursive = T)
debug: return(d_r)
Downloading 1 requests, up to 641 time slices each
Called from: extractr::ed_extract(ed, var = v, sf_zones = ply, bbox = bb, 
    mask_tif = F, rast_tif = glue("{dir_out}/{nms}/{yr}.tif"), 
    zonal_fun = "mean", zonal_csv = glue("{dir_out}/{nms}/{yr}.csv"), 
    dir_nc = glue("{dir_out}/{nms}/{yr}_nc"), keep_nc = F, n_max_vals_per_req = 1e+05, 
    time_min = time_min, time_max = time_max, verbose = T)
debug: while (i_req <= n_reqs) {
    i_t_beg <- (i_req - 1) * n_t_per_req + 1
    i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
    t_req <- times_todo[c(i_t_beg, i_t_end)]
    t_req_str <- format_ISO8601(t_req, usetz = "Z")
    if (verbose) 
        message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
    ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
        ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
        0), nc)
    unlink(ncs0)
    nc_retry <- T
    nc_n_try <- 1
    n_max_retries
    while (nc_retry) {
        res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
            url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
                bbox[["xmax"]]), latitude = c(bbox[["ymin"]], 
                bbox[["ymax"]]), time = t_req_str, fmt = "nc", 
            store = rerddap::disk(path = dir_nc)))
        if (inherits(res, "try-error")) {
            err <- attr(res, "condition")
            msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
            nc_n_try <- nc_n_try + 1
            if (nc_n_try > n_max_retries) {
                stop(msg)
            }
            else {
                message(msg, "\nRETRYing...")
                Sys.sleep(1)
            }
        }
        else {
            nc_retry <- F
        }
    }
    i_req <- i_req + 1
}
debug: i_t_beg <- (i_req - 1) * n_t_per_req + 1
debug: i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
debug: t_req <- times_todo[c(i_t_beg, i_t_end)]
debug: t_req_str <- format_ISO8601(t_req, usetz = "Z")
debug: if (verbose) message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
debug: message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
Fetching request 1 of 1 (2019-01-01 to 2019-12-01) ~ 19:41:02 UTC
debug: ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
    0), nc)
debug: unlink(ncs0)
debug: nc_retry <- T
debug: nc_n_try <- 1
debug: n_max_retries
debug: while (nc_retry) {
    res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
        url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
            bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
        time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
    if (inherits(res, "try-error")) {
        err <- attr(res, "condition")
        msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
        nc_n_try <- nc_n_try + 1
        if (nc_n_try > n_max_retries) {
            stop(msg)
        }
        else {
            message(msg, "\nRETRYing...")
            Sys.sleep(1)
        }
    }
    else {
        nc_retry <- F
    }
}
debug: res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
    url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
        bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
    time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
debug: if (inherits(res, "try-error")) {
    err <- attr(res, "condition")
    msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
    nc_n_try <- nc_n_try + 1
    if (nc_n_try > n_max_retries) {
        stop(msg)
    }
    else {
        message(msg, "\nRETRYing...")
        Sys.sleep(1)
    }
} else {
    nc_retry <- F
}
debug: nc_retry <- F
debug: (while) nc_retry
debug: i_req <- i_req + 1
debug: (while) i_req <= n_reqs
debug: ncs <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size > 
    0), nc)
debug: r <- terra::rast(ncs)
debug: stopifnot(all(class(terra::time(r)) %in% c("POSIXct", "POSIXt")))
debug: idx <- dplyr::pull(dplyr::filter(dplyr::arrange(dplyr::tibble(idx = 1:terra::nlyr(r), 
    time = terra::time(r)), time), !duplicated(time)), idx)
debug: r <- terra::subset(r, idx)
debug: stopifnot(terra::crs(r, proj = T) == wgs84)
debug: if (mask_tif) r <- terra::mask(r, sf_zones)
debug: lyrs <- glue("{var}|{terra::time(r)}")
debug: if (length(dims_other) > 0 && !all(length(dims[dims_other]) == 
    1)) stop(glue("Other dimensions not yet supported: {paste(dims_other, collapse = ',')}"))
debug: names(r) <- lyrs
debug: if (!is.null(rast_tif)) {
    if (fs::file_exists(rast_tif)) {
        r_tmp_tif <- tempfile(fileext = ".tif")
        r_tmp <- c(rast(rast_tif), r)
        r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
        terra::writeRaster(r_tmp, r_tmp_tif)
        fs::file_delete(rast_tif)
        fs::file_move(r_tmp_tif, rast_tif)
        rm(r)
        rm(r_tmp)
    }
    else {
        terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
    }
    r <- terra::rast(rast_tif)
}
debug: if (fs::file_exists(rast_tif)) {
    r_tmp_tif <- tempfile(fileext = ".tif")
    r_tmp <- c(rast(rast_tif), r)
    r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
    terra::writeRaster(r_tmp, r_tmp_tif)
    fs::file_delete(rast_tif)
    fs::file_move(r_tmp_tif, rast_tif)
    rm(r)
    rm(r_tmp)
} else {
    terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
}
debug: terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
debug: r <- terra::rast(rast_tif)
debug: d_r <- mutate(tidyr::pivot_longer(sf::st_drop_geometry(sf::st_as_sf(terra::zonal(x = r, 
    z = terra::vect(dplyr::select(sf_zones, dplyr::all_of(fld_zones))), 
    fun = zonal_fun, exact = T, na.rm = T, as.polygons = T))), 
    cols = -dplyr::any_of(fld_zones), names_to = "lyr", values_to = zonal_fun), 
    time = readr::parse_datetime(str_replace(lyr, glue("{var}\\|(.*)"), 
        "\\1")))
debug: if (!is.null(zonal_csv)) write_csv(d_r, zonal_csv)
debug: write_csv(d_r, zonal_csv)
debug: if (!keep_nc) unlink(dir_nc, recursive = T)
debug: unlink(dir_nc, recursive = T)
debug: return(d_r)
Downloading 1 requests, up to 641 time slices each
Called from: extractr::ed_extract(ed, var = v, sf_zones = ply, bbox = bb, 
    mask_tif = F, rast_tif = glue("{dir_out}/{nms}/{yr}.tif"), 
    zonal_fun = "mean", zonal_csv = glue("{dir_out}/{nms}/{yr}.csv"), 
    dir_nc = glue("{dir_out}/{nms}/{yr}_nc"), keep_nc = F, n_max_vals_per_req = 1e+05, 
    time_min = time_min, time_max = time_max, verbose = T)
debug: while (i_req <= n_reqs) {
    i_t_beg <- (i_req - 1) * n_t_per_req + 1
    i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
    t_req <- times_todo[c(i_t_beg, i_t_end)]
    t_req_str <- format_ISO8601(t_req, usetz = "Z")
    if (verbose) 
        message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
    ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
        ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
        0), nc)
    unlink(ncs0)
    nc_retry <- T
    nc_n_try <- 1
    n_max_retries
    while (nc_retry) {
        res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
            url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
                bbox[["xmax"]]), latitude = c(bbox[["ymin"]], 
                bbox[["ymax"]]), time = t_req_str, fmt = "nc", 
            store = rerddap::disk(path = dir_nc)))
        if (inherits(res, "try-error")) {
            err <- attr(res, "condition")
            msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
            nc_n_try <- nc_n_try + 1
            if (nc_n_try > n_max_retries) {
                stop(msg)
            }
            else {
                message(msg, "\nRETRYing...")
                Sys.sleep(1)
            }
        }
        else {
            nc_retry <- F
        }
    }
    i_req <- i_req + 1
}
debug: i_t_beg <- (i_req - 1) * n_t_per_req + 1
debug: i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
debug: t_req <- times_todo[c(i_t_beg, i_t_end)]
debug: t_req_str <- format_ISO8601(t_req, usetz = "Z")
debug: if (verbose) message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
debug: message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
Fetching request 1 of 1 (2020-01-01 to 2020-12-01) ~ 19:41:03 UTC
debug: ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
    0), nc)
debug: unlink(ncs0)
debug: nc_retry <- T
debug: nc_n_try <- 1
debug: n_max_retries
debug: while (nc_retry) {
    res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
        url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
            bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
        time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
    if (inherits(res, "try-error")) {
        err <- attr(res, "condition")
        msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
        nc_n_try <- nc_n_try + 1
        if (nc_n_try > n_max_retries) {
            stop(msg)
        }
        else {
            message(msg, "\nRETRYing...")
            Sys.sleep(1)
        }
    }
    else {
        nc_retry <- F
    }
}
debug: res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
    url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
        bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
    time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
debug: if (inherits(res, "try-error")) {
    err <- attr(res, "condition")
    msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
    nc_n_try <- nc_n_try + 1
    if (nc_n_try > n_max_retries) {
        stop(msg)
    }
    else {
        message(msg, "\nRETRYing...")
        Sys.sleep(1)
    }
} else {
    nc_retry <- F
}
debug: nc_retry <- F
debug: (while) nc_retry
debug: i_req <- i_req + 1
debug: (while) i_req <= n_reqs
debug: ncs <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size > 
    0), nc)
debug: r <- terra::rast(ncs)
debug: stopifnot(all(class(terra::time(r)) %in% c("POSIXct", "POSIXt")))
debug: idx <- dplyr::pull(dplyr::filter(dplyr::arrange(dplyr::tibble(idx = 1:terra::nlyr(r), 
    time = terra::time(r)), time), !duplicated(time)), idx)
debug: r <- terra::subset(r, idx)
debug: stopifnot(terra::crs(r, proj = T) == wgs84)
debug: if (mask_tif) r <- terra::mask(r, sf_zones)
debug: lyrs <- glue("{var}|{terra::time(r)}")
debug: if (length(dims_other) > 0 && !all(length(dims[dims_other]) == 
    1)) stop(glue("Other dimensions not yet supported: {paste(dims_other, collapse = ',')}"))
debug: names(r) <- lyrs
debug: if (!is.null(rast_tif)) {
    if (fs::file_exists(rast_tif)) {
        r_tmp_tif <- tempfile(fileext = ".tif")
        r_tmp <- c(rast(rast_tif), r)
        r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
        terra::writeRaster(r_tmp, r_tmp_tif)
        fs::file_delete(rast_tif)
        fs::file_move(r_tmp_tif, rast_tif)
        rm(r)
        rm(r_tmp)
    }
    else {
        terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
    }
    r <- terra::rast(rast_tif)
}
debug: if (fs::file_exists(rast_tif)) {
    r_tmp_tif <- tempfile(fileext = ".tif")
    r_tmp <- c(rast(rast_tif), r)
    r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
    terra::writeRaster(r_tmp, r_tmp_tif)
    fs::file_delete(rast_tif)
    fs::file_move(r_tmp_tif, rast_tif)
    rm(r)
    rm(r_tmp)
} else {
    terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
}
debug: terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
debug: r <- terra::rast(rast_tif)
debug: d_r <- mutate(tidyr::pivot_longer(sf::st_drop_geometry(sf::st_as_sf(terra::zonal(x = r, 
    z = terra::vect(dplyr::select(sf_zones, dplyr::all_of(fld_zones))), 
    fun = zonal_fun, exact = T, na.rm = T, as.polygons = T))), 
    cols = -dplyr::any_of(fld_zones), names_to = "lyr", values_to = zonal_fun), 
    time = readr::parse_datetime(str_replace(lyr, glue("{var}\\|(.*)"), 
        "\\1")))
debug: if (!is.null(zonal_csv)) write_csv(d_r, zonal_csv)
debug: write_csv(d_r, zonal_csv)
debug: if (!keep_nc) unlink(dir_nc, recursive = T)
debug: unlink(dir_nc, recursive = T)
debug: return(d_r)
Downloading 1 requests, up to 641 time slices each
Called from: extractr::ed_extract(ed, var = v, sf_zones = ply, bbox = bb, 
    mask_tif = F, rast_tif = glue("{dir_out}/{nms}/{yr}.tif"), 
    zonal_fun = "mean", zonal_csv = glue("{dir_out}/{nms}/{yr}.csv"), 
    dir_nc = glue("{dir_out}/{nms}/{yr}_nc"), keep_nc = F, n_max_vals_per_req = 1e+05, 
    time_min = time_min, time_max = time_max, verbose = T)
debug: while (i_req <= n_reqs) {
    i_t_beg <- (i_req - 1) * n_t_per_req + 1
    i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
    t_req <- times_todo[c(i_t_beg, i_t_end)]
    t_req_str <- format_ISO8601(t_req, usetz = "Z")
    if (verbose) 
        message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
    ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
        ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
        0), nc)
    unlink(ncs0)
    nc_retry <- T
    nc_n_try <- 1
    n_max_retries
    while (nc_retry) {
        res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
            url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
                bbox[["xmax"]]), latitude = c(bbox[["ymin"]], 
                bbox[["ymax"]]), time = t_req_str, fmt = "nc", 
            store = rerddap::disk(path = dir_nc)))
        if (inherits(res, "try-error")) {
            err <- attr(res, "condition")
            msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
            nc_n_try <- nc_n_try + 1
            if (nc_n_try > n_max_retries) {
                stop(msg)
            }
            else {
                message(msg, "\nRETRYing...")
                Sys.sleep(1)
            }
        }
        else {
            nc_retry <- F
        }
    }
    i_req <- i_req + 1
}
debug: i_t_beg <- (i_req - 1) * n_t_per_req + 1
debug: i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
debug: t_req <- times_todo[c(i_t_beg, i_t_end)]
debug: t_req_str <- format_ISO8601(t_req, usetz = "Z")
debug: if (verbose) message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
debug: message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
Fetching request 1 of 1 (2021-01-01 to 2021-12-01) ~ 19:41:06 UTC
debug: ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
    0), nc)
debug: unlink(ncs0)
debug: nc_retry <- T
debug: nc_n_try <- 1
debug: n_max_retries
debug: while (nc_retry) {
    res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
        url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
            bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
        time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
    if (inherits(res, "try-error")) {
        err <- attr(res, "condition")
        msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
        nc_n_try <- nc_n_try + 1
        if (nc_n_try > n_max_retries) {
            stop(msg)
        }
        else {
            message(msg, "\nRETRYing...")
            Sys.sleep(1)
        }
    }
    else {
        nc_retry <- F
    }
}
debug: res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
    url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
        bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
    time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
debug: if (inherits(res, "try-error")) {
    err <- attr(res, "condition")
    msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
    nc_n_try <- nc_n_try + 1
    if (nc_n_try > n_max_retries) {
        stop(msg)
    }
    else {
        message(msg, "\nRETRYing...")
        Sys.sleep(1)
    }
} else {
    nc_retry <- F
}
debug: nc_retry <- F
debug: (while) nc_retry
debug: i_req <- i_req + 1
debug: (while) i_req <= n_reqs
debug: ncs <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size > 
    0), nc)
debug: r <- terra::rast(ncs)
debug: stopifnot(all(class(terra::time(r)) %in% c("POSIXct", "POSIXt")))
debug: idx <- dplyr::pull(dplyr::filter(dplyr::arrange(dplyr::tibble(idx = 1:terra::nlyr(r), 
    time = terra::time(r)), time), !duplicated(time)), idx)
debug: r <- terra::subset(r, idx)
debug: stopifnot(terra::crs(r, proj = T) == wgs84)
debug: if (mask_tif) r <- terra::mask(r, sf_zones)
debug: lyrs <- glue("{var}|{terra::time(r)}")
debug: if (length(dims_other) > 0 && !all(length(dims[dims_other]) == 
    1)) stop(glue("Other dimensions not yet supported: {paste(dims_other, collapse = ',')}"))
debug: names(r) <- lyrs
debug: if (!is.null(rast_tif)) {
    if (fs::file_exists(rast_tif)) {
        r_tmp_tif <- tempfile(fileext = ".tif")
        r_tmp <- c(rast(rast_tif), r)
        r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
        terra::writeRaster(r_tmp, r_tmp_tif)
        fs::file_delete(rast_tif)
        fs::file_move(r_tmp_tif, rast_tif)
        rm(r)
        rm(r_tmp)
    }
    else {
        terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
    }
    r <- terra::rast(rast_tif)
}
debug: if (fs::file_exists(rast_tif)) {
    r_tmp_tif <- tempfile(fileext = ".tif")
    r_tmp <- c(rast(rast_tif), r)
    r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
    terra::writeRaster(r_tmp, r_tmp_tif)
    fs::file_delete(rast_tif)
    fs::file_move(r_tmp_tif, rast_tif)
    rm(r)
    rm(r_tmp)
} else {
    terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
}
debug: terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
debug: r <- terra::rast(rast_tif)
debug: d_r <- mutate(tidyr::pivot_longer(sf::st_drop_geometry(sf::st_as_sf(terra::zonal(x = r, 
    z = terra::vect(dplyr::select(sf_zones, dplyr::all_of(fld_zones))), 
    fun = zonal_fun, exact = T, na.rm = T, as.polygons = T))), 
    cols = -dplyr::any_of(fld_zones), names_to = "lyr", values_to = zonal_fun), 
    time = readr::parse_datetime(str_replace(lyr, glue("{var}\\|(.*)"), 
        "\\1")))
debug: if (!is.null(zonal_csv)) write_csv(d_r, zonal_csv)
debug: write_csv(d_r, zonal_csv)
debug: if (!keep_nc) unlink(dir_nc, recursive = T)
debug: unlink(dir_nc, recursive = T)
debug: return(d_r)
Downloading 1 requests, up to 641 time slices each
Called from: extractr::ed_extract(ed, var = v, sf_zones = ply, bbox = bb, 
    mask_tif = F, rast_tif = glue("{dir_out}/{nms}/{yr}.tif"), 
    zonal_fun = "mean", zonal_csv = glue("{dir_out}/{nms}/{yr}.csv"), 
    dir_nc = glue("{dir_out}/{nms}/{yr}_nc"), keep_nc = F, n_max_vals_per_req = 1e+05, 
    time_min = time_min, time_max = time_max, verbose = T)
debug: while (i_req <= n_reqs) {
    i_t_beg <- (i_req - 1) * n_t_per_req + 1
    i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
    t_req <- times_todo[c(i_t_beg, i_t_end)]
    t_req_str <- format_ISO8601(t_req, usetz = "Z")
    if (verbose) 
        message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
    ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
        ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
        0), nc)
    unlink(ncs0)
    nc_retry <- T
    nc_n_try <- 1
    n_max_retries
    while (nc_retry) {
        res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
            url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
                bbox[["xmax"]]), latitude = c(bbox[["ymin"]], 
                bbox[["ymax"]]), time = t_req_str, fmt = "nc", 
            store = rerddap::disk(path = dir_nc)))
        if (inherits(res, "try-error")) {
            err <- attr(res, "condition")
            msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
            nc_n_try <- nc_n_try + 1
            if (nc_n_try > n_max_retries) {
                stop(msg)
            }
            else {
                message(msg, "\nRETRYing...")
                Sys.sleep(1)
            }
        }
        else {
            nc_retry <- F
        }
    }
    i_req <- i_req + 1
}
debug: i_t_beg <- (i_req - 1) * n_t_per_req + 1
debug: i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
debug: t_req <- times_todo[c(i_t_beg, i_t_end)]
debug: t_req_str <- format_ISO8601(t_req, usetz = "Z")
debug: if (verbose) message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
debug: message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
Fetching request 1 of 1 (2022-01-01 to 2022-12-01) ~ 19:41:07 UTC
debug: ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
    0), nc)
debug: unlink(ncs0)
debug: nc_retry <- T
debug: nc_n_try <- 1
debug: n_max_retries
debug: while (nc_retry) {
    res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
        url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
            bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
        time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
    if (inherits(res, "try-error")) {
        err <- attr(res, "condition")
        msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
        nc_n_try <- nc_n_try + 1
        if (nc_n_try > n_max_retries) {
            stop(msg)
        }
        else {
            message(msg, "\nRETRYing...")
            Sys.sleep(1)
        }
    }
    else {
        nc_retry <- F
    }
}
debug: res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
    url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
        bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
    time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
debug: if (inherits(res, "try-error")) {
    err <- attr(res, "condition")
    msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
    nc_n_try <- nc_n_try + 1
    if (nc_n_try > n_max_retries) {
        stop(msg)
    }
    else {
        message(msg, "\nRETRYing...")
        Sys.sleep(1)
    }
} else {
    nc_retry <- F
}
debug: nc_retry <- F
debug: (while) nc_retry
debug: i_req <- i_req + 1
debug: (while) i_req <= n_reqs
debug: ncs <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size > 
    0), nc)
debug: r <- terra::rast(ncs)
debug: stopifnot(all(class(terra::time(r)) %in% c("POSIXct", "POSIXt")))
debug: idx <- dplyr::pull(dplyr::filter(dplyr::arrange(dplyr::tibble(idx = 1:terra::nlyr(r), 
    time = terra::time(r)), time), !duplicated(time)), idx)
debug: r <- terra::subset(r, idx)
debug: stopifnot(terra::crs(r, proj = T) == wgs84)
debug: if (mask_tif) r <- terra::mask(r, sf_zones)
debug: lyrs <- glue("{var}|{terra::time(r)}")
debug: if (length(dims_other) > 0 && !all(length(dims[dims_other]) == 
    1)) stop(glue("Other dimensions not yet supported: {paste(dims_other, collapse = ',')}"))
debug: names(r) <- lyrs
debug: if (!is.null(rast_tif)) {
    if (fs::file_exists(rast_tif)) {
        r_tmp_tif <- tempfile(fileext = ".tif")
        r_tmp <- c(rast(rast_tif), r)
        r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
        terra::writeRaster(r_tmp, r_tmp_tif)
        fs::file_delete(rast_tif)
        fs::file_move(r_tmp_tif, rast_tif)
        rm(r)
        rm(r_tmp)
    }
    else {
        terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
    }
    r <- terra::rast(rast_tif)
}
debug: if (fs::file_exists(rast_tif)) {
    r_tmp_tif <- tempfile(fileext = ".tif")
    r_tmp <- c(rast(rast_tif), r)
    r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
    terra::writeRaster(r_tmp, r_tmp_tif)
    fs::file_delete(rast_tif)
    fs::file_move(r_tmp_tif, rast_tif)
    rm(r)
    rm(r_tmp)
} else {
    terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
}
debug: terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
debug: r <- terra::rast(rast_tif)
debug: d_r <- mutate(tidyr::pivot_longer(sf::st_drop_geometry(sf::st_as_sf(terra::zonal(x = r, 
    z = terra::vect(dplyr::select(sf_zones, dplyr::all_of(fld_zones))), 
    fun = zonal_fun, exact = T, na.rm = T, as.polygons = T))), 
    cols = -dplyr::any_of(fld_zones), names_to = "lyr", values_to = zonal_fun), 
    time = readr::parse_datetime(str_replace(lyr, glue("{var}\\|(.*)"), 
        "\\1")))
debug: if (!is.null(zonal_csv)) write_csv(d_r, zonal_csv)
debug: write_csv(d_r, zonal_csv)
debug: if (!keep_nc) unlink(dir_nc, recursive = T)
debug: unlink(dir_nc, recursive = T)
debug: return(d_r)
Downloading 1 requests, up to 641 time slices each
Called from: extractr::ed_extract(ed, var = v, sf_zones = ply, bbox = bb, 
    mask_tif = F, rast_tif = glue("{dir_out}/{nms}/{yr}.tif"), 
    zonal_fun = "mean", zonal_csv = glue("{dir_out}/{nms}/{yr}.csv"), 
    dir_nc = glue("{dir_out}/{nms}/{yr}_nc"), keep_nc = F, n_max_vals_per_req = 1e+05, 
    time_min = time_min, time_max = time_max, verbose = T)
debug: while (i_req <= n_reqs) {
    i_t_beg <- (i_req - 1) * n_t_per_req + 1
    i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
    t_req <- times_todo[c(i_t_beg, i_t_end)]
    t_req_str <- format_ISO8601(t_req, usetz = "Z")
    if (verbose) 
        message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
    ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
        ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
        0), nc)
    unlink(ncs0)
    nc_retry <- T
    nc_n_try <- 1
    n_max_retries
    while (nc_retry) {
        res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
            url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
                bbox[["xmax"]]), latitude = c(bbox[["ymin"]], 
                bbox[["ymax"]]), time = t_req_str, fmt = "nc", 
            store = rerddap::disk(path = dir_nc)))
        if (inherits(res, "try-error")) {
            err <- attr(res, "condition")
            msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
            nc_n_try <- nc_n_try + 1
            if (nc_n_try > n_max_retries) {
                stop(msg)
            }
            else {
                message(msg, "\nRETRYing...")
                Sys.sleep(1)
            }
        }
        else {
            nc_retry <- F
        }
    }
    i_req <- i_req + 1
}
debug: i_t_beg <- (i_req - 1) * n_t_per_req + 1
debug: i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
debug: t_req <- times_todo[c(i_t_beg, i_t_end)]
debug: t_req_str <- format_ISO8601(t_req, usetz = "Z")
debug: if (verbose) message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
debug: message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
Fetching request 1 of 1 (2023-01-01 to 2023-12-01) ~ 19:41:09 UTC
debug: ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
    0), nc)
debug: unlink(ncs0)
debug: nc_retry <- T
debug: nc_n_try <- 1
debug: n_max_retries
debug: while (nc_retry) {
    res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
        url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
            bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
        time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
    if (inherits(res, "try-error")) {
        err <- attr(res, "condition")
        msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
        nc_n_try <- nc_n_try + 1
        if (nc_n_try > n_max_retries) {
            stop(msg)
        }
        else {
            message(msg, "\nRETRYing...")
            Sys.sleep(1)
        }
    }
    else {
        nc_retry <- F
    }
}
debug: res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
    url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
        bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
    time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
debug: if (inherits(res, "try-error")) {
    err <- attr(res, "condition")
    msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
    nc_n_try <- nc_n_try + 1
    if (nc_n_try > n_max_retries) {
        stop(msg)
    }
    else {
        message(msg, "\nRETRYing...")
        Sys.sleep(1)
    }
} else {
    nc_retry <- F
}
debug: nc_retry <- F
debug: (while) nc_retry
debug: i_req <- i_req + 1
debug: (while) i_req <= n_reqs
debug: ncs <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size > 
    0), nc)
debug: r <- terra::rast(ncs)
debug: stopifnot(all(class(terra::time(r)) %in% c("POSIXct", "POSIXt")))
debug: idx <- dplyr::pull(dplyr::filter(dplyr::arrange(dplyr::tibble(idx = 1:terra::nlyr(r), 
    time = terra::time(r)), time), !duplicated(time)), idx)
debug: r <- terra::subset(r, idx)
debug: stopifnot(terra::crs(r, proj = T) == wgs84)
debug: if (mask_tif) r <- terra::mask(r, sf_zones)
debug: lyrs <- glue("{var}|{terra::time(r)}")
debug: if (length(dims_other) > 0 && !all(length(dims[dims_other]) == 
    1)) stop(glue("Other dimensions not yet supported: {paste(dims_other, collapse = ',')}"))
debug: names(r) <- lyrs
debug: if (!is.null(rast_tif)) {
    if (fs::file_exists(rast_tif)) {
        r_tmp_tif <- tempfile(fileext = ".tif")
        r_tmp <- c(rast(rast_tif), r)
        r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
        terra::writeRaster(r_tmp, r_tmp_tif)
        fs::file_delete(rast_tif)
        fs::file_move(r_tmp_tif, rast_tif)
        rm(r)
        rm(r_tmp)
    }
    else {
        terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
    }
    r <- terra::rast(rast_tif)
}
debug: if (fs::file_exists(rast_tif)) {
    r_tmp_tif <- tempfile(fileext = ".tif")
    r_tmp <- c(rast(rast_tif), r)
    r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
    terra::writeRaster(r_tmp, r_tmp_tif)
    fs::file_delete(rast_tif)
    fs::file_move(r_tmp_tif, rast_tif)
    rm(r)
    rm(r_tmp)
} else {
    terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
}
debug: terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
debug: r <- terra::rast(rast_tif)
debug: d_r <- mutate(tidyr::pivot_longer(sf::st_drop_geometry(sf::st_as_sf(terra::zonal(x = r, 
    z = terra::vect(dplyr::select(sf_zones, dplyr::all_of(fld_zones))), 
    fun = zonal_fun, exact = T, na.rm = T, as.polygons = T))), 
    cols = -dplyr::any_of(fld_zones), names_to = "lyr", values_to = zonal_fun), 
    time = readr::parse_datetime(str_replace(lyr, glue("{var}\\|(.*)"), 
        "\\1")))
debug: if (!is.null(zonal_csv)) write_csv(d_r, zonal_csv)
debug: write_csv(d_r, zonal_csv)
debug: if (!keep_nc) unlink(dir_nc, recursive = T)
debug: unlink(dir_nc, recursive = T)
debug: return(d_r)
Downloading 1 requests, up to 641 time slices each
Called from: extractr::ed_extract(ed, var = v, sf_zones = ply, bbox = bb, 
    mask_tif = F, rast_tif = glue("{dir_out}/{nms}/{yr}.tif"), 
    zonal_fun = "mean", zonal_csv = glue("{dir_out}/{nms}/{yr}.csv"), 
    dir_nc = glue("{dir_out}/{nms}/{yr}_nc"), keep_nc = F, n_max_vals_per_req = 1e+05, 
    time_min = time_min, time_max = time_max, verbose = T)
debug: while (i_req <= n_reqs) {
    i_t_beg <- (i_req - 1) * n_t_per_req + 1
    i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
    t_req <- times_todo[c(i_t_beg, i_t_end)]
    t_req_str <- format_ISO8601(t_req, usetz = "Z")
    if (verbose) 
        message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
    ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
        ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
        0), nc)
    unlink(ncs0)
    nc_retry <- T
    nc_n_try <- 1
    n_max_retries
    while (nc_retry) {
        res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
            url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
                bbox[["xmax"]]), latitude = c(bbox[["ymin"]], 
                bbox[["ymax"]]), time = t_req_str, fmt = "nc", 
            store = rerddap::disk(path = dir_nc)))
        if (inherits(res, "try-error")) {
            err <- attr(res, "condition")
            msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
            nc_n_try <- nc_n_try + 1
            if (nc_n_try > n_max_retries) {
                stop(msg)
            }
            else {
                message(msg, "\nRETRYing...")
                Sys.sleep(1)
            }
        }
        else {
            nc_retry <- F
        }
    }
    i_req <- i_req + 1
}
debug: i_t_beg <- (i_req - 1) * n_t_per_req + 1
debug: i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
debug: t_req <- times_todo[c(i_t_beg, i_t_end)]
debug: t_req_str <- format_ISO8601(t_req, usetz = "Z")
debug: if (verbose) message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
debug: message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
Fetching request 1 of 1 (2024-01-01 to 2024-12-01) ~ 19:41:11 UTC
debug: ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
    0), nc)
debug: unlink(ncs0)
debug: nc_retry <- T
debug: nc_n_try <- 1
debug: n_max_retries
debug: while (nc_retry) {
    res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
        url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
            bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
        time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
    if (inherits(res, "try-error")) {
        err <- attr(res, "condition")
        msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
        nc_n_try <- nc_n_try + 1
        if (nc_n_try > n_max_retries) {
            stop(msg)
        }
        else {
            message(msg, "\nRETRYing...")
            Sys.sleep(1)
        }
    }
    else {
        nc_retry <- F
    }
}
debug: res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
    url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
        bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
    time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
debug: if (inherits(res, "try-error")) {
    err <- attr(res, "condition")
    msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
    nc_n_try <- nc_n_try + 1
    if (nc_n_try > n_max_retries) {
        stop(msg)
    }
    else {
        message(msg, "\nRETRYing...")
        Sys.sleep(1)
    }
} else {
    nc_retry <- F
}
debug: nc_retry <- F
debug: (while) nc_retry
debug: i_req <- i_req + 1
debug: (while) i_req <= n_reqs
debug: ncs <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size > 
    0), nc)
debug: r <- terra::rast(ncs)
debug: stopifnot(all(class(terra::time(r)) %in% c("POSIXct", "POSIXt")))
debug: idx <- dplyr::pull(dplyr::filter(dplyr::arrange(dplyr::tibble(idx = 1:terra::nlyr(r), 
    time = terra::time(r)), time), !duplicated(time)), idx)
debug: r <- terra::subset(r, idx)
debug: stopifnot(terra::crs(r, proj = T) == wgs84)
debug: if (mask_tif) r <- terra::mask(r, sf_zones)
debug: lyrs <- glue("{var}|{terra::time(r)}")
debug: if (length(dims_other) > 0 && !all(length(dims[dims_other]) == 
    1)) stop(glue("Other dimensions not yet supported: {paste(dims_other, collapse = ',')}"))
debug: names(r) <- lyrs
debug: if (!is.null(rast_tif)) {
    if (fs::file_exists(rast_tif)) {
        r_tmp_tif <- tempfile(fileext = ".tif")
        r_tmp <- c(rast(rast_tif), r)
        r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
        terra::writeRaster(r_tmp, r_tmp_tif)
        fs::file_delete(rast_tif)
        fs::file_move(r_tmp_tif, rast_tif)
        rm(r)
        rm(r_tmp)
    }
    else {
        terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
    }
    r <- terra::rast(rast_tif)
}
debug: if (fs::file_exists(rast_tif)) {
    r_tmp_tif <- tempfile(fileext = ".tif")
    r_tmp <- c(rast(rast_tif), r)
    r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
    terra::writeRaster(r_tmp, r_tmp_tif)
    fs::file_delete(rast_tif)
    fs::file_move(r_tmp_tif, rast_tif)
    rm(r)
    rm(r_tmp)
} else {
    terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
}
debug: terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
debug: r <- terra::rast(rast_tif)
debug: d_r <- mutate(tidyr::pivot_longer(sf::st_drop_geometry(sf::st_as_sf(terra::zonal(x = r, 
    z = terra::vect(dplyr::select(sf_zones, dplyr::all_of(fld_zones))), 
    fun = zonal_fun, exact = T, na.rm = T, as.polygons = T))), 
    cols = -dplyr::any_of(fld_zones), names_to = "lyr", values_to = zonal_fun), 
    time = readr::parse_datetime(str_replace(lyr, glue("{var}\\|(.*)"), 
        "\\1")))
debug: if (!is.null(zonal_csv)) write_csv(d_r, zonal_csv)
debug: write_csv(d_r, zonal_csv)
debug: if (!keep_nc) unlink(dir_nc, recursive = T)
debug: unlink(dir_nc, recursive = T)
debug: return(d_r)
Downloading 1 requests, up to 641 time slices each
Called from: extractr::ed_extract(ed, var = v, sf_zones = ply, bbox = bb, 
    mask_tif = F, rast_tif = glue("{dir_out}/{nms}/{yr}.tif"), 
    zonal_fun = "mean", zonal_csv = glue("{dir_out}/{nms}/{yr}.csv"), 
    dir_nc = glue("{dir_out}/{nms}/{yr}_nc"), keep_nc = F, n_max_vals_per_req = 1e+05, 
    time_min = time_min, time_max = time_max, verbose = T)
debug: while (i_req <= n_reqs) {
    i_t_beg <- (i_req - 1) * n_t_per_req + 1
    i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
    t_req <- times_todo[c(i_t_beg, i_t_end)]
    t_req_str <- format_ISO8601(t_req, usetz = "Z")
    if (verbose) 
        message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
    ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
        ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
        0), nc)
    unlink(ncs0)
    nc_retry <- T
    nc_n_try <- 1
    n_max_retries
    while (nc_retry) {
        res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
            url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
                bbox[["xmax"]]), latitude = c(bbox[["ymin"]], 
                bbox[["ymax"]]), time = t_req_str, fmt = "nc", 
            store = rerddap::disk(path = dir_nc)))
        if (inherits(res, "try-error")) {
            err <- attr(res, "condition")
            msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
            nc_n_try <- nc_n_try + 1
            if (nc_n_try > n_max_retries) {
                stop(msg)
            }
            else {
                message(msg, "\nRETRYing...")
                Sys.sleep(1)
            }
        }
        else {
            nc_retry <- F
        }
    }
    i_req <- i_req + 1
}
debug: i_t_beg <- (i_req - 1) * n_t_per_req + 1
debug: i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
debug: t_req <- times_todo[c(i_t_beg, i_t_end)]
debug: t_req_str <- format_ISO8601(t_req, usetz = "Z")
debug: if (verbose) message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
debug: message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
Fetching request 1 of 1 (2025-01-01 to 2025-07-01) ~ 19:41:13 UTC
debug: ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
    0), nc)
debug: unlink(ncs0)
debug: nc_retry <- T
debug: nc_n_try <- 1
debug: n_max_retries
debug: while (nc_retry) {
    res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
        url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
            bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
        time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
    if (inherits(res, "try-error")) {
        err <- attr(res, "condition")
        msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
        nc_n_try <- nc_n_try + 1
        if (nc_n_try > n_max_retries) {
            stop(msg)
        }
        else {
            message(msg, "\nRETRYing...")
            Sys.sleep(1)
        }
    }
    else {
        nc_retry <- F
    }
}
debug: res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
    url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
        bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
    time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
debug: if (inherits(res, "try-error")) {
    err <- attr(res, "condition")
    msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
    nc_n_try <- nc_n_try + 1
    if (nc_n_try > n_max_retries) {
        stop(msg)
    }
    else {
        message(msg, "\nRETRYing...")
        Sys.sleep(1)
    }
} else {
    nc_retry <- F
}
debug: nc_retry <- F
debug: (while) nc_retry
debug: i_req <- i_req + 1
debug: (while) i_req <= n_reqs
debug: ncs <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size > 
    0), nc)
debug: r <- terra::rast(ncs)
debug: stopifnot(all(class(terra::time(r)) %in% c("POSIXct", "POSIXt")))
debug: idx <- dplyr::pull(dplyr::filter(dplyr::arrange(dplyr::tibble(idx = 1:terra::nlyr(r), 
    time = terra::time(r)), time), !duplicated(time)), idx)
debug: r <- terra::subset(r, idx)
debug: stopifnot(terra::crs(r, proj = T) == wgs84)
debug: if (mask_tif) r <- terra::mask(r, sf_zones)
debug: lyrs <- glue("{var}|{terra::time(r)}")
debug: if (length(dims_other) > 0 && !all(length(dims[dims_other]) == 
    1)) stop(glue("Other dimensions not yet supported: {paste(dims_other, collapse = ',')}"))
debug: names(r) <- lyrs
debug: if (!is.null(rast_tif)) {
    if (fs::file_exists(rast_tif)) {
        r_tmp_tif <- tempfile(fileext = ".tif")
        r_tmp <- c(rast(rast_tif), r)
        r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
        terra::writeRaster(r_tmp, r_tmp_tif)
        fs::file_delete(rast_tif)
        fs::file_move(r_tmp_tif, rast_tif)
        rm(r)
        rm(r_tmp)
    }
    else {
        terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
    }
    r <- terra::rast(rast_tif)
}
debug: if (fs::file_exists(rast_tif)) {
    r_tmp_tif <- tempfile(fileext = ".tif")
    r_tmp <- c(rast(rast_tif), r)
    r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
    terra::writeRaster(r_tmp, r_tmp_tif)
    fs::file_delete(rast_tif)
    fs::file_move(r_tmp_tif, rast_tif)
    rm(r)
    rm(r_tmp)
} else {
    terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
}
debug: terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
debug: r <- terra::rast(rast_tif)
debug: d_r <- mutate(tidyr::pivot_longer(sf::st_drop_geometry(sf::st_as_sf(terra::zonal(x = r, 
    z = terra::vect(dplyr::select(sf_zones, dplyr::all_of(fld_zones))), 
    fun = zonal_fun, exact = T, na.rm = T, as.polygons = T))), 
    cols = -dplyr::any_of(fld_zones), names_to = "lyr", values_to = zonal_fun), 
    time = readr::parse_datetime(str_replace(lyr, glue("{var}\\|(.*)"), 
        "\\1")))
debug: if (!is.null(zonal_csv)) write_csv(d_r, zonal_csv)
debug: write_csv(d_r, zonal_csv)
debug: if (!keep_nc) unlink(dir_nc, recursive = T)
debug: unlink(dir_nc, recursive = T)
debug: return(d_r)
Downloading 1 requests, up to 114 time slices each
Called from: extractr::ed_extract(ed, var = v, sf_zones = ply, bbox = bb, 
    mask_tif = F, rast_tif = glue("{dir_out}/{nms}/{yr}.tif"), 
    zonal_fun = "mean", zonal_csv = glue("{dir_out}/{nms}/{yr}.csv"), 
    dir_nc = glue("{dir_out}/{nms}/{yr}_nc"), keep_nc = F, n_max_vals_per_req = 1e+05, 
    time_min = time_min, time_max = time_max, verbose = T)
debug: while (i_req <= n_reqs) {
    i_t_beg <- (i_req - 1) * n_t_per_req + 1
    i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
    t_req <- times_todo[c(i_t_beg, i_t_end)]
    t_req_str <- format_ISO8601(t_req, usetz = "Z")
    if (verbose) 
        message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
    ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
        ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
        0), nc)
    unlink(ncs0)
    nc_retry <- T
    nc_n_try <- 1
    n_max_retries
    while (nc_retry) {
        res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
            url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
                bbox[["xmax"]]), latitude = c(bbox[["ymin"]], 
                bbox[["ymax"]]), time = t_req_str, fmt = "nc", 
            store = rerddap::disk(path = dir_nc)))
        if (inherits(res, "try-error")) {
            err <- attr(res, "condition")
            msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
            nc_n_try <- nc_n_try + 1
            if (nc_n_try > n_max_retries) {
                stop(msg)
            }
            else {
                message(msg, "\nRETRYing...")
                Sys.sleep(1)
            }
        }
        else {
            nc_retry <- F
        }
    }
    i_req <- i_req + 1
}
debug: i_t_beg <- (i_req - 1) * n_t_per_req + 1
debug: i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
debug: t_req <- times_todo[c(i_t_beg, i_t_end)]
debug: t_req_str <- format_ISO8601(t_req, usetz = "Z")
debug: if (verbose) message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
debug: message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
Fetching request 1 of 1 (1998-01-01 to 1998-12-01) ~ 19:41:14 UTC
debug: ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
    0), nc)
debug: unlink(ncs0)
debug: nc_retry <- T
debug: nc_n_try <- 1
debug: n_max_retries
debug: while (nc_retry) {
    res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
        url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
            bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
        time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
    if (inherits(res, "try-error")) {
        err <- attr(res, "condition")
        msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
        nc_n_try <- nc_n_try + 1
        if (nc_n_try > n_max_retries) {
            stop(msg)
        }
        else {
            message(msg, "\nRETRYing...")
            Sys.sleep(1)
        }
    }
    else {
        nc_retry <- F
    }
}
debug: res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
    url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
        bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
    time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
debug: if (inherits(res, "try-error")) {
    err <- attr(res, "condition")
    msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
    nc_n_try <- nc_n_try + 1
    if (nc_n_try > n_max_retries) {
        stop(msg)
    }
    else {
        message(msg, "\nRETRYing...")
        Sys.sleep(1)
    }
} else {
    nc_retry <- F
}
debug: nc_retry <- F
debug: (while) nc_retry
debug: i_req <- i_req + 1
debug: (while) i_req <= n_reqs
debug: ncs <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size > 
    0), nc)
debug: r <- terra::rast(ncs)
debug: stopifnot(all(class(terra::time(r)) %in% c("POSIXct", "POSIXt")))
debug: idx <- dplyr::pull(dplyr::filter(dplyr::arrange(dplyr::tibble(idx = 1:terra::nlyr(r), 
    time = terra::time(r)), time), !duplicated(time)), idx)
debug: r <- terra::subset(r, idx)
debug: stopifnot(terra::crs(r, proj = T) == wgs84)
debug: if (mask_tif) r <- terra::mask(r, sf_zones)
debug: lyrs <- glue("{var}|{terra::time(r)}")
debug: if (length(dims_other) > 0 && !all(length(dims[dims_other]) == 
    1)) stop(glue("Other dimensions not yet supported: {paste(dims_other, collapse = ',')}"))
debug: names(r) <- lyrs
debug: if (!is.null(rast_tif)) {
    if (fs::file_exists(rast_tif)) {
        r_tmp_tif <- tempfile(fileext = ".tif")
        r_tmp <- c(rast(rast_tif), r)
        r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
        terra::writeRaster(r_tmp, r_tmp_tif)
        fs::file_delete(rast_tif)
        fs::file_move(r_tmp_tif, rast_tif)
        rm(r)
        rm(r_tmp)
    }
    else {
        terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
    }
    r <- terra::rast(rast_tif)
}
debug: if (fs::file_exists(rast_tif)) {
    r_tmp_tif <- tempfile(fileext = ".tif")
    r_tmp <- c(rast(rast_tif), r)
    r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
    terra::writeRaster(r_tmp, r_tmp_tif)
    fs::file_delete(rast_tif)
    fs::file_move(r_tmp_tif, rast_tif)
    rm(r)
    rm(r_tmp)
} else {
    terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
}
debug: terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
debug: r <- terra::rast(rast_tif)
debug: d_r <- mutate(tidyr::pivot_longer(sf::st_drop_geometry(sf::st_as_sf(terra::zonal(x = r, 
    z = terra::vect(dplyr::select(sf_zones, dplyr::all_of(fld_zones))), 
    fun = zonal_fun, exact = T, na.rm = T, as.polygons = T))), 
    cols = -dplyr::any_of(fld_zones), names_to = "lyr", values_to = zonal_fun), 
    time = readr::parse_datetime(str_replace(lyr, glue("{var}\\|(.*)"), 
        "\\1")))
debug: if (!is.null(zonal_csv)) write_csv(d_r, zonal_csv)
debug: write_csv(d_r, zonal_csv)
debug: if (!keep_nc) unlink(dir_nc, recursive = T)
debug: unlink(dir_nc, recursive = T)
debug: return(d_r)
Downloading 1 requests, up to 114 time slices each
Called from: extractr::ed_extract(ed, var = v, sf_zones = ply, bbox = bb, 
    mask_tif = F, rast_tif = glue("{dir_out}/{nms}/{yr}.tif"), 
    zonal_fun = "mean", zonal_csv = glue("{dir_out}/{nms}/{yr}.csv"), 
    dir_nc = glue("{dir_out}/{nms}/{yr}_nc"), keep_nc = F, n_max_vals_per_req = 1e+05, 
    time_min = time_min, time_max = time_max, verbose = T)
debug: while (i_req <= n_reqs) {
    i_t_beg <- (i_req - 1) * n_t_per_req + 1
    i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
    t_req <- times_todo[c(i_t_beg, i_t_end)]
    t_req_str <- format_ISO8601(t_req, usetz = "Z")
    if (verbose) 
        message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
    ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
        ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
        0), nc)
    unlink(ncs0)
    nc_retry <- T
    nc_n_try <- 1
    n_max_retries
    while (nc_retry) {
        res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
            url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
                bbox[["xmax"]]), latitude = c(bbox[["ymin"]], 
                bbox[["ymax"]]), time = t_req_str, fmt = "nc", 
            store = rerddap::disk(path = dir_nc)))
        if (inherits(res, "try-error")) {
            err <- attr(res, "condition")
            msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
            nc_n_try <- nc_n_try + 1
            if (nc_n_try > n_max_retries) {
                stop(msg)
            }
            else {
                message(msg, "\nRETRYing...")
                Sys.sleep(1)
            }
        }
        else {
            nc_retry <- F
        }
    }
    i_req <- i_req + 1
}
debug: i_t_beg <- (i_req - 1) * n_t_per_req + 1
debug: i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
debug: t_req <- times_todo[c(i_t_beg, i_t_end)]
debug: t_req_str <- format_ISO8601(t_req, usetz = "Z")
debug: if (verbose) message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
debug: message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
Fetching request 1 of 1 (1999-01-01 to 1999-12-01) ~ 19:41:16 UTC
debug: ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
    0), nc)
debug: unlink(ncs0)
debug: nc_retry <- T
debug: nc_n_try <- 1
debug: n_max_retries
debug: while (nc_retry) {
    res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
        url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
            bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
        time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
    if (inherits(res, "try-error")) {
        err <- attr(res, "condition")
        msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
        nc_n_try <- nc_n_try + 1
        if (nc_n_try > n_max_retries) {
            stop(msg)
        }
        else {
            message(msg, "\nRETRYing...")
            Sys.sleep(1)
        }
    }
    else {
        nc_retry <- F
    }
}
debug: res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
    url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
        bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
    time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
debug: if (inherits(res, "try-error")) {
    err <- attr(res, "condition")
    msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
    nc_n_try <- nc_n_try + 1
    if (nc_n_try > n_max_retries) {
        stop(msg)
    }
    else {
        message(msg, "\nRETRYing...")
        Sys.sleep(1)
    }
} else {
    nc_retry <- F
}
debug: nc_retry <- F
debug: (while) nc_retry
debug: i_req <- i_req + 1
debug: (while) i_req <= n_reqs
debug: ncs <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size > 
    0), nc)
debug: r <- terra::rast(ncs)
debug: stopifnot(all(class(terra::time(r)) %in% c("POSIXct", "POSIXt")))
debug: idx <- dplyr::pull(dplyr::filter(dplyr::arrange(dplyr::tibble(idx = 1:terra::nlyr(r), 
    time = terra::time(r)), time), !duplicated(time)), idx)
debug: r <- terra::subset(r, idx)
debug: stopifnot(terra::crs(r, proj = T) == wgs84)
debug: if (mask_tif) r <- terra::mask(r, sf_zones)
debug: lyrs <- glue("{var}|{terra::time(r)}")
debug: if (length(dims_other) > 0 && !all(length(dims[dims_other]) == 
    1)) stop(glue("Other dimensions not yet supported: {paste(dims_other, collapse = ',')}"))
debug: names(r) <- lyrs
debug: if (!is.null(rast_tif)) {
    if (fs::file_exists(rast_tif)) {
        r_tmp_tif <- tempfile(fileext = ".tif")
        r_tmp <- c(rast(rast_tif), r)
        r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
        terra::writeRaster(r_tmp, r_tmp_tif)
        fs::file_delete(rast_tif)
        fs::file_move(r_tmp_tif, rast_tif)
        rm(r)
        rm(r_tmp)
    }
    else {
        terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
    }
    r <- terra::rast(rast_tif)
}
debug: if (fs::file_exists(rast_tif)) {
    r_tmp_tif <- tempfile(fileext = ".tif")
    r_tmp <- c(rast(rast_tif), r)
    r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
    terra::writeRaster(r_tmp, r_tmp_tif)
    fs::file_delete(rast_tif)
    fs::file_move(r_tmp_tif, rast_tif)
    rm(r)
    rm(r_tmp)
} else {
    terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
}
debug: terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
debug: r <- terra::rast(rast_tif)
debug: d_r <- mutate(tidyr::pivot_longer(sf::st_drop_geometry(sf::st_as_sf(terra::zonal(x = r, 
    z = terra::vect(dplyr::select(sf_zones, dplyr::all_of(fld_zones))), 
    fun = zonal_fun, exact = T, na.rm = T, as.polygons = T))), 
    cols = -dplyr::any_of(fld_zones), names_to = "lyr", values_to = zonal_fun), 
    time = readr::parse_datetime(str_replace(lyr, glue("{var}\\|(.*)"), 
        "\\1")))
debug: if (!is.null(zonal_csv)) write_csv(d_r, zonal_csv)
debug: write_csv(d_r, zonal_csv)
debug: if (!keep_nc) unlink(dir_nc, recursive = T)
debug: unlink(dir_nc, recursive = T)
debug: return(d_r)
Downloading 1 requests, up to 114 time slices each
Called from: extractr::ed_extract(ed, var = v, sf_zones = ply, bbox = bb, 
    mask_tif = F, rast_tif = glue("{dir_out}/{nms}/{yr}.tif"), 
    zonal_fun = "mean", zonal_csv = glue("{dir_out}/{nms}/{yr}.csv"), 
    dir_nc = glue("{dir_out}/{nms}/{yr}_nc"), keep_nc = F, n_max_vals_per_req = 1e+05, 
    time_min = time_min, time_max = time_max, verbose = T)
debug: while (i_req <= n_reqs) {
    i_t_beg <- (i_req - 1) * n_t_per_req + 1
    i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
    t_req <- times_todo[c(i_t_beg, i_t_end)]
    t_req_str <- format_ISO8601(t_req, usetz = "Z")
    if (verbose) 
        message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
    ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
        ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
        0), nc)
    unlink(ncs0)
    nc_retry <- T
    nc_n_try <- 1
    n_max_retries
    while (nc_retry) {
        res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
            url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
                bbox[["xmax"]]), latitude = c(bbox[["ymin"]], 
                bbox[["ymax"]]), time = t_req_str, fmt = "nc", 
            store = rerddap::disk(path = dir_nc)))
        if (inherits(res, "try-error")) {
            err <- attr(res, "condition")
            msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
            nc_n_try <- nc_n_try + 1
            if (nc_n_try > n_max_retries) {
                stop(msg)
            }
            else {
                message(msg, "\nRETRYing...")
                Sys.sleep(1)
            }
        }
        else {
            nc_retry <- F
        }
    }
    i_req <- i_req + 1
}
debug: i_t_beg <- (i_req - 1) * n_t_per_req + 1
debug: i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
debug: t_req <- times_todo[c(i_t_beg, i_t_end)]
debug: t_req_str <- format_ISO8601(t_req, usetz = "Z")
debug: if (verbose) message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
debug: message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
Fetching request 1 of 1 (2000-01-01 to 2000-12-01) ~ 19:41:18 UTC
debug: ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
    0), nc)
debug: unlink(ncs0)
debug: nc_retry <- T
debug: nc_n_try <- 1
debug: n_max_retries
debug: while (nc_retry) {
    res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
        url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
            bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
        time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
    if (inherits(res, "try-error")) {
        err <- attr(res, "condition")
        msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
        nc_n_try <- nc_n_try + 1
        if (nc_n_try > n_max_retries) {
            stop(msg)
        }
        else {
            message(msg, "\nRETRYing...")
            Sys.sleep(1)
        }
    }
    else {
        nc_retry <- F
    }
}
debug: res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
    url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
        bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
    time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
debug: if (inherits(res, "try-error")) {
    err <- attr(res, "condition")
    msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
    nc_n_try <- nc_n_try + 1
    if (nc_n_try > n_max_retries) {
        stop(msg)
    }
    else {
        message(msg, "\nRETRYing...")
        Sys.sleep(1)
    }
} else {
    nc_retry <- F
}
debug: nc_retry <- F
debug: (while) nc_retry
debug: i_req <- i_req + 1
debug: (while) i_req <= n_reqs
debug: ncs <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size > 
    0), nc)
debug: r <- terra::rast(ncs)
debug: stopifnot(all(class(terra::time(r)) %in% c("POSIXct", "POSIXt")))
debug: idx <- dplyr::pull(dplyr::filter(dplyr::arrange(dplyr::tibble(idx = 1:terra::nlyr(r), 
    time = terra::time(r)), time), !duplicated(time)), idx)
debug: r <- terra::subset(r, idx)
debug: stopifnot(terra::crs(r, proj = T) == wgs84)
debug: if (mask_tif) r <- terra::mask(r, sf_zones)
debug: lyrs <- glue("{var}|{terra::time(r)}")
debug: if (length(dims_other) > 0 && !all(length(dims[dims_other]) == 
    1)) stop(glue("Other dimensions not yet supported: {paste(dims_other, collapse = ',')}"))
debug: names(r) <- lyrs
debug: if (!is.null(rast_tif)) {
    if (fs::file_exists(rast_tif)) {
        r_tmp_tif <- tempfile(fileext = ".tif")
        r_tmp <- c(rast(rast_tif), r)
        r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
        terra::writeRaster(r_tmp, r_tmp_tif)
        fs::file_delete(rast_tif)
        fs::file_move(r_tmp_tif, rast_tif)
        rm(r)
        rm(r_tmp)
    }
    else {
        terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
    }
    r <- terra::rast(rast_tif)
}
debug: if (fs::file_exists(rast_tif)) {
    r_tmp_tif <- tempfile(fileext = ".tif")
    r_tmp <- c(rast(rast_tif), r)
    r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
    terra::writeRaster(r_tmp, r_tmp_tif)
    fs::file_delete(rast_tif)
    fs::file_move(r_tmp_tif, rast_tif)
    rm(r)
    rm(r_tmp)
} else {
    terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
}
debug: terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
debug: r <- terra::rast(rast_tif)
debug: d_r <- mutate(tidyr::pivot_longer(sf::st_drop_geometry(sf::st_as_sf(terra::zonal(x = r, 
    z = terra::vect(dplyr::select(sf_zones, dplyr::all_of(fld_zones))), 
    fun = zonal_fun, exact = T, na.rm = T, as.polygons = T))), 
    cols = -dplyr::any_of(fld_zones), names_to = "lyr", values_to = zonal_fun), 
    time = readr::parse_datetime(str_replace(lyr, glue("{var}\\|(.*)"), 
        "\\1")))
debug: if (!is.null(zonal_csv)) write_csv(d_r, zonal_csv)
debug: write_csv(d_r, zonal_csv)
debug: if (!keep_nc) unlink(dir_nc, recursive = T)
debug: unlink(dir_nc, recursive = T)
debug: return(d_r)
Downloading 1 requests, up to 114 time slices each
Called from: extractr::ed_extract(ed, var = v, sf_zones = ply, bbox = bb, 
    mask_tif = F, rast_tif = glue("{dir_out}/{nms}/{yr}.tif"), 
    zonal_fun = "mean", zonal_csv = glue("{dir_out}/{nms}/{yr}.csv"), 
    dir_nc = glue("{dir_out}/{nms}/{yr}_nc"), keep_nc = F, n_max_vals_per_req = 1e+05, 
    time_min = time_min, time_max = time_max, verbose = T)
debug: while (i_req <= n_reqs) {
    i_t_beg <- (i_req - 1) * n_t_per_req + 1
    i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
    t_req <- times_todo[c(i_t_beg, i_t_end)]
    t_req_str <- format_ISO8601(t_req, usetz = "Z")
    if (verbose) 
        message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
    ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
        ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
        0), nc)
    unlink(ncs0)
    nc_retry <- T
    nc_n_try <- 1
    n_max_retries
    while (nc_retry) {
        res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
            url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
                bbox[["xmax"]]), latitude = c(bbox[["ymin"]], 
                bbox[["ymax"]]), time = t_req_str, fmt = "nc", 
            store = rerddap::disk(path = dir_nc)))
        if (inherits(res, "try-error")) {
            err <- attr(res, "condition")
            msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
            nc_n_try <- nc_n_try + 1
            if (nc_n_try > n_max_retries) {
                stop(msg)
            }
            else {
                message(msg, "\nRETRYing...")
                Sys.sleep(1)
            }
        }
        else {
            nc_retry <- F
        }
    }
    i_req <- i_req + 1
}
debug: i_t_beg <- (i_req - 1) * n_t_per_req + 1
debug: i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
debug: t_req <- times_todo[c(i_t_beg, i_t_end)]
debug: t_req_str <- format_ISO8601(t_req, usetz = "Z")
debug: if (verbose) message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
debug: message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
Fetching request 1 of 1 (2001-01-01 to 2001-12-01) ~ 19:41:20 UTC
debug: ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
    0), nc)
debug: unlink(ncs0)
debug: nc_retry <- T
debug: nc_n_try <- 1
debug: n_max_retries
debug: while (nc_retry) {
    res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
        url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
            bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
        time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
    if (inherits(res, "try-error")) {
        err <- attr(res, "condition")
        msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
        nc_n_try <- nc_n_try + 1
        if (nc_n_try > n_max_retries) {
            stop(msg)
        }
        else {
            message(msg, "\nRETRYing...")
            Sys.sleep(1)
        }
    }
    else {
        nc_retry <- F
    }
}
debug: res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
    url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
        bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
    time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
debug: if (inherits(res, "try-error")) {
    err <- attr(res, "condition")
    msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
    nc_n_try <- nc_n_try + 1
    if (nc_n_try > n_max_retries) {
        stop(msg)
    }
    else {
        message(msg, "\nRETRYing...")
        Sys.sleep(1)
    }
} else {
    nc_retry <- F
}
debug: nc_retry <- F
debug: (while) nc_retry
debug: i_req <- i_req + 1
debug: (while) i_req <= n_reqs
debug: ncs <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size > 
    0), nc)
debug: r <- terra::rast(ncs)
debug: stopifnot(all(class(terra::time(r)) %in% c("POSIXct", "POSIXt")))
debug: idx <- dplyr::pull(dplyr::filter(dplyr::arrange(dplyr::tibble(idx = 1:terra::nlyr(r), 
    time = terra::time(r)), time), !duplicated(time)), idx)
debug: r <- terra::subset(r, idx)
debug: stopifnot(terra::crs(r, proj = T) == wgs84)
debug: if (mask_tif) r <- terra::mask(r, sf_zones)
debug: lyrs <- glue("{var}|{terra::time(r)}")
debug: if (length(dims_other) > 0 && !all(length(dims[dims_other]) == 
    1)) stop(glue("Other dimensions not yet supported: {paste(dims_other, collapse = ',')}"))
debug: names(r) <- lyrs
debug: if (!is.null(rast_tif)) {
    if (fs::file_exists(rast_tif)) {
        r_tmp_tif <- tempfile(fileext = ".tif")
        r_tmp <- c(rast(rast_tif), r)
        r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
        terra::writeRaster(r_tmp, r_tmp_tif)
        fs::file_delete(rast_tif)
        fs::file_move(r_tmp_tif, rast_tif)
        rm(r)
        rm(r_tmp)
    }
    else {
        terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
    }
    r <- terra::rast(rast_tif)
}
debug: if (fs::file_exists(rast_tif)) {
    r_tmp_tif <- tempfile(fileext = ".tif")
    r_tmp <- c(rast(rast_tif), r)
    r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
    terra::writeRaster(r_tmp, r_tmp_tif)
    fs::file_delete(rast_tif)
    fs::file_move(r_tmp_tif, rast_tif)
    rm(r)
    rm(r_tmp)
} else {
    terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
}
debug: terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
debug: r <- terra::rast(rast_tif)
debug: d_r <- mutate(tidyr::pivot_longer(sf::st_drop_geometry(sf::st_as_sf(terra::zonal(x = r, 
    z = terra::vect(dplyr::select(sf_zones, dplyr::all_of(fld_zones))), 
    fun = zonal_fun, exact = T, na.rm = T, as.polygons = T))), 
    cols = -dplyr::any_of(fld_zones), names_to = "lyr", values_to = zonal_fun), 
    time = readr::parse_datetime(str_replace(lyr, glue("{var}\\|(.*)"), 
        "\\1")))
debug: if (!is.null(zonal_csv)) write_csv(d_r, zonal_csv)
debug: write_csv(d_r, zonal_csv)
debug: if (!keep_nc) unlink(dir_nc, recursive = T)
debug: unlink(dir_nc, recursive = T)
debug: return(d_r)
Downloading 1 requests, up to 114 time slices each
Called from: extractr::ed_extract(ed, var = v, sf_zones = ply, bbox = bb, 
    mask_tif = F, rast_tif = glue("{dir_out}/{nms}/{yr}.tif"), 
    zonal_fun = "mean", zonal_csv = glue("{dir_out}/{nms}/{yr}.csv"), 
    dir_nc = glue("{dir_out}/{nms}/{yr}_nc"), keep_nc = F, n_max_vals_per_req = 1e+05, 
    time_min = time_min, time_max = time_max, verbose = T)
debug: while (i_req <= n_reqs) {
    i_t_beg <- (i_req - 1) * n_t_per_req + 1
    i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
    t_req <- times_todo[c(i_t_beg, i_t_end)]
    t_req_str <- format_ISO8601(t_req, usetz = "Z")
    if (verbose) 
        message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
    ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
        ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
        0), nc)
    unlink(ncs0)
    nc_retry <- T
    nc_n_try <- 1
    n_max_retries
    while (nc_retry) {
        res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
            url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
                bbox[["xmax"]]), latitude = c(bbox[["ymin"]], 
                bbox[["ymax"]]), time = t_req_str, fmt = "nc", 
            store = rerddap::disk(path = dir_nc)))
        if (inherits(res, "try-error")) {
            err <- attr(res, "condition")
            msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
            nc_n_try <- nc_n_try + 1
            if (nc_n_try > n_max_retries) {
                stop(msg)
            }
            else {
                message(msg, "\nRETRYing...")
                Sys.sleep(1)
            }
        }
        else {
            nc_retry <- F
        }
    }
    i_req <- i_req + 1
}
debug: i_t_beg <- (i_req - 1) * n_t_per_req + 1
debug: i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
debug: t_req <- times_todo[c(i_t_beg, i_t_end)]
debug: t_req_str <- format_ISO8601(t_req, usetz = "Z")
debug: if (verbose) message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
debug: message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
Fetching request 1 of 1 (2002-01-01 to 2002-12-01) ~ 19:41:22 UTC
debug: ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
    0), nc)
debug: unlink(ncs0)
debug: nc_retry <- T
debug: nc_n_try <- 1
debug: n_max_retries
debug: while (nc_retry) {
    res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
        url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
            bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
        time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
    if (inherits(res, "try-error")) {
        err <- attr(res, "condition")
        msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
        nc_n_try <- nc_n_try + 1
        if (nc_n_try > n_max_retries) {
            stop(msg)
        }
        else {
            message(msg, "\nRETRYing...")
            Sys.sleep(1)
        }
    }
    else {
        nc_retry <- F
    }
}
debug: res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
    url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
        bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
    time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
debug: if (inherits(res, "try-error")) {
    err <- attr(res, "condition")
    msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
    nc_n_try <- nc_n_try + 1
    if (nc_n_try > n_max_retries) {
        stop(msg)
    }
    else {
        message(msg, "\nRETRYing...")
        Sys.sleep(1)
    }
} else {
    nc_retry <- F
}
debug: nc_retry <- F
debug: (while) nc_retry
debug: i_req <- i_req + 1
debug: (while) i_req <= n_reqs
debug: ncs <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size > 
    0), nc)
debug: r <- terra::rast(ncs)
debug: stopifnot(all(class(terra::time(r)) %in% c("POSIXct", "POSIXt")))
debug: idx <- dplyr::pull(dplyr::filter(dplyr::arrange(dplyr::tibble(idx = 1:terra::nlyr(r), 
    time = terra::time(r)), time), !duplicated(time)), idx)
debug: r <- terra::subset(r, idx)
debug: stopifnot(terra::crs(r, proj = T) == wgs84)
debug: if (mask_tif) r <- terra::mask(r, sf_zones)
debug: lyrs <- glue("{var}|{terra::time(r)}")
debug: if (length(dims_other) > 0 && !all(length(dims[dims_other]) == 
    1)) stop(glue("Other dimensions not yet supported: {paste(dims_other, collapse = ',')}"))
debug: names(r) <- lyrs
debug: if (!is.null(rast_tif)) {
    if (fs::file_exists(rast_tif)) {
        r_tmp_tif <- tempfile(fileext = ".tif")
        r_tmp <- c(rast(rast_tif), r)
        r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
        terra::writeRaster(r_tmp, r_tmp_tif)
        fs::file_delete(rast_tif)
        fs::file_move(r_tmp_tif, rast_tif)
        rm(r)
        rm(r_tmp)
    }
    else {
        terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
    }
    r <- terra::rast(rast_tif)
}
debug: if (fs::file_exists(rast_tif)) {
    r_tmp_tif <- tempfile(fileext = ".tif")
    r_tmp <- c(rast(rast_tif), r)
    r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
    terra::writeRaster(r_tmp, r_tmp_tif)
    fs::file_delete(rast_tif)
    fs::file_move(r_tmp_tif, rast_tif)
    rm(r)
    rm(r_tmp)
} else {
    terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
}
debug: terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
debug: r <- terra::rast(rast_tif)
debug: d_r <- mutate(tidyr::pivot_longer(sf::st_drop_geometry(sf::st_as_sf(terra::zonal(x = r, 
    z = terra::vect(dplyr::select(sf_zones, dplyr::all_of(fld_zones))), 
    fun = zonal_fun, exact = T, na.rm = T, as.polygons = T))), 
    cols = -dplyr::any_of(fld_zones), names_to = "lyr", values_to = zonal_fun), 
    time = readr::parse_datetime(str_replace(lyr, glue("{var}\\|(.*)"), 
        "\\1")))
debug: if (!is.null(zonal_csv)) write_csv(d_r, zonal_csv)
debug: write_csv(d_r, zonal_csv)
debug: if (!keep_nc) unlink(dir_nc, recursive = T)
debug: unlink(dir_nc, recursive = T)
debug: return(d_r)
Downloading 1 requests, up to 114 time slices each
Called from: extractr::ed_extract(ed, var = v, sf_zones = ply, bbox = bb, 
    mask_tif = F, rast_tif = glue("{dir_out}/{nms}/{yr}.tif"), 
    zonal_fun = "mean", zonal_csv = glue("{dir_out}/{nms}/{yr}.csv"), 
    dir_nc = glue("{dir_out}/{nms}/{yr}_nc"), keep_nc = F, n_max_vals_per_req = 1e+05, 
    time_min = time_min, time_max = time_max, verbose = T)
debug: while (i_req <= n_reqs) {
    i_t_beg <- (i_req - 1) * n_t_per_req + 1
    i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
    t_req <- times_todo[c(i_t_beg, i_t_end)]
    t_req_str <- format_ISO8601(t_req, usetz = "Z")
    if (verbose) 
        message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
    ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
        ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
        0), nc)
    unlink(ncs0)
    nc_retry <- T
    nc_n_try <- 1
    n_max_retries
    while (nc_retry) {
        res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
            url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
                bbox[["xmax"]]), latitude = c(bbox[["ymin"]], 
                bbox[["ymax"]]), time = t_req_str, fmt = "nc", 
            store = rerddap::disk(path = dir_nc)))
        if (inherits(res, "try-error")) {
            err <- attr(res, "condition")
            msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
            nc_n_try <- nc_n_try + 1
            if (nc_n_try > n_max_retries) {
                stop(msg)
            }
            else {
                message(msg, "\nRETRYing...")
                Sys.sleep(1)
            }
        }
        else {
            nc_retry <- F
        }
    }
    i_req <- i_req + 1
}
debug: i_t_beg <- (i_req - 1) * n_t_per_req + 1
debug: i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
debug: t_req <- times_todo[c(i_t_beg, i_t_end)]
debug: t_req_str <- format_ISO8601(t_req, usetz = "Z")
debug: if (verbose) message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
debug: message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
Fetching request 1 of 1 (2003-01-01 to 2003-12-01) ~ 19:41:24 UTC
debug: ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
    0), nc)
debug: unlink(ncs0)
debug: nc_retry <- T
debug: nc_n_try <- 1
debug: n_max_retries
debug: while (nc_retry) {
    res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
        url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
            bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
        time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
    if (inherits(res, "try-error")) {
        err <- attr(res, "condition")
        msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
        nc_n_try <- nc_n_try + 1
        if (nc_n_try > n_max_retries) {
            stop(msg)
        }
        else {
            message(msg, "\nRETRYing...")
            Sys.sleep(1)
        }
    }
    else {
        nc_retry <- F
    }
}
debug: res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
    url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
        bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
    time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
debug: if (inherits(res, "try-error")) {
    err <- attr(res, "condition")
    msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
    nc_n_try <- nc_n_try + 1
    if (nc_n_try > n_max_retries) {
        stop(msg)
    }
    else {
        message(msg, "\nRETRYing...")
        Sys.sleep(1)
    }
} else {
    nc_retry <- F
}
debug: nc_retry <- F
debug: (while) nc_retry
debug: i_req <- i_req + 1
debug: (while) i_req <= n_reqs
debug: ncs <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size > 
    0), nc)
debug: r <- terra::rast(ncs)
debug: stopifnot(all(class(terra::time(r)) %in% c("POSIXct", "POSIXt")))
debug: idx <- dplyr::pull(dplyr::filter(dplyr::arrange(dplyr::tibble(idx = 1:terra::nlyr(r), 
    time = terra::time(r)), time), !duplicated(time)), idx)
debug: r <- terra::subset(r, idx)
debug: stopifnot(terra::crs(r, proj = T) == wgs84)
debug: if (mask_tif) r <- terra::mask(r, sf_zones)
debug: lyrs <- glue("{var}|{terra::time(r)}")
debug: if (length(dims_other) > 0 && !all(length(dims[dims_other]) == 
    1)) stop(glue("Other dimensions not yet supported: {paste(dims_other, collapse = ',')}"))
debug: names(r) <- lyrs
debug: if (!is.null(rast_tif)) {
    if (fs::file_exists(rast_tif)) {
        r_tmp_tif <- tempfile(fileext = ".tif")
        r_tmp <- c(rast(rast_tif), r)
        r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
        terra::writeRaster(r_tmp, r_tmp_tif)
        fs::file_delete(rast_tif)
        fs::file_move(r_tmp_tif, rast_tif)
        rm(r)
        rm(r_tmp)
    }
    else {
        terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
    }
    r <- terra::rast(rast_tif)
}
debug: if (fs::file_exists(rast_tif)) {
    r_tmp_tif <- tempfile(fileext = ".tif")
    r_tmp <- c(rast(rast_tif), r)
    r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
    terra::writeRaster(r_tmp, r_tmp_tif)
    fs::file_delete(rast_tif)
    fs::file_move(r_tmp_tif, rast_tif)
    rm(r)
    rm(r_tmp)
} else {
    terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
}
debug: terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
debug: r <- terra::rast(rast_tif)
debug: d_r <- mutate(tidyr::pivot_longer(sf::st_drop_geometry(sf::st_as_sf(terra::zonal(x = r, 
    z = terra::vect(dplyr::select(sf_zones, dplyr::all_of(fld_zones))), 
    fun = zonal_fun, exact = T, na.rm = T, as.polygons = T))), 
    cols = -dplyr::any_of(fld_zones), names_to = "lyr", values_to = zonal_fun), 
    time = readr::parse_datetime(str_replace(lyr, glue("{var}\\|(.*)"), 
        "\\1")))
debug: if (!is.null(zonal_csv)) write_csv(d_r, zonal_csv)
debug: write_csv(d_r, zonal_csv)
debug: if (!keep_nc) unlink(dir_nc, recursive = T)
debug: unlink(dir_nc, recursive = T)
debug: return(d_r)
Downloading 1 requests, up to 114 time slices each
Called from: extractr::ed_extract(ed, var = v, sf_zones = ply, bbox = bb, 
    mask_tif = F, rast_tif = glue("{dir_out}/{nms}/{yr}.tif"), 
    zonal_fun = "mean", zonal_csv = glue("{dir_out}/{nms}/{yr}.csv"), 
    dir_nc = glue("{dir_out}/{nms}/{yr}_nc"), keep_nc = F, n_max_vals_per_req = 1e+05, 
    time_min = time_min, time_max = time_max, verbose = T)
debug: while (i_req <= n_reqs) {
    i_t_beg <- (i_req - 1) * n_t_per_req + 1
    i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
    t_req <- times_todo[c(i_t_beg, i_t_end)]
    t_req_str <- format_ISO8601(t_req, usetz = "Z")
    if (verbose) 
        message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
    ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
        ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
        0), nc)
    unlink(ncs0)
    nc_retry <- T
    nc_n_try <- 1
    n_max_retries
    while (nc_retry) {
        res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
            url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
                bbox[["xmax"]]), latitude = c(bbox[["ymin"]], 
                bbox[["ymax"]]), time = t_req_str, fmt = "nc", 
            store = rerddap::disk(path = dir_nc)))
        if (inherits(res, "try-error")) {
            err <- attr(res, "condition")
            msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
            nc_n_try <- nc_n_try + 1
            if (nc_n_try > n_max_retries) {
                stop(msg)
            }
            else {
                message(msg, "\nRETRYing...")
                Sys.sleep(1)
            }
        }
        else {
            nc_retry <- F
        }
    }
    i_req <- i_req + 1
}
debug: i_t_beg <- (i_req - 1) * n_t_per_req + 1
debug: i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
debug: t_req <- times_todo[c(i_t_beg, i_t_end)]
debug: t_req_str <- format_ISO8601(t_req, usetz = "Z")
debug: if (verbose) message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
debug: message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
Fetching request 1 of 1 (2004-01-01 to 2004-12-01) ~ 19:41:26 UTC
debug: ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
    0), nc)
debug: unlink(ncs0)
debug: nc_retry <- T
debug: nc_n_try <- 1
debug: n_max_retries
debug: while (nc_retry) {
    res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
        url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
            bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
        time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
    if (inherits(res, "try-error")) {
        err <- attr(res, "condition")
        msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
        nc_n_try <- nc_n_try + 1
        if (nc_n_try > n_max_retries) {
            stop(msg)
        }
        else {
            message(msg, "\nRETRYing...")
            Sys.sleep(1)
        }
    }
    else {
        nc_retry <- F
    }
}
debug: res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
    url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
        bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
    time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
debug: if (inherits(res, "try-error")) {
    err <- attr(res, "condition")
    msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
    nc_n_try <- nc_n_try + 1
    if (nc_n_try > n_max_retries) {
        stop(msg)
    }
    else {
        message(msg, "\nRETRYing...")
        Sys.sleep(1)
    }
} else {
    nc_retry <- F
}
debug: nc_retry <- F
debug: (while) nc_retry
debug: i_req <- i_req + 1
debug: (while) i_req <= n_reqs
debug: ncs <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size > 
    0), nc)
debug: r <- terra::rast(ncs)
debug: stopifnot(all(class(terra::time(r)) %in% c("POSIXct", "POSIXt")))
debug: idx <- dplyr::pull(dplyr::filter(dplyr::arrange(dplyr::tibble(idx = 1:terra::nlyr(r), 
    time = terra::time(r)), time), !duplicated(time)), idx)
debug: r <- terra::subset(r, idx)
debug: stopifnot(terra::crs(r, proj = T) == wgs84)
debug: if (mask_tif) r <- terra::mask(r, sf_zones)
debug: lyrs <- glue("{var}|{terra::time(r)}")
debug: if (length(dims_other) > 0 && !all(length(dims[dims_other]) == 
    1)) stop(glue("Other dimensions not yet supported: {paste(dims_other, collapse = ',')}"))
debug: names(r) <- lyrs
debug: if (!is.null(rast_tif)) {
    if (fs::file_exists(rast_tif)) {
        r_tmp_tif <- tempfile(fileext = ".tif")
        r_tmp <- c(rast(rast_tif), r)
        r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
        terra::writeRaster(r_tmp, r_tmp_tif)
        fs::file_delete(rast_tif)
        fs::file_move(r_tmp_tif, rast_tif)
        rm(r)
        rm(r_tmp)
    }
    else {
        terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
    }
    r <- terra::rast(rast_tif)
}
debug: if (fs::file_exists(rast_tif)) {
    r_tmp_tif <- tempfile(fileext = ".tif")
    r_tmp <- c(rast(rast_tif), r)
    r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
    terra::writeRaster(r_tmp, r_tmp_tif)
    fs::file_delete(rast_tif)
    fs::file_move(r_tmp_tif, rast_tif)
    rm(r)
    rm(r_tmp)
} else {
    terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
}
debug: terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
debug: r <- terra::rast(rast_tif)
debug: d_r <- mutate(tidyr::pivot_longer(sf::st_drop_geometry(sf::st_as_sf(terra::zonal(x = r, 
    z = terra::vect(dplyr::select(sf_zones, dplyr::all_of(fld_zones))), 
    fun = zonal_fun, exact = T, na.rm = T, as.polygons = T))), 
    cols = -dplyr::any_of(fld_zones), names_to = "lyr", values_to = zonal_fun), 
    time = readr::parse_datetime(str_replace(lyr, glue("{var}\\|(.*)"), 
        "\\1")))
debug: if (!is.null(zonal_csv)) write_csv(d_r, zonal_csv)
debug: write_csv(d_r, zonal_csv)
debug: if (!keep_nc) unlink(dir_nc, recursive = T)
debug: unlink(dir_nc, recursive = T)
debug: return(d_r)
Downloading 1 requests, up to 114 time slices each
Called from: extractr::ed_extract(ed, var = v, sf_zones = ply, bbox = bb, 
    mask_tif = F, rast_tif = glue("{dir_out}/{nms}/{yr}.tif"), 
    zonal_fun = "mean", zonal_csv = glue("{dir_out}/{nms}/{yr}.csv"), 
    dir_nc = glue("{dir_out}/{nms}/{yr}_nc"), keep_nc = F, n_max_vals_per_req = 1e+05, 
    time_min = time_min, time_max = time_max, verbose = T)
debug: while (i_req <= n_reqs) {
    i_t_beg <- (i_req - 1) * n_t_per_req + 1
    i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
    t_req <- times_todo[c(i_t_beg, i_t_end)]
    t_req_str <- format_ISO8601(t_req, usetz = "Z")
    if (verbose) 
        message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
    ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
        ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
        0), nc)
    unlink(ncs0)
    nc_retry <- T
    nc_n_try <- 1
    n_max_retries
    while (nc_retry) {
        res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
            url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
                bbox[["xmax"]]), latitude = c(bbox[["ymin"]], 
                bbox[["ymax"]]), time = t_req_str, fmt = "nc", 
            store = rerddap::disk(path = dir_nc)))
        if (inherits(res, "try-error")) {
            err <- attr(res, "condition")
            msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
            nc_n_try <- nc_n_try + 1
            if (nc_n_try > n_max_retries) {
                stop(msg)
            }
            else {
                message(msg, "\nRETRYing...")
                Sys.sleep(1)
            }
        }
        else {
            nc_retry <- F
        }
    }
    i_req <- i_req + 1
}
debug: i_t_beg <- (i_req - 1) * n_t_per_req + 1
debug: i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
debug: t_req <- times_todo[c(i_t_beg, i_t_end)]
debug: t_req_str <- format_ISO8601(t_req, usetz = "Z")
debug: if (verbose) message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
debug: message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
Fetching request 1 of 1 (2005-01-01 to 2005-12-01) ~ 19:41:28 UTC
debug: ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
    0), nc)
debug: unlink(ncs0)
debug: nc_retry <- T
debug: nc_n_try <- 1
debug: n_max_retries
debug: while (nc_retry) {
    res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
        url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
            bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
        time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
    if (inherits(res, "try-error")) {
        err <- attr(res, "condition")
        msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
        nc_n_try <- nc_n_try + 1
        if (nc_n_try > n_max_retries) {
            stop(msg)
        }
        else {
            message(msg, "\nRETRYing...")
            Sys.sleep(1)
        }
    }
    else {
        nc_retry <- F
    }
}
debug: res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
    url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
        bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
    time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
debug: if (inherits(res, "try-error")) {
    err <- attr(res, "condition")
    msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
    nc_n_try <- nc_n_try + 1
    if (nc_n_try > n_max_retries) {
        stop(msg)
    }
    else {
        message(msg, "\nRETRYing...")
        Sys.sleep(1)
    }
} else {
    nc_retry <- F
}
debug: nc_retry <- F
debug: (while) nc_retry
debug: i_req <- i_req + 1
debug: (while) i_req <= n_reqs
debug: ncs <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size > 
    0), nc)
debug: r <- terra::rast(ncs)
debug: stopifnot(all(class(terra::time(r)) %in% c("POSIXct", "POSIXt")))
debug: idx <- dplyr::pull(dplyr::filter(dplyr::arrange(dplyr::tibble(idx = 1:terra::nlyr(r), 
    time = terra::time(r)), time), !duplicated(time)), idx)
debug: r <- terra::subset(r, idx)
debug: stopifnot(terra::crs(r, proj = T) == wgs84)
debug: if (mask_tif) r <- terra::mask(r, sf_zones)
debug: lyrs <- glue("{var}|{terra::time(r)}")
debug: if (length(dims_other) > 0 && !all(length(dims[dims_other]) == 
    1)) stop(glue("Other dimensions not yet supported: {paste(dims_other, collapse = ',')}"))
debug: names(r) <- lyrs
debug: if (!is.null(rast_tif)) {
    if (fs::file_exists(rast_tif)) {
        r_tmp_tif <- tempfile(fileext = ".tif")
        r_tmp <- c(rast(rast_tif), r)
        r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
        terra::writeRaster(r_tmp, r_tmp_tif)
        fs::file_delete(rast_tif)
        fs::file_move(r_tmp_tif, rast_tif)
        rm(r)
        rm(r_tmp)
    }
    else {
        terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
    }
    r <- terra::rast(rast_tif)
}
debug: if (fs::file_exists(rast_tif)) {
    r_tmp_tif <- tempfile(fileext = ".tif")
    r_tmp <- c(rast(rast_tif), r)
    r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
    terra::writeRaster(r_tmp, r_tmp_tif)
    fs::file_delete(rast_tif)
    fs::file_move(r_tmp_tif, rast_tif)
    rm(r)
    rm(r_tmp)
} else {
    terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
}
debug: terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
debug: r <- terra::rast(rast_tif)
debug: d_r <- mutate(tidyr::pivot_longer(sf::st_drop_geometry(sf::st_as_sf(terra::zonal(x = r, 
    z = terra::vect(dplyr::select(sf_zones, dplyr::all_of(fld_zones))), 
    fun = zonal_fun, exact = T, na.rm = T, as.polygons = T))), 
    cols = -dplyr::any_of(fld_zones), names_to = "lyr", values_to = zonal_fun), 
    time = readr::parse_datetime(str_replace(lyr, glue("{var}\\|(.*)"), 
        "\\1")))
debug: if (!is.null(zonal_csv)) write_csv(d_r, zonal_csv)
debug: write_csv(d_r, zonal_csv)
debug: if (!keep_nc) unlink(dir_nc, recursive = T)
debug: unlink(dir_nc, recursive = T)
debug: return(d_r)
Downloading 1 requests, up to 114 time slices each
Called from: extractr::ed_extract(ed, var = v, sf_zones = ply, bbox = bb, 
    mask_tif = F, rast_tif = glue("{dir_out}/{nms}/{yr}.tif"), 
    zonal_fun = "mean", zonal_csv = glue("{dir_out}/{nms}/{yr}.csv"), 
    dir_nc = glue("{dir_out}/{nms}/{yr}_nc"), keep_nc = F, n_max_vals_per_req = 1e+05, 
    time_min = time_min, time_max = time_max, verbose = T)
debug: while (i_req <= n_reqs) {
    i_t_beg <- (i_req - 1) * n_t_per_req + 1
    i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
    t_req <- times_todo[c(i_t_beg, i_t_end)]
    t_req_str <- format_ISO8601(t_req, usetz = "Z")
    if (verbose) 
        message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
    ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
        ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
        0), nc)
    unlink(ncs0)
    nc_retry <- T
    nc_n_try <- 1
    n_max_retries
    while (nc_retry) {
        res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
            url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
                bbox[["xmax"]]), latitude = c(bbox[["ymin"]], 
                bbox[["ymax"]]), time = t_req_str, fmt = "nc", 
            store = rerddap::disk(path = dir_nc)))
        if (inherits(res, "try-error")) {
            err <- attr(res, "condition")
            msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
            nc_n_try <- nc_n_try + 1
            if (nc_n_try > n_max_retries) {
                stop(msg)
            }
            else {
                message(msg, "\nRETRYing...")
                Sys.sleep(1)
            }
        }
        else {
            nc_retry <- F
        }
    }
    i_req <- i_req + 1
}
debug: i_t_beg <- (i_req - 1) * n_t_per_req + 1
debug: i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
debug: t_req <- times_todo[c(i_t_beg, i_t_end)]
debug: t_req_str <- format_ISO8601(t_req, usetz = "Z")
debug: if (verbose) message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
debug: message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
Fetching request 1 of 1 (2006-01-01 to 2006-12-01) ~ 19:41:30 UTC
debug: ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
    0), nc)
debug: unlink(ncs0)
debug: nc_retry <- T
debug: nc_n_try <- 1
debug: n_max_retries
debug: while (nc_retry) {
    res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
        url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
            bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
        time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
    if (inherits(res, "try-error")) {
        err <- attr(res, "condition")
        msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
        nc_n_try <- nc_n_try + 1
        if (nc_n_try > n_max_retries) {
            stop(msg)
        }
        else {
            message(msg, "\nRETRYing...")
            Sys.sleep(1)
        }
    }
    else {
        nc_retry <- F
    }
}
debug: res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
    url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
        bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
    time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
debug: if (inherits(res, "try-error")) {
    err <- attr(res, "condition")
    msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
    nc_n_try <- nc_n_try + 1
    if (nc_n_try > n_max_retries) {
        stop(msg)
    }
    else {
        message(msg, "\nRETRYing...")
        Sys.sleep(1)
    }
} else {
    nc_retry <- F
}
debug: nc_retry <- F
debug: (while) nc_retry
debug: i_req <- i_req + 1
debug: (while) i_req <= n_reqs
debug: ncs <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size > 
    0), nc)
debug: r <- terra::rast(ncs)
debug: stopifnot(all(class(terra::time(r)) %in% c("POSIXct", "POSIXt")))
debug: idx <- dplyr::pull(dplyr::filter(dplyr::arrange(dplyr::tibble(idx = 1:terra::nlyr(r), 
    time = terra::time(r)), time), !duplicated(time)), idx)
debug: r <- terra::subset(r, idx)
debug: stopifnot(terra::crs(r, proj = T) == wgs84)
debug: if (mask_tif) r <- terra::mask(r, sf_zones)
debug: lyrs <- glue("{var}|{terra::time(r)}")
debug: if (length(dims_other) > 0 && !all(length(dims[dims_other]) == 
    1)) stop(glue("Other dimensions not yet supported: {paste(dims_other, collapse = ',')}"))
debug: names(r) <- lyrs
debug: if (!is.null(rast_tif)) {
    if (fs::file_exists(rast_tif)) {
        r_tmp_tif <- tempfile(fileext = ".tif")
        r_tmp <- c(rast(rast_tif), r)
        r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
        terra::writeRaster(r_tmp, r_tmp_tif)
        fs::file_delete(rast_tif)
        fs::file_move(r_tmp_tif, rast_tif)
        rm(r)
        rm(r_tmp)
    }
    else {
        terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
    }
    r <- terra::rast(rast_tif)
}
debug: if (fs::file_exists(rast_tif)) {
    r_tmp_tif <- tempfile(fileext = ".tif")
    r_tmp <- c(rast(rast_tif), r)
    r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
    terra::writeRaster(r_tmp, r_tmp_tif)
    fs::file_delete(rast_tif)
    fs::file_move(r_tmp_tif, rast_tif)
    rm(r)
    rm(r_tmp)
} else {
    terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
}
debug: terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
debug: r <- terra::rast(rast_tif)
debug: d_r <- mutate(tidyr::pivot_longer(sf::st_drop_geometry(sf::st_as_sf(terra::zonal(x = r, 
    z = terra::vect(dplyr::select(sf_zones, dplyr::all_of(fld_zones))), 
    fun = zonal_fun, exact = T, na.rm = T, as.polygons = T))), 
    cols = -dplyr::any_of(fld_zones), names_to = "lyr", values_to = zonal_fun), 
    time = readr::parse_datetime(str_replace(lyr, glue("{var}\\|(.*)"), 
        "\\1")))
debug: if (!is.null(zonal_csv)) write_csv(d_r, zonal_csv)
debug: write_csv(d_r, zonal_csv)
debug: if (!keep_nc) unlink(dir_nc, recursive = T)
debug: unlink(dir_nc, recursive = T)
debug: return(d_r)
Downloading 1 requests, up to 114 time slices each
Called from: extractr::ed_extract(ed, var = v, sf_zones = ply, bbox = bb, 
    mask_tif = F, rast_tif = glue("{dir_out}/{nms}/{yr}.tif"), 
    zonal_fun = "mean", zonal_csv = glue("{dir_out}/{nms}/{yr}.csv"), 
    dir_nc = glue("{dir_out}/{nms}/{yr}_nc"), keep_nc = F, n_max_vals_per_req = 1e+05, 
    time_min = time_min, time_max = time_max, verbose = T)
debug: while (i_req <= n_reqs) {
    i_t_beg <- (i_req - 1) * n_t_per_req + 1
    i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
    t_req <- times_todo[c(i_t_beg, i_t_end)]
    t_req_str <- format_ISO8601(t_req, usetz = "Z")
    if (verbose) 
        message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
    ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
        ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
        0), nc)
    unlink(ncs0)
    nc_retry <- T
    nc_n_try <- 1
    n_max_retries
    while (nc_retry) {
        res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
            url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
                bbox[["xmax"]]), latitude = c(bbox[["ymin"]], 
                bbox[["ymax"]]), time = t_req_str, fmt = "nc", 
            store = rerddap::disk(path = dir_nc)))
        if (inherits(res, "try-error")) {
            err <- attr(res, "condition")
            msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
            nc_n_try <- nc_n_try + 1
            if (nc_n_try > n_max_retries) {
                stop(msg)
            }
            else {
                message(msg, "\nRETRYing...")
                Sys.sleep(1)
            }
        }
        else {
            nc_retry <- F
        }
    }
    i_req <- i_req + 1
}
debug: i_t_beg <- (i_req - 1) * n_t_per_req + 1
debug: i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
debug: t_req <- times_todo[c(i_t_beg, i_t_end)]
debug: t_req_str <- format_ISO8601(t_req, usetz = "Z")
debug: if (verbose) message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
debug: message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
Fetching request 1 of 1 (2007-01-01 to 2007-12-01) ~ 19:41:32 UTC
debug: ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
    0), nc)
debug: unlink(ncs0)
debug: nc_retry <- T
debug: nc_n_try <- 1
debug: n_max_retries
debug: while (nc_retry) {
    res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
        url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
            bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
        time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
    if (inherits(res, "try-error")) {
        err <- attr(res, "condition")
        msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
        nc_n_try <- nc_n_try + 1
        if (nc_n_try > n_max_retries) {
            stop(msg)
        }
        else {
            message(msg, "\nRETRYing...")
            Sys.sleep(1)
        }
    }
    else {
        nc_retry <- F
    }
}
debug: res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
    url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
        bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
    time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
debug: if (inherits(res, "try-error")) {
    err <- attr(res, "condition")
    msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
    nc_n_try <- nc_n_try + 1
    if (nc_n_try > n_max_retries) {
        stop(msg)
    }
    else {
        message(msg, "\nRETRYing...")
        Sys.sleep(1)
    }
} else {
    nc_retry <- F
}
debug: nc_retry <- F
debug: (while) nc_retry
debug: i_req <- i_req + 1
debug: (while) i_req <= n_reqs
debug: ncs <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size > 
    0), nc)
debug: r <- terra::rast(ncs)
debug: stopifnot(all(class(terra::time(r)) %in% c("POSIXct", "POSIXt")))
debug: idx <- dplyr::pull(dplyr::filter(dplyr::arrange(dplyr::tibble(idx = 1:terra::nlyr(r), 
    time = terra::time(r)), time), !duplicated(time)), idx)
debug: r <- terra::subset(r, idx)
debug: stopifnot(terra::crs(r, proj = T) == wgs84)
debug: if (mask_tif) r <- terra::mask(r, sf_zones)
debug: lyrs <- glue("{var}|{terra::time(r)}")
debug: if (length(dims_other) > 0 && !all(length(dims[dims_other]) == 
    1)) stop(glue("Other dimensions not yet supported: {paste(dims_other, collapse = ',')}"))
debug: names(r) <- lyrs
debug: if (!is.null(rast_tif)) {
    if (fs::file_exists(rast_tif)) {
        r_tmp_tif <- tempfile(fileext = ".tif")
        r_tmp <- c(rast(rast_tif), r)
        r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
        terra::writeRaster(r_tmp, r_tmp_tif)
        fs::file_delete(rast_tif)
        fs::file_move(r_tmp_tif, rast_tif)
        rm(r)
        rm(r_tmp)
    }
    else {
        terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
    }
    r <- terra::rast(rast_tif)
}
debug: if (fs::file_exists(rast_tif)) {
    r_tmp_tif <- tempfile(fileext = ".tif")
    r_tmp <- c(rast(rast_tif), r)
    r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
    terra::writeRaster(r_tmp, r_tmp_tif)
    fs::file_delete(rast_tif)
    fs::file_move(r_tmp_tif, rast_tif)
    rm(r)
    rm(r_tmp)
} else {
    terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
}
debug: terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
debug: r <- terra::rast(rast_tif)
debug: d_r <- mutate(tidyr::pivot_longer(sf::st_drop_geometry(sf::st_as_sf(terra::zonal(x = r, 
    z = terra::vect(dplyr::select(sf_zones, dplyr::all_of(fld_zones))), 
    fun = zonal_fun, exact = T, na.rm = T, as.polygons = T))), 
    cols = -dplyr::any_of(fld_zones), names_to = "lyr", values_to = zonal_fun), 
    time = readr::parse_datetime(str_replace(lyr, glue("{var}\\|(.*)"), 
        "\\1")))
debug: if (!is.null(zonal_csv)) write_csv(d_r, zonal_csv)
debug: write_csv(d_r, zonal_csv)
debug: if (!keep_nc) unlink(dir_nc, recursive = T)
debug: unlink(dir_nc, recursive = T)
debug: return(d_r)
Downloading 1 requests, up to 114 time slices each
Called from: extractr::ed_extract(ed, var = v, sf_zones = ply, bbox = bb, 
    mask_tif = F, rast_tif = glue("{dir_out}/{nms}/{yr}.tif"), 
    zonal_fun = "mean", zonal_csv = glue("{dir_out}/{nms}/{yr}.csv"), 
    dir_nc = glue("{dir_out}/{nms}/{yr}_nc"), keep_nc = F, n_max_vals_per_req = 1e+05, 
    time_min = time_min, time_max = time_max, verbose = T)
debug: while (i_req <= n_reqs) {
    i_t_beg <- (i_req - 1) * n_t_per_req + 1
    i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
    t_req <- times_todo[c(i_t_beg, i_t_end)]
    t_req_str <- format_ISO8601(t_req, usetz = "Z")
    if (verbose) 
        message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
    ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
        ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
        0), nc)
    unlink(ncs0)
    nc_retry <- T
    nc_n_try <- 1
    n_max_retries
    while (nc_retry) {
        res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
            url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
                bbox[["xmax"]]), latitude = c(bbox[["ymin"]], 
                bbox[["ymax"]]), time = t_req_str, fmt = "nc", 
            store = rerddap::disk(path = dir_nc)))
        if (inherits(res, "try-error")) {
            err <- attr(res, "condition")
            msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
            nc_n_try <- nc_n_try + 1
            if (nc_n_try > n_max_retries) {
                stop(msg)
            }
            else {
                message(msg, "\nRETRYing...")
                Sys.sleep(1)
            }
        }
        else {
            nc_retry <- F
        }
    }
    i_req <- i_req + 1
}
debug: i_t_beg <- (i_req - 1) * n_t_per_req + 1
debug: i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
debug: t_req <- times_todo[c(i_t_beg, i_t_end)]
debug: t_req_str <- format_ISO8601(t_req, usetz = "Z")
debug: if (verbose) message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
debug: message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
Fetching request 1 of 1 (2008-01-01 to 2008-12-01) ~ 19:41:34 UTC
debug: ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
    0), nc)
debug: unlink(ncs0)
debug: nc_retry <- T
debug: nc_n_try <- 1
debug: n_max_retries
debug: while (nc_retry) {
    res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
        url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
            bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
        time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
    if (inherits(res, "try-error")) {
        err <- attr(res, "condition")
        msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
        nc_n_try <- nc_n_try + 1
        if (nc_n_try > n_max_retries) {
            stop(msg)
        }
        else {
            message(msg, "\nRETRYing...")
            Sys.sleep(1)
        }
    }
    else {
        nc_retry <- F
    }
}
debug: res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
    url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
        bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
    time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
debug: if (inherits(res, "try-error")) {
    err <- attr(res, "condition")
    msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
    nc_n_try <- nc_n_try + 1
    if (nc_n_try > n_max_retries) {
        stop(msg)
    }
    else {
        message(msg, "\nRETRYing...")
        Sys.sleep(1)
    }
} else {
    nc_retry <- F
}
debug: nc_retry <- F
debug: (while) nc_retry
debug: i_req <- i_req + 1
debug: (while) i_req <= n_reqs
debug: ncs <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size > 
    0), nc)
debug: r <- terra::rast(ncs)
debug: stopifnot(all(class(terra::time(r)) %in% c("POSIXct", "POSIXt")))
debug: idx <- dplyr::pull(dplyr::filter(dplyr::arrange(dplyr::tibble(idx = 1:terra::nlyr(r), 
    time = terra::time(r)), time), !duplicated(time)), idx)
debug: r <- terra::subset(r, idx)
debug: stopifnot(terra::crs(r, proj = T) == wgs84)
debug: if (mask_tif) r <- terra::mask(r, sf_zones)
debug: lyrs <- glue("{var}|{terra::time(r)}")
debug: if (length(dims_other) > 0 && !all(length(dims[dims_other]) == 
    1)) stop(glue("Other dimensions not yet supported: {paste(dims_other, collapse = ',')}"))
debug: names(r) <- lyrs
debug: if (!is.null(rast_tif)) {
    if (fs::file_exists(rast_tif)) {
        r_tmp_tif <- tempfile(fileext = ".tif")
        r_tmp <- c(rast(rast_tif), r)
        r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
        terra::writeRaster(r_tmp, r_tmp_tif)
        fs::file_delete(rast_tif)
        fs::file_move(r_tmp_tif, rast_tif)
        rm(r)
        rm(r_tmp)
    }
    else {
        terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
    }
    r <- terra::rast(rast_tif)
}
debug: if (fs::file_exists(rast_tif)) {
    r_tmp_tif <- tempfile(fileext = ".tif")
    r_tmp <- c(rast(rast_tif), r)
    r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
    terra::writeRaster(r_tmp, r_tmp_tif)
    fs::file_delete(rast_tif)
    fs::file_move(r_tmp_tif, rast_tif)
    rm(r)
    rm(r_tmp)
} else {
    terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
}
debug: terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
debug: r <- terra::rast(rast_tif)
debug: d_r <- mutate(tidyr::pivot_longer(sf::st_drop_geometry(sf::st_as_sf(terra::zonal(x = r, 
    z = terra::vect(dplyr::select(sf_zones, dplyr::all_of(fld_zones))), 
    fun = zonal_fun, exact = T, na.rm = T, as.polygons = T))), 
    cols = -dplyr::any_of(fld_zones), names_to = "lyr", values_to = zonal_fun), 
    time = readr::parse_datetime(str_replace(lyr, glue("{var}\\|(.*)"), 
        "\\1")))
debug: if (!is.null(zonal_csv)) write_csv(d_r, zonal_csv)
debug: write_csv(d_r, zonal_csv)
debug: if (!keep_nc) unlink(dir_nc, recursive = T)
debug: unlink(dir_nc, recursive = T)
debug: return(d_r)
Downloading 1 requests, up to 114 time slices each
Called from: extractr::ed_extract(ed, var = v, sf_zones = ply, bbox = bb, 
    mask_tif = F, rast_tif = glue("{dir_out}/{nms}/{yr}.tif"), 
    zonal_fun = "mean", zonal_csv = glue("{dir_out}/{nms}/{yr}.csv"), 
    dir_nc = glue("{dir_out}/{nms}/{yr}_nc"), keep_nc = F, n_max_vals_per_req = 1e+05, 
    time_min = time_min, time_max = time_max, verbose = T)
debug: while (i_req <= n_reqs) {
    i_t_beg <- (i_req - 1) * n_t_per_req + 1
    i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
    t_req <- times_todo[c(i_t_beg, i_t_end)]
    t_req_str <- format_ISO8601(t_req, usetz = "Z")
    if (verbose) 
        message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
    ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
        ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
        0), nc)
    unlink(ncs0)
    nc_retry <- T
    nc_n_try <- 1
    n_max_retries
    while (nc_retry) {
        res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
            url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
                bbox[["xmax"]]), latitude = c(bbox[["ymin"]], 
                bbox[["ymax"]]), time = t_req_str, fmt = "nc", 
            store = rerddap::disk(path = dir_nc)))
        if (inherits(res, "try-error")) {
            err <- attr(res, "condition")
            msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
            nc_n_try <- nc_n_try + 1
            if (nc_n_try > n_max_retries) {
                stop(msg)
            }
            else {
                message(msg, "\nRETRYing...")
                Sys.sleep(1)
            }
        }
        else {
            nc_retry <- F
        }
    }
    i_req <- i_req + 1
}
debug: i_t_beg <- (i_req - 1) * n_t_per_req + 1
debug: i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
debug: t_req <- times_todo[c(i_t_beg, i_t_end)]
debug: t_req_str <- format_ISO8601(t_req, usetz = "Z")
debug: if (verbose) message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
debug: message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
Fetching request 1 of 1 (2009-01-01 to 2009-12-01) ~ 19:41:36 UTC
debug: ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
    0), nc)
debug: unlink(ncs0)
debug: nc_retry <- T
debug: nc_n_try <- 1
debug: n_max_retries
debug: while (nc_retry) {
    res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
        url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
            bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
        time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
    if (inherits(res, "try-error")) {
        err <- attr(res, "condition")
        msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
        nc_n_try <- nc_n_try + 1
        if (nc_n_try > n_max_retries) {
            stop(msg)
        }
        else {
            message(msg, "\nRETRYing...")
            Sys.sleep(1)
        }
    }
    else {
        nc_retry <- F
    }
}
debug: res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
    url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
        bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
    time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
debug: if (inherits(res, "try-error")) {
    err <- attr(res, "condition")
    msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
    nc_n_try <- nc_n_try + 1
    if (nc_n_try > n_max_retries) {
        stop(msg)
    }
    else {
        message(msg, "\nRETRYing...")
        Sys.sleep(1)
    }
} else {
    nc_retry <- F
}
debug: nc_retry <- F
debug: (while) nc_retry
debug: i_req <- i_req + 1
debug: (while) i_req <= n_reqs
debug: ncs <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size > 
    0), nc)
debug: r <- terra::rast(ncs)
debug: stopifnot(all(class(terra::time(r)) %in% c("POSIXct", "POSIXt")))
debug: idx <- dplyr::pull(dplyr::filter(dplyr::arrange(dplyr::tibble(idx = 1:terra::nlyr(r), 
    time = terra::time(r)), time), !duplicated(time)), idx)
debug: r <- terra::subset(r, idx)
debug: stopifnot(terra::crs(r, proj = T) == wgs84)
debug: if (mask_tif) r <- terra::mask(r, sf_zones)
debug: lyrs <- glue("{var}|{terra::time(r)}")
debug: if (length(dims_other) > 0 && !all(length(dims[dims_other]) == 
    1)) stop(glue("Other dimensions not yet supported: {paste(dims_other, collapse = ',')}"))
debug: names(r) <- lyrs
debug: if (!is.null(rast_tif)) {
    if (fs::file_exists(rast_tif)) {
        r_tmp_tif <- tempfile(fileext = ".tif")
        r_tmp <- c(rast(rast_tif), r)
        r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
        terra::writeRaster(r_tmp, r_tmp_tif)
        fs::file_delete(rast_tif)
        fs::file_move(r_tmp_tif, rast_tif)
        rm(r)
        rm(r_tmp)
    }
    else {
        terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
    }
    r <- terra::rast(rast_tif)
}
debug: if (fs::file_exists(rast_tif)) {
    r_tmp_tif <- tempfile(fileext = ".tif")
    r_tmp <- c(rast(rast_tif), r)
    r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
    terra::writeRaster(r_tmp, r_tmp_tif)
    fs::file_delete(rast_tif)
    fs::file_move(r_tmp_tif, rast_tif)
    rm(r)
    rm(r_tmp)
} else {
    terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
}
debug: terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
debug: r <- terra::rast(rast_tif)
debug: d_r <- mutate(tidyr::pivot_longer(sf::st_drop_geometry(sf::st_as_sf(terra::zonal(x = r, 
    z = terra::vect(dplyr::select(sf_zones, dplyr::all_of(fld_zones))), 
    fun = zonal_fun, exact = T, na.rm = T, as.polygons = T))), 
    cols = -dplyr::any_of(fld_zones), names_to = "lyr", values_to = zonal_fun), 
    time = readr::parse_datetime(str_replace(lyr, glue("{var}\\|(.*)"), 
        "\\1")))
debug: if (!is.null(zonal_csv)) write_csv(d_r, zonal_csv)
debug: write_csv(d_r, zonal_csv)
debug: if (!keep_nc) unlink(dir_nc, recursive = T)
debug: unlink(dir_nc, recursive = T)
debug: return(d_r)
Downloading 1 requests, up to 114 time slices each
Called from: extractr::ed_extract(ed, var = v, sf_zones = ply, bbox = bb, 
    mask_tif = F, rast_tif = glue("{dir_out}/{nms}/{yr}.tif"), 
    zonal_fun = "mean", zonal_csv = glue("{dir_out}/{nms}/{yr}.csv"), 
    dir_nc = glue("{dir_out}/{nms}/{yr}_nc"), keep_nc = F, n_max_vals_per_req = 1e+05, 
    time_min = time_min, time_max = time_max, verbose = T)
debug: while (i_req <= n_reqs) {
    i_t_beg <- (i_req - 1) * n_t_per_req + 1
    i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
    t_req <- times_todo[c(i_t_beg, i_t_end)]
    t_req_str <- format_ISO8601(t_req, usetz = "Z")
    if (verbose) 
        message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
    ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
        ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
        0), nc)
    unlink(ncs0)
    nc_retry <- T
    nc_n_try <- 1
    n_max_retries
    while (nc_retry) {
        res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
            url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
                bbox[["xmax"]]), latitude = c(bbox[["ymin"]], 
                bbox[["ymax"]]), time = t_req_str, fmt = "nc", 
            store = rerddap::disk(path = dir_nc)))
        if (inherits(res, "try-error")) {
            err <- attr(res, "condition")
            msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
            nc_n_try <- nc_n_try + 1
            if (nc_n_try > n_max_retries) {
                stop(msg)
            }
            else {
                message(msg, "\nRETRYing...")
                Sys.sleep(1)
            }
        }
        else {
            nc_retry <- F
        }
    }
    i_req <- i_req + 1
}
debug: i_t_beg <- (i_req - 1) * n_t_per_req + 1
debug: i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
debug: t_req <- times_todo[c(i_t_beg, i_t_end)]
debug: t_req_str <- format_ISO8601(t_req, usetz = "Z")
debug: if (verbose) message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
debug: message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
Fetching request 1 of 1 (2010-01-01 to 2010-12-01) ~ 19:41:38 UTC
debug: ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
    0), nc)
debug: unlink(ncs0)
debug: nc_retry <- T
debug: nc_n_try <- 1
debug: n_max_retries
debug: while (nc_retry) {
    res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
        url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
            bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
        time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
    if (inherits(res, "try-error")) {
        err <- attr(res, "condition")
        msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
        nc_n_try <- nc_n_try + 1
        if (nc_n_try > n_max_retries) {
            stop(msg)
        }
        else {
            message(msg, "\nRETRYing...")
            Sys.sleep(1)
        }
    }
    else {
        nc_retry <- F
    }
}
debug: res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
    url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
        bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
    time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
debug: if (inherits(res, "try-error")) {
    err <- attr(res, "condition")
    msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
    nc_n_try <- nc_n_try + 1
    if (nc_n_try > n_max_retries) {
        stop(msg)
    }
    else {
        message(msg, "\nRETRYing...")
        Sys.sleep(1)
    }
} else {
    nc_retry <- F
}
debug: nc_retry <- F
debug: (while) nc_retry
debug: i_req <- i_req + 1
debug: (while) i_req <= n_reqs
debug: ncs <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size > 
    0), nc)
debug: r <- terra::rast(ncs)
debug: stopifnot(all(class(terra::time(r)) %in% c("POSIXct", "POSIXt")))
debug: idx <- dplyr::pull(dplyr::filter(dplyr::arrange(dplyr::tibble(idx = 1:terra::nlyr(r), 
    time = terra::time(r)), time), !duplicated(time)), idx)
debug: r <- terra::subset(r, idx)
debug: stopifnot(terra::crs(r, proj = T) == wgs84)
debug: if (mask_tif) r <- terra::mask(r, sf_zones)
debug: lyrs <- glue("{var}|{terra::time(r)}")
debug: if (length(dims_other) > 0 && !all(length(dims[dims_other]) == 
    1)) stop(glue("Other dimensions not yet supported: {paste(dims_other, collapse = ',')}"))
debug: names(r) <- lyrs
debug: if (!is.null(rast_tif)) {
    if (fs::file_exists(rast_tif)) {
        r_tmp_tif <- tempfile(fileext = ".tif")
        r_tmp <- c(rast(rast_tif), r)
        r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
        terra::writeRaster(r_tmp, r_tmp_tif)
        fs::file_delete(rast_tif)
        fs::file_move(r_tmp_tif, rast_tif)
        rm(r)
        rm(r_tmp)
    }
    else {
        terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
    }
    r <- terra::rast(rast_tif)
}
debug: if (fs::file_exists(rast_tif)) {
    r_tmp_tif <- tempfile(fileext = ".tif")
    r_tmp <- c(rast(rast_tif), r)
    r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
    terra::writeRaster(r_tmp, r_tmp_tif)
    fs::file_delete(rast_tif)
    fs::file_move(r_tmp_tif, rast_tif)
    rm(r)
    rm(r_tmp)
} else {
    terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
}
debug: terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
debug: r <- terra::rast(rast_tif)
debug: d_r <- mutate(tidyr::pivot_longer(sf::st_drop_geometry(sf::st_as_sf(terra::zonal(x = r, 
    z = terra::vect(dplyr::select(sf_zones, dplyr::all_of(fld_zones))), 
    fun = zonal_fun, exact = T, na.rm = T, as.polygons = T))), 
    cols = -dplyr::any_of(fld_zones), names_to = "lyr", values_to = zonal_fun), 
    time = readr::parse_datetime(str_replace(lyr, glue("{var}\\|(.*)"), 
        "\\1")))
debug: if (!is.null(zonal_csv)) write_csv(d_r, zonal_csv)
debug: write_csv(d_r, zonal_csv)
debug: if (!keep_nc) unlink(dir_nc, recursive = T)
debug: unlink(dir_nc, recursive = T)
debug: return(d_r)
Downloading 1 requests, up to 114 time slices each
Called from: extractr::ed_extract(ed, var = v, sf_zones = ply, bbox = bb, 
    mask_tif = F, rast_tif = glue("{dir_out}/{nms}/{yr}.tif"), 
    zonal_fun = "mean", zonal_csv = glue("{dir_out}/{nms}/{yr}.csv"), 
    dir_nc = glue("{dir_out}/{nms}/{yr}_nc"), keep_nc = F, n_max_vals_per_req = 1e+05, 
    time_min = time_min, time_max = time_max, verbose = T)
debug: while (i_req <= n_reqs) {
    i_t_beg <- (i_req - 1) * n_t_per_req + 1
    i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
    t_req <- times_todo[c(i_t_beg, i_t_end)]
    t_req_str <- format_ISO8601(t_req, usetz = "Z")
    if (verbose) 
        message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
    ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
        ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
        0), nc)
    unlink(ncs0)
    nc_retry <- T
    nc_n_try <- 1
    n_max_retries
    while (nc_retry) {
        res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
            url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
                bbox[["xmax"]]), latitude = c(bbox[["ymin"]], 
                bbox[["ymax"]]), time = t_req_str, fmt = "nc", 
            store = rerddap::disk(path = dir_nc)))
        if (inherits(res, "try-error")) {
            err <- attr(res, "condition")
            msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
            nc_n_try <- nc_n_try + 1
            if (nc_n_try > n_max_retries) {
                stop(msg)
            }
            else {
                message(msg, "\nRETRYing...")
                Sys.sleep(1)
            }
        }
        else {
            nc_retry <- F
        }
    }
    i_req <- i_req + 1
}
debug: i_t_beg <- (i_req - 1) * n_t_per_req + 1
debug: i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
debug: t_req <- times_todo[c(i_t_beg, i_t_end)]
debug: t_req_str <- format_ISO8601(t_req, usetz = "Z")
debug: if (verbose) message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
debug: message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
Fetching request 1 of 1 (2011-01-01 to 2011-12-01) ~ 19:41:41 UTC
debug: ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
    0), nc)
debug: unlink(ncs0)
debug: nc_retry <- T
debug: nc_n_try <- 1
debug: n_max_retries
debug: while (nc_retry) {
    res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
        url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
            bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
        time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
    if (inherits(res, "try-error")) {
        err <- attr(res, "condition")
        msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
        nc_n_try <- nc_n_try + 1
        if (nc_n_try > n_max_retries) {
            stop(msg)
        }
        else {
            message(msg, "\nRETRYing...")
            Sys.sleep(1)
        }
    }
    else {
        nc_retry <- F
    }
}
debug: res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
    url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
        bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
    time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
debug: if (inherits(res, "try-error")) {
    err <- attr(res, "condition")
    msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
    nc_n_try <- nc_n_try + 1
    if (nc_n_try > n_max_retries) {
        stop(msg)
    }
    else {
        message(msg, "\nRETRYing...")
        Sys.sleep(1)
    }
} else {
    nc_retry <- F
}
debug: nc_retry <- F
debug: (while) nc_retry
debug: i_req <- i_req + 1
debug: (while) i_req <= n_reqs
debug: ncs <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size > 
    0), nc)
debug: r <- terra::rast(ncs)
debug: stopifnot(all(class(terra::time(r)) %in% c("POSIXct", "POSIXt")))
debug: idx <- dplyr::pull(dplyr::filter(dplyr::arrange(dplyr::tibble(idx = 1:terra::nlyr(r), 
    time = terra::time(r)), time), !duplicated(time)), idx)
debug: r <- terra::subset(r, idx)
debug: stopifnot(terra::crs(r, proj = T) == wgs84)
debug: if (mask_tif) r <- terra::mask(r, sf_zones)
debug: lyrs <- glue("{var}|{terra::time(r)}")
debug: if (length(dims_other) > 0 && !all(length(dims[dims_other]) == 
    1)) stop(glue("Other dimensions not yet supported: {paste(dims_other, collapse = ',')}"))
debug: names(r) <- lyrs
debug: if (!is.null(rast_tif)) {
    if (fs::file_exists(rast_tif)) {
        r_tmp_tif <- tempfile(fileext = ".tif")
        r_tmp <- c(rast(rast_tif), r)
        r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
        terra::writeRaster(r_tmp, r_tmp_tif)
        fs::file_delete(rast_tif)
        fs::file_move(r_tmp_tif, rast_tif)
        rm(r)
        rm(r_tmp)
    }
    else {
        terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
    }
    r <- terra::rast(rast_tif)
}
debug: if (fs::file_exists(rast_tif)) {
    r_tmp_tif <- tempfile(fileext = ".tif")
    r_tmp <- c(rast(rast_tif), r)
    r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
    terra::writeRaster(r_tmp, r_tmp_tif)
    fs::file_delete(rast_tif)
    fs::file_move(r_tmp_tif, rast_tif)
    rm(r)
    rm(r_tmp)
} else {
    terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
}
debug: terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
debug: r <- terra::rast(rast_tif)
debug: d_r <- mutate(tidyr::pivot_longer(sf::st_drop_geometry(sf::st_as_sf(terra::zonal(x = r, 
    z = terra::vect(dplyr::select(sf_zones, dplyr::all_of(fld_zones))), 
    fun = zonal_fun, exact = T, na.rm = T, as.polygons = T))), 
    cols = -dplyr::any_of(fld_zones), names_to = "lyr", values_to = zonal_fun), 
    time = readr::parse_datetime(str_replace(lyr, glue("{var}\\|(.*)"), 
        "\\1")))
debug: if (!is.null(zonal_csv)) write_csv(d_r, zonal_csv)
debug: write_csv(d_r, zonal_csv)
debug: if (!keep_nc) unlink(dir_nc, recursive = T)
debug: unlink(dir_nc, recursive = T)
debug: return(d_r)
Downloading 1 requests, up to 114 time slices each
Called from: extractr::ed_extract(ed, var = v, sf_zones = ply, bbox = bb, 
    mask_tif = F, rast_tif = glue("{dir_out}/{nms}/{yr}.tif"), 
    zonal_fun = "mean", zonal_csv = glue("{dir_out}/{nms}/{yr}.csv"), 
    dir_nc = glue("{dir_out}/{nms}/{yr}_nc"), keep_nc = F, n_max_vals_per_req = 1e+05, 
    time_min = time_min, time_max = time_max, verbose = T)
debug: while (i_req <= n_reqs) {
    i_t_beg <- (i_req - 1) * n_t_per_req + 1
    i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
    t_req <- times_todo[c(i_t_beg, i_t_end)]
    t_req_str <- format_ISO8601(t_req, usetz = "Z")
    if (verbose) 
        message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
    ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
        ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
        0), nc)
    unlink(ncs0)
    nc_retry <- T
    nc_n_try <- 1
    n_max_retries
    while (nc_retry) {
        res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
            url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
                bbox[["xmax"]]), latitude = c(bbox[["ymin"]], 
                bbox[["ymax"]]), time = t_req_str, fmt = "nc", 
            store = rerddap::disk(path = dir_nc)))
        if (inherits(res, "try-error")) {
            err <- attr(res, "condition")
            msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
            nc_n_try <- nc_n_try + 1
            if (nc_n_try > n_max_retries) {
                stop(msg)
            }
            else {
                message(msg, "\nRETRYing...")
                Sys.sleep(1)
            }
        }
        else {
            nc_retry <- F
        }
    }
    i_req <- i_req + 1
}
debug: i_t_beg <- (i_req - 1) * n_t_per_req + 1
debug: i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
debug: t_req <- times_todo[c(i_t_beg, i_t_end)]
debug: t_req_str <- format_ISO8601(t_req, usetz = "Z")
debug: if (verbose) message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
debug: message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
Fetching request 1 of 1 (2012-01-01 to 2012-12-01) ~ 19:41:43 UTC
debug: ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
    0), nc)
debug: unlink(ncs0)
debug: nc_retry <- T
debug: nc_n_try <- 1
debug: n_max_retries
debug: while (nc_retry) {
    res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
        url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
            bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
        time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
    if (inherits(res, "try-error")) {
        err <- attr(res, "condition")
        msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
        nc_n_try <- nc_n_try + 1
        if (nc_n_try > n_max_retries) {
            stop(msg)
        }
        else {
            message(msg, "\nRETRYing...")
            Sys.sleep(1)
        }
    }
    else {
        nc_retry <- F
    }
}
debug: res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
    url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
        bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
    time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
debug: if (inherits(res, "try-error")) {
    err <- attr(res, "condition")
    msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
    nc_n_try <- nc_n_try + 1
    if (nc_n_try > n_max_retries) {
        stop(msg)
    }
    else {
        message(msg, "\nRETRYing...")
        Sys.sleep(1)
    }
} else {
    nc_retry <- F
}
debug: nc_retry <- F
debug: (while) nc_retry
debug: i_req <- i_req + 1
debug: (while) i_req <= n_reqs
debug: ncs <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size > 
    0), nc)
debug: r <- terra::rast(ncs)
debug: stopifnot(all(class(terra::time(r)) %in% c("POSIXct", "POSIXt")))
debug: idx <- dplyr::pull(dplyr::filter(dplyr::arrange(dplyr::tibble(idx = 1:terra::nlyr(r), 
    time = terra::time(r)), time), !duplicated(time)), idx)
debug: r <- terra::subset(r, idx)
debug: stopifnot(terra::crs(r, proj = T) == wgs84)
debug: if (mask_tif) r <- terra::mask(r, sf_zones)
debug: lyrs <- glue("{var}|{terra::time(r)}")
debug: if (length(dims_other) > 0 && !all(length(dims[dims_other]) == 
    1)) stop(glue("Other dimensions not yet supported: {paste(dims_other, collapse = ',')}"))
debug: names(r) <- lyrs
debug: if (!is.null(rast_tif)) {
    if (fs::file_exists(rast_tif)) {
        r_tmp_tif <- tempfile(fileext = ".tif")
        r_tmp <- c(rast(rast_tif), r)
        r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
        terra::writeRaster(r_tmp, r_tmp_tif)
        fs::file_delete(rast_tif)
        fs::file_move(r_tmp_tif, rast_tif)
        rm(r)
        rm(r_tmp)
    }
    else {
        terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
    }
    r <- terra::rast(rast_tif)
}
debug: if (fs::file_exists(rast_tif)) {
    r_tmp_tif <- tempfile(fileext = ".tif")
    r_tmp <- c(rast(rast_tif), r)
    r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
    terra::writeRaster(r_tmp, r_tmp_tif)
    fs::file_delete(rast_tif)
    fs::file_move(r_tmp_tif, rast_tif)
    rm(r)
    rm(r_tmp)
} else {
    terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
}
debug: terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
debug: r <- terra::rast(rast_tif)
debug: d_r <- mutate(tidyr::pivot_longer(sf::st_drop_geometry(sf::st_as_sf(terra::zonal(x = r, 
    z = terra::vect(dplyr::select(sf_zones, dplyr::all_of(fld_zones))), 
    fun = zonal_fun, exact = T, na.rm = T, as.polygons = T))), 
    cols = -dplyr::any_of(fld_zones), names_to = "lyr", values_to = zonal_fun), 
    time = readr::parse_datetime(str_replace(lyr, glue("{var}\\|(.*)"), 
        "\\1")))
debug: if (!is.null(zonal_csv)) write_csv(d_r, zonal_csv)
debug: write_csv(d_r, zonal_csv)
debug: if (!keep_nc) unlink(dir_nc, recursive = T)
debug: unlink(dir_nc, recursive = T)
debug: return(d_r)
Downloading 1 requests, up to 114 time slices each
Called from: extractr::ed_extract(ed, var = v, sf_zones = ply, bbox = bb, 
    mask_tif = F, rast_tif = glue("{dir_out}/{nms}/{yr}.tif"), 
    zonal_fun = "mean", zonal_csv = glue("{dir_out}/{nms}/{yr}.csv"), 
    dir_nc = glue("{dir_out}/{nms}/{yr}_nc"), keep_nc = F, n_max_vals_per_req = 1e+05, 
    time_min = time_min, time_max = time_max, verbose = T)
debug: while (i_req <= n_reqs) {
    i_t_beg <- (i_req - 1) * n_t_per_req + 1
    i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
    t_req <- times_todo[c(i_t_beg, i_t_end)]
    t_req_str <- format_ISO8601(t_req, usetz = "Z")
    if (verbose) 
        message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
    ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
        ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
        0), nc)
    unlink(ncs0)
    nc_retry <- T
    nc_n_try <- 1
    n_max_retries
    while (nc_retry) {
        res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
            url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
                bbox[["xmax"]]), latitude = c(bbox[["ymin"]], 
                bbox[["ymax"]]), time = t_req_str, fmt = "nc", 
            store = rerddap::disk(path = dir_nc)))
        if (inherits(res, "try-error")) {
            err <- attr(res, "condition")
            msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
            nc_n_try <- nc_n_try + 1
            if (nc_n_try > n_max_retries) {
                stop(msg)
            }
            else {
                message(msg, "\nRETRYing...")
                Sys.sleep(1)
            }
        }
        else {
            nc_retry <- F
        }
    }
    i_req <- i_req + 1
}
debug: i_t_beg <- (i_req - 1) * n_t_per_req + 1
debug: i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
debug: t_req <- times_todo[c(i_t_beg, i_t_end)]
debug: t_req_str <- format_ISO8601(t_req, usetz = "Z")
debug: if (verbose) message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
debug: message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
Fetching request 1 of 1 (2013-01-01 to 2013-12-01) ~ 19:41:45 UTC
debug: ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
    0), nc)
debug: unlink(ncs0)
debug: nc_retry <- T
debug: nc_n_try <- 1
debug: n_max_retries
debug: while (nc_retry) {
    res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
        url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
            bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
        time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
    if (inherits(res, "try-error")) {
        err <- attr(res, "condition")
        msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
        nc_n_try <- nc_n_try + 1
        if (nc_n_try > n_max_retries) {
            stop(msg)
        }
        else {
            message(msg, "\nRETRYing...")
            Sys.sleep(1)
        }
    }
    else {
        nc_retry <- F
    }
}
debug: res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
    url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
        bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
    time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
debug: if (inherits(res, "try-error")) {
    err <- attr(res, "condition")
    msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
    nc_n_try <- nc_n_try + 1
    if (nc_n_try > n_max_retries) {
        stop(msg)
    }
    else {
        message(msg, "\nRETRYing...")
        Sys.sleep(1)
    }
} else {
    nc_retry <- F
}
debug: nc_retry <- F
debug: (while) nc_retry
debug: i_req <- i_req + 1
debug: (while) i_req <= n_reqs
debug: ncs <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size > 
    0), nc)
debug: r <- terra::rast(ncs)
debug: stopifnot(all(class(terra::time(r)) %in% c("POSIXct", "POSIXt")))
debug: idx <- dplyr::pull(dplyr::filter(dplyr::arrange(dplyr::tibble(idx = 1:terra::nlyr(r), 
    time = terra::time(r)), time), !duplicated(time)), idx)
debug: r <- terra::subset(r, idx)
debug: stopifnot(terra::crs(r, proj = T) == wgs84)
debug: if (mask_tif) r <- terra::mask(r, sf_zones)
debug: lyrs <- glue("{var}|{terra::time(r)}")
debug: if (length(dims_other) > 0 && !all(length(dims[dims_other]) == 
    1)) stop(glue("Other dimensions not yet supported: {paste(dims_other, collapse = ',')}"))
debug: names(r) <- lyrs
debug: if (!is.null(rast_tif)) {
    if (fs::file_exists(rast_tif)) {
        r_tmp_tif <- tempfile(fileext = ".tif")
        r_tmp <- c(rast(rast_tif), r)
        r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
        terra::writeRaster(r_tmp, r_tmp_tif)
        fs::file_delete(rast_tif)
        fs::file_move(r_tmp_tif, rast_tif)
        rm(r)
        rm(r_tmp)
    }
    else {
        terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
    }
    r <- terra::rast(rast_tif)
}
debug: if (fs::file_exists(rast_tif)) {
    r_tmp_tif <- tempfile(fileext = ".tif")
    r_tmp <- c(rast(rast_tif), r)
    r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
    terra::writeRaster(r_tmp, r_tmp_tif)
    fs::file_delete(rast_tif)
    fs::file_move(r_tmp_tif, rast_tif)
    rm(r)
    rm(r_tmp)
} else {
    terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
}
debug: terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
debug: r <- terra::rast(rast_tif)
debug: d_r <- mutate(tidyr::pivot_longer(sf::st_drop_geometry(sf::st_as_sf(terra::zonal(x = r, 
    z = terra::vect(dplyr::select(sf_zones, dplyr::all_of(fld_zones))), 
    fun = zonal_fun, exact = T, na.rm = T, as.polygons = T))), 
    cols = -dplyr::any_of(fld_zones), names_to = "lyr", values_to = zonal_fun), 
    time = readr::parse_datetime(str_replace(lyr, glue("{var}\\|(.*)"), 
        "\\1")))
debug: if (!is.null(zonal_csv)) write_csv(d_r, zonal_csv)
debug: write_csv(d_r, zonal_csv)
debug: if (!keep_nc) unlink(dir_nc, recursive = T)
debug: unlink(dir_nc, recursive = T)
debug: return(d_r)
Downloading 1 requests, up to 114 time slices each
Called from: extractr::ed_extract(ed, var = v, sf_zones = ply, bbox = bb, 
    mask_tif = F, rast_tif = glue("{dir_out}/{nms}/{yr}.tif"), 
    zonal_fun = "mean", zonal_csv = glue("{dir_out}/{nms}/{yr}.csv"), 
    dir_nc = glue("{dir_out}/{nms}/{yr}_nc"), keep_nc = F, n_max_vals_per_req = 1e+05, 
    time_min = time_min, time_max = time_max, verbose = T)
debug: while (i_req <= n_reqs) {
    i_t_beg <- (i_req - 1) * n_t_per_req + 1
    i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
    t_req <- times_todo[c(i_t_beg, i_t_end)]
    t_req_str <- format_ISO8601(t_req, usetz = "Z")
    if (verbose) 
        message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
    ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
        ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
        0), nc)
    unlink(ncs0)
    nc_retry <- T
    nc_n_try <- 1
    n_max_retries
    while (nc_retry) {
        res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
            url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
                bbox[["xmax"]]), latitude = c(bbox[["ymin"]], 
                bbox[["ymax"]]), time = t_req_str, fmt = "nc", 
            store = rerddap::disk(path = dir_nc)))
        if (inherits(res, "try-error")) {
            err <- attr(res, "condition")
            msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
            nc_n_try <- nc_n_try + 1
            if (nc_n_try > n_max_retries) {
                stop(msg)
            }
            else {
                message(msg, "\nRETRYing...")
                Sys.sleep(1)
            }
        }
        else {
            nc_retry <- F
        }
    }
    i_req <- i_req + 1
}
debug: i_t_beg <- (i_req - 1) * n_t_per_req + 1
debug: i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
debug: t_req <- times_todo[c(i_t_beg, i_t_end)]
debug: t_req_str <- format_ISO8601(t_req, usetz = "Z")
debug: if (verbose) message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
debug: message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
Fetching request 1 of 1 (2014-01-01 to 2014-12-01) ~ 19:41:47 UTC
debug: ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
    0), nc)
debug: unlink(ncs0)
debug: nc_retry <- T
debug: nc_n_try <- 1
debug: n_max_retries
debug: while (nc_retry) {
    res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
        url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
            bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
        time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
    if (inherits(res, "try-error")) {
        err <- attr(res, "condition")
        msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
        nc_n_try <- nc_n_try + 1
        if (nc_n_try > n_max_retries) {
            stop(msg)
        }
        else {
            message(msg, "\nRETRYing...")
            Sys.sleep(1)
        }
    }
    else {
        nc_retry <- F
    }
}
debug: res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
    url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
        bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
    time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
debug: if (inherits(res, "try-error")) {
    err <- attr(res, "condition")
    msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
    nc_n_try <- nc_n_try + 1
    if (nc_n_try > n_max_retries) {
        stop(msg)
    }
    else {
        message(msg, "\nRETRYing...")
        Sys.sleep(1)
    }
} else {
    nc_retry <- F
}
debug: nc_retry <- F
debug: (while) nc_retry
debug: i_req <- i_req + 1
debug: (while) i_req <= n_reqs
debug: ncs <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size > 
    0), nc)
debug: r <- terra::rast(ncs)
debug: stopifnot(all(class(terra::time(r)) %in% c("POSIXct", "POSIXt")))
debug: idx <- dplyr::pull(dplyr::filter(dplyr::arrange(dplyr::tibble(idx = 1:terra::nlyr(r), 
    time = terra::time(r)), time), !duplicated(time)), idx)
debug: r <- terra::subset(r, idx)
debug: stopifnot(terra::crs(r, proj = T) == wgs84)
debug: if (mask_tif) r <- terra::mask(r, sf_zones)
debug: lyrs <- glue("{var}|{terra::time(r)}")
debug: if (length(dims_other) > 0 && !all(length(dims[dims_other]) == 
    1)) stop(glue("Other dimensions not yet supported: {paste(dims_other, collapse = ',')}"))
debug: names(r) <- lyrs
debug: if (!is.null(rast_tif)) {
    if (fs::file_exists(rast_tif)) {
        r_tmp_tif <- tempfile(fileext = ".tif")
        r_tmp <- c(rast(rast_tif), r)
        r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
        terra::writeRaster(r_tmp, r_tmp_tif)
        fs::file_delete(rast_tif)
        fs::file_move(r_tmp_tif, rast_tif)
        rm(r)
        rm(r_tmp)
    }
    else {
        terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
    }
    r <- terra::rast(rast_tif)
}
debug: if (fs::file_exists(rast_tif)) {
    r_tmp_tif <- tempfile(fileext = ".tif")
    r_tmp <- c(rast(rast_tif), r)
    r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
    terra::writeRaster(r_tmp, r_tmp_tif)
    fs::file_delete(rast_tif)
    fs::file_move(r_tmp_tif, rast_tif)
    rm(r)
    rm(r_tmp)
} else {
    terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
}
debug: terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
debug: r <- terra::rast(rast_tif)
debug: d_r <- mutate(tidyr::pivot_longer(sf::st_drop_geometry(sf::st_as_sf(terra::zonal(x = r, 
    z = terra::vect(dplyr::select(sf_zones, dplyr::all_of(fld_zones))), 
    fun = zonal_fun, exact = T, na.rm = T, as.polygons = T))), 
    cols = -dplyr::any_of(fld_zones), names_to = "lyr", values_to = zonal_fun), 
    time = readr::parse_datetime(str_replace(lyr, glue("{var}\\|(.*)"), 
        "\\1")))
debug: if (!is.null(zonal_csv)) write_csv(d_r, zonal_csv)
debug: write_csv(d_r, zonal_csv)
debug: if (!keep_nc) unlink(dir_nc, recursive = T)
debug: unlink(dir_nc, recursive = T)
debug: return(d_r)
Downloading 1 requests, up to 114 time slices each
Called from: extractr::ed_extract(ed, var = v, sf_zones = ply, bbox = bb, 
    mask_tif = F, rast_tif = glue("{dir_out}/{nms}/{yr}.tif"), 
    zonal_fun = "mean", zonal_csv = glue("{dir_out}/{nms}/{yr}.csv"), 
    dir_nc = glue("{dir_out}/{nms}/{yr}_nc"), keep_nc = F, n_max_vals_per_req = 1e+05, 
    time_min = time_min, time_max = time_max, verbose = T)
debug: while (i_req <= n_reqs) {
    i_t_beg <- (i_req - 1) * n_t_per_req + 1
    i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
    t_req <- times_todo[c(i_t_beg, i_t_end)]
    t_req_str <- format_ISO8601(t_req, usetz = "Z")
    if (verbose) 
        message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
    ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
        ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
        0), nc)
    unlink(ncs0)
    nc_retry <- T
    nc_n_try <- 1
    n_max_retries
    while (nc_retry) {
        res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
            url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
                bbox[["xmax"]]), latitude = c(bbox[["ymin"]], 
                bbox[["ymax"]]), time = t_req_str, fmt = "nc", 
            store = rerddap::disk(path = dir_nc)))
        if (inherits(res, "try-error")) {
            err <- attr(res, "condition")
            msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
            nc_n_try <- nc_n_try + 1
            if (nc_n_try > n_max_retries) {
                stop(msg)
            }
            else {
                message(msg, "\nRETRYing...")
                Sys.sleep(1)
            }
        }
        else {
            nc_retry <- F
        }
    }
    i_req <- i_req + 1
}
debug: i_t_beg <- (i_req - 1) * n_t_per_req + 1
debug: i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
debug: t_req <- times_todo[c(i_t_beg, i_t_end)]
debug: t_req_str <- format_ISO8601(t_req, usetz = "Z")
debug: if (verbose) message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
debug: message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
Fetching request 1 of 1 (2015-01-01 to 2015-12-01) ~ 19:41:50 UTC
debug: ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
    0), nc)
debug: unlink(ncs0)
debug: nc_retry <- T
debug: nc_n_try <- 1
debug: n_max_retries
debug: while (nc_retry) {
    res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
        url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
            bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
        time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
    if (inherits(res, "try-error")) {
        err <- attr(res, "condition")
        msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
        nc_n_try <- nc_n_try + 1
        if (nc_n_try > n_max_retries) {
            stop(msg)
        }
        else {
            message(msg, "\nRETRYing...")
            Sys.sleep(1)
        }
    }
    else {
        nc_retry <- F
    }
}
debug: res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
    url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
        bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
    time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
debug: if (inherits(res, "try-error")) {
    err <- attr(res, "condition")
    msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
    nc_n_try <- nc_n_try + 1
    if (nc_n_try > n_max_retries) {
        stop(msg)
    }
    else {
        message(msg, "\nRETRYing...")
        Sys.sleep(1)
    }
} else {
    nc_retry <- F
}
debug: nc_retry <- F
debug: (while) nc_retry
debug: i_req <- i_req + 1
debug: (while) i_req <= n_reqs
debug: ncs <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size > 
    0), nc)
debug: r <- terra::rast(ncs)
debug: stopifnot(all(class(terra::time(r)) %in% c("POSIXct", "POSIXt")))
debug: idx <- dplyr::pull(dplyr::filter(dplyr::arrange(dplyr::tibble(idx = 1:terra::nlyr(r), 
    time = terra::time(r)), time), !duplicated(time)), idx)
debug: r <- terra::subset(r, idx)
debug: stopifnot(terra::crs(r, proj = T) == wgs84)
debug: if (mask_tif) r <- terra::mask(r, sf_zones)
debug: lyrs <- glue("{var}|{terra::time(r)}")
debug: if (length(dims_other) > 0 && !all(length(dims[dims_other]) == 
    1)) stop(glue("Other dimensions not yet supported: {paste(dims_other, collapse = ',')}"))
debug: names(r) <- lyrs
debug: if (!is.null(rast_tif)) {
    if (fs::file_exists(rast_tif)) {
        r_tmp_tif <- tempfile(fileext = ".tif")
        r_tmp <- c(rast(rast_tif), r)
        r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
        terra::writeRaster(r_tmp, r_tmp_tif)
        fs::file_delete(rast_tif)
        fs::file_move(r_tmp_tif, rast_tif)
        rm(r)
        rm(r_tmp)
    }
    else {
        terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
    }
    r <- terra::rast(rast_tif)
}
debug: if (fs::file_exists(rast_tif)) {
    r_tmp_tif <- tempfile(fileext = ".tif")
    r_tmp <- c(rast(rast_tif), r)
    r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
    terra::writeRaster(r_tmp, r_tmp_tif)
    fs::file_delete(rast_tif)
    fs::file_move(r_tmp_tif, rast_tif)
    rm(r)
    rm(r_tmp)
} else {
    terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
}
debug: terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
debug: r <- terra::rast(rast_tif)
debug: d_r <- mutate(tidyr::pivot_longer(sf::st_drop_geometry(sf::st_as_sf(terra::zonal(x = r, 
    z = terra::vect(dplyr::select(sf_zones, dplyr::all_of(fld_zones))), 
    fun = zonal_fun, exact = T, na.rm = T, as.polygons = T))), 
    cols = -dplyr::any_of(fld_zones), names_to = "lyr", values_to = zonal_fun), 
    time = readr::parse_datetime(str_replace(lyr, glue("{var}\\|(.*)"), 
        "\\1")))
debug: if (!is.null(zonal_csv)) write_csv(d_r, zonal_csv)
debug: write_csv(d_r, zonal_csv)
debug: if (!keep_nc) unlink(dir_nc, recursive = T)
debug: unlink(dir_nc, recursive = T)
debug: return(d_r)
Downloading 1 requests, up to 114 time slices each
Called from: extractr::ed_extract(ed, var = v, sf_zones = ply, bbox = bb, 
    mask_tif = F, rast_tif = glue("{dir_out}/{nms}/{yr}.tif"), 
    zonal_fun = "mean", zonal_csv = glue("{dir_out}/{nms}/{yr}.csv"), 
    dir_nc = glue("{dir_out}/{nms}/{yr}_nc"), keep_nc = F, n_max_vals_per_req = 1e+05, 
    time_min = time_min, time_max = time_max, verbose = T)
debug: while (i_req <= n_reqs) {
    i_t_beg <- (i_req - 1) * n_t_per_req + 1
    i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
    t_req <- times_todo[c(i_t_beg, i_t_end)]
    t_req_str <- format_ISO8601(t_req, usetz = "Z")
    if (verbose) 
        message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
    ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
        ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
        0), nc)
    unlink(ncs0)
    nc_retry <- T
    nc_n_try <- 1
    n_max_retries
    while (nc_retry) {
        res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
            url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
                bbox[["xmax"]]), latitude = c(bbox[["ymin"]], 
                bbox[["ymax"]]), time = t_req_str, fmt = "nc", 
            store = rerddap::disk(path = dir_nc)))
        if (inherits(res, "try-error")) {
            err <- attr(res, "condition")
            msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
            nc_n_try <- nc_n_try + 1
            if (nc_n_try > n_max_retries) {
                stop(msg)
            }
            else {
                message(msg, "\nRETRYing...")
                Sys.sleep(1)
            }
        }
        else {
            nc_retry <- F
        }
    }
    i_req <- i_req + 1
}
debug: i_t_beg <- (i_req - 1) * n_t_per_req + 1
debug: i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
debug: t_req <- times_todo[c(i_t_beg, i_t_end)]
debug: t_req_str <- format_ISO8601(t_req, usetz = "Z")
debug: if (verbose) message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
debug: message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
Fetching request 1 of 1 (2016-01-01 to 2016-12-01) ~ 19:41:52 UTC
debug: ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
    0), nc)
debug: unlink(ncs0)
debug: nc_retry <- T
debug: nc_n_try <- 1
debug: n_max_retries
debug: while (nc_retry) {
    res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
        url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
            bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
        time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
    if (inherits(res, "try-error")) {
        err <- attr(res, "condition")
        msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
        nc_n_try <- nc_n_try + 1
        if (nc_n_try > n_max_retries) {
            stop(msg)
        }
        else {
            message(msg, "\nRETRYing...")
            Sys.sleep(1)
        }
    }
    else {
        nc_retry <- F
    }
}
debug: res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
    url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
        bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
    time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
debug: if (inherits(res, "try-error")) {
    err <- attr(res, "condition")
    msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
    nc_n_try <- nc_n_try + 1
    if (nc_n_try > n_max_retries) {
        stop(msg)
    }
    else {
        message(msg, "\nRETRYing...")
        Sys.sleep(1)
    }
} else {
    nc_retry <- F
}
debug: nc_retry <- F
debug: (while) nc_retry
debug: i_req <- i_req + 1
debug: (while) i_req <= n_reqs
debug: ncs <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size > 
    0), nc)
debug: r <- terra::rast(ncs)
debug: stopifnot(all(class(terra::time(r)) %in% c("POSIXct", "POSIXt")))
debug: idx <- dplyr::pull(dplyr::filter(dplyr::arrange(dplyr::tibble(idx = 1:terra::nlyr(r), 
    time = terra::time(r)), time), !duplicated(time)), idx)
debug: r <- terra::subset(r, idx)
debug: stopifnot(terra::crs(r, proj = T) == wgs84)
debug: if (mask_tif) r <- terra::mask(r, sf_zones)
debug: lyrs <- glue("{var}|{terra::time(r)}")
debug: if (length(dims_other) > 0 && !all(length(dims[dims_other]) == 
    1)) stop(glue("Other dimensions not yet supported: {paste(dims_other, collapse = ',')}"))
debug: names(r) <- lyrs
debug: if (!is.null(rast_tif)) {
    if (fs::file_exists(rast_tif)) {
        r_tmp_tif <- tempfile(fileext = ".tif")
        r_tmp <- c(rast(rast_tif), r)
        r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
        terra::writeRaster(r_tmp, r_tmp_tif)
        fs::file_delete(rast_tif)
        fs::file_move(r_tmp_tif, rast_tif)
        rm(r)
        rm(r_tmp)
    }
    else {
        terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
    }
    r <- terra::rast(rast_tif)
}
debug: if (fs::file_exists(rast_tif)) {
    r_tmp_tif <- tempfile(fileext = ".tif")
    r_tmp <- c(rast(rast_tif), r)
    r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
    terra::writeRaster(r_tmp, r_tmp_tif)
    fs::file_delete(rast_tif)
    fs::file_move(r_tmp_tif, rast_tif)
    rm(r)
    rm(r_tmp)
} else {
    terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
}
debug: terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
debug: r <- terra::rast(rast_tif)
debug: d_r <- mutate(tidyr::pivot_longer(sf::st_drop_geometry(sf::st_as_sf(terra::zonal(x = r, 
    z = terra::vect(dplyr::select(sf_zones, dplyr::all_of(fld_zones))), 
    fun = zonal_fun, exact = T, na.rm = T, as.polygons = T))), 
    cols = -dplyr::any_of(fld_zones), names_to = "lyr", values_to = zonal_fun), 
    time = readr::parse_datetime(str_replace(lyr, glue("{var}\\|(.*)"), 
        "\\1")))
debug: if (!is.null(zonal_csv)) write_csv(d_r, zonal_csv)
debug: write_csv(d_r, zonal_csv)
debug: if (!keep_nc) unlink(dir_nc, recursive = T)
debug: unlink(dir_nc, recursive = T)
debug: return(d_r)
Downloading 1 requests, up to 114 time slices each
Called from: extractr::ed_extract(ed, var = v, sf_zones = ply, bbox = bb, 
    mask_tif = F, rast_tif = glue("{dir_out}/{nms}/{yr}.tif"), 
    zonal_fun = "mean", zonal_csv = glue("{dir_out}/{nms}/{yr}.csv"), 
    dir_nc = glue("{dir_out}/{nms}/{yr}_nc"), keep_nc = F, n_max_vals_per_req = 1e+05, 
    time_min = time_min, time_max = time_max, verbose = T)
debug: while (i_req <= n_reqs) {
    i_t_beg <- (i_req - 1) * n_t_per_req + 1
    i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
    t_req <- times_todo[c(i_t_beg, i_t_end)]
    t_req_str <- format_ISO8601(t_req, usetz = "Z")
    if (verbose) 
        message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
    ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
        ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
        0), nc)
    unlink(ncs0)
    nc_retry <- T
    nc_n_try <- 1
    n_max_retries
    while (nc_retry) {
        res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
            url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
                bbox[["xmax"]]), latitude = c(bbox[["ymin"]], 
                bbox[["ymax"]]), time = t_req_str, fmt = "nc", 
            store = rerddap::disk(path = dir_nc)))
        if (inherits(res, "try-error")) {
            err <- attr(res, "condition")
            msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
            nc_n_try <- nc_n_try + 1
            if (nc_n_try > n_max_retries) {
                stop(msg)
            }
            else {
                message(msg, "\nRETRYing...")
                Sys.sleep(1)
            }
        }
        else {
            nc_retry <- F
        }
    }
    i_req <- i_req + 1
}
debug: i_t_beg <- (i_req - 1) * n_t_per_req + 1
debug: i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
debug: t_req <- times_todo[c(i_t_beg, i_t_end)]
debug: t_req_str <- format_ISO8601(t_req, usetz = "Z")
debug: if (verbose) message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
debug: message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
Fetching request 1 of 1 (2017-01-01 to 2017-12-01) ~ 19:41:54 UTC
debug: ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
    0), nc)
debug: unlink(ncs0)
debug: nc_retry <- T
debug: nc_n_try <- 1
debug: n_max_retries
debug: while (nc_retry) {
    res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
        url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
            bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
        time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
    if (inherits(res, "try-error")) {
        err <- attr(res, "condition")
        msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
        nc_n_try <- nc_n_try + 1
        if (nc_n_try > n_max_retries) {
            stop(msg)
        }
        else {
            message(msg, "\nRETRYing...")
            Sys.sleep(1)
        }
    }
    else {
        nc_retry <- F
    }
}
debug: res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
    url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
        bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
    time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
debug: if (inherits(res, "try-error")) {
    err <- attr(res, "condition")
    msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
    nc_n_try <- nc_n_try + 1
    if (nc_n_try > n_max_retries) {
        stop(msg)
    }
    else {
        message(msg, "\nRETRYing...")
        Sys.sleep(1)
    }
} else {
    nc_retry <- F
}
debug: nc_retry <- F
debug: (while) nc_retry
debug: i_req <- i_req + 1
debug: (while) i_req <= n_reqs
debug: ncs <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size > 
    0), nc)
debug: r <- terra::rast(ncs)
debug: stopifnot(all(class(terra::time(r)) %in% c("POSIXct", "POSIXt")))
debug: idx <- dplyr::pull(dplyr::filter(dplyr::arrange(dplyr::tibble(idx = 1:terra::nlyr(r), 
    time = terra::time(r)), time), !duplicated(time)), idx)
debug: r <- terra::subset(r, idx)
debug: stopifnot(terra::crs(r, proj = T) == wgs84)
debug: if (mask_tif) r <- terra::mask(r, sf_zones)
debug: lyrs <- glue("{var}|{terra::time(r)}")
debug: if (length(dims_other) > 0 && !all(length(dims[dims_other]) == 
    1)) stop(glue("Other dimensions not yet supported: {paste(dims_other, collapse = ',')}"))
debug: names(r) <- lyrs
debug: if (!is.null(rast_tif)) {
    if (fs::file_exists(rast_tif)) {
        r_tmp_tif <- tempfile(fileext = ".tif")
        r_tmp <- c(rast(rast_tif), r)
        r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
        terra::writeRaster(r_tmp, r_tmp_tif)
        fs::file_delete(rast_tif)
        fs::file_move(r_tmp_tif, rast_tif)
        rm(r)
        rm(r_tmp)
    }
    else {
        terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
    }
    r <- terra::rast(rast_tif)
}
debug: if (fs::file_exists(rast_tif)) {
    r_tmp_tif <- tempfile(fileext = ".tif")
    r_tmp <- c(rast(rast_tif), r)
    r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
    terra::writeRaster(r_tmp, r_tmp_tif)
    fs::file_delete(rast_tif)
    fs::file_move(r_tmp_tif, rast_tif)
    rm(r)
    rm(r_tmp)
} else {
    terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
}
debug: terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
debug: r <- terra::rast(rast_tif)
debug: d_r <- mutate(tidyr::pivot_longer(sf::st_drop_geometry(sf::st_as_sf(terra::zonal(x = r, 
    z = terra::vect(dplyr::select(sf_zones, dplyr::all_of(fld_zones))), 
    fun = zonal_fun, exact = T, na.rm = T, as.polygons = T))), 
    cols = -dplyr::any_of(fld_zones), names_to = "lyr", values_to = zonal_fun), 
    time = readr::parse_datetime(str_replace(lyr, glue("{var}\\|(.*)"), 
        "\\1")))
debug: if (!is.null(zonal_csv)) write_csv(d_r, zonal_csv)
debug: write_csv(d_r, zonal_csv)
debug: if (!keep_nc) unlink(dir_nc, recursive = T)
debug: unlink(dir_nc, recursive = T)
debug: return(d_r)
Downloading 1 requests, up to 114 time slices each
Called from: extractr::ed_extract(ed, var = v, sf_zones = ply, bbox = bb, 
    mask_tif = F, rast_tif = glue("{dir_out}/{nms}/{yr}.tif"), 
    zonal_fun = "mean", zonal_csv = glue("{dir_out}/{nms}/{yr}.csv"), 
    dir_nc = glue("{dir_out}/{nms}/{yr}_nc"), keep_nc = F, n_max_vals_per_req = 1e+05, 
    time_min = time_min, time_max = time_max, verbose = T)
debug: while (i_req <= n_reqs) {
    i_t_beg <- (i_req - 1) * n_t_per_req + 1
    i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
    t_req <- times_todo[c(i_t_beg, i_t_end)]
    t_req_str <- format_ISO8601(t_req, usetz = "Z")
    if (verbose) 
        message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
    ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
        ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
        0), nc)
    unlink(ncs0)
    nc_retry <- T
    nc_n_try <- 1
    n_max_retries
    while (nc_retry) {
        res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
            url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
                bbox[["xmax"]]), latitude = c(bbox[["ymin"]], 
                bbox[["ymax"]]), time = t_req_str, fmt = "nc", 
            store = rerddap::disk(path = dir_nc)))
        if (inherits(res, "try-error")) {
            err <- attr(res, "condition")
            msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
            nc_n_try <- nc_n_try + 1
            if (nc_n_try > n_max_retries) {
                stop(msg)
            }
            else {
                message(msg, "\nRETRYing...")
                Sys.sleep(1)
            }
        }
        else {
            nc_retry <- F
        }
    }
    i_req <- i_req + 1
}
debug: i_t_beg <- (i_req - 1) * n_t_per_req + 1
debug: i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
debug: t_req <- times_todo[c(i_t_beg, i_t_end)]
debug: t_req_str <- format_ISO8601(t_req, usetz = "Z")
debug: if (verbose) message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
debug: message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
Fetching request 1 of 1 (2018-01-01 to 2018-12-01) ~ 19:41:56 UTC
debug: ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
    0), nc)
debug: unlink(ncs0)
debug: nc_retry <- T
debug: nc_n_try <- 1
debug: n_max_retries
debug: while (nc_retry) {
    res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
        url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
            bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
        time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
    if (inherits(res, "try-error")) {
        err <- attr(res, "condition")
        msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
        nc_n_try <- nc_n_try + 1
        if (nc_n_try > n_max_retries) {
            stop(msg)
        }
        else {
            message(msg, "\nRETRYing...")
            Sys.sleep(1)
        }
    }
    else {
        nc_retry <- F
    }
}
debug: res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
    url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
        bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
    time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
debug: if (inherits(res, "try-error")) {
    err <- attr(res, "condition")
    msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
    nc_n_try <- nc_n_try + 1
    if (nc_n_try > n_max_retries) {
        stop(msg)
    }
    else {
        message(msg, "\nRETRYing...")
        Sys.sleep(1)
    }
} else {
    nc_retry <- F
}
debug: nc_retry <- F
debug: (while) nc_retry
debug: i_req <- i_req + 1
debug: (while) i_req <= n_reqs
debug: ncs <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size > 
    0), nc)
debug: r <- terra::rast(ncs)
debug: stopifnot(all(class(terra::time(r)) %in% c("POSIXct", "POSIXt")))
debug: idx <- dplyr::pull(dplyr::filter(dplyr::arrange(dplyr::tibble(idx = 1:terra::nlyr(r), 
    time = terra::time(r)), time), !duplicated(time)), idx)
debug: r <- terra::subset(r, idx)
debug: stopifnot(terra::crs(r, proj = T) == wgs84)
debug: if (mask_tif) r <- terra::mask(r, sf_zones)
debug: lyrs <- glue("{var}|{terra::time(r)}")
debug: if (length(dims_other) > 0 && !all(length(dims[dims_other]) == 
    1)) stop(glue("Other dimensions not yet supported: {paste(dims_other, collapse = ',')}"))
debug: names(r) <- lyrs
debug: if (!is.null(rast_tif)) {
    if (fs::file_exists(rast_tif)) {
        r_tmp_tif <- tempfile(fileext = ".tif")
        r_tmp <- c(rast(rast_tif), r)
        r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
        terra::writeRaster(r_tmp, r_tmp_tif)
        fs::file_delete(rast_tif)
        fs::file_move(r_tmp_tif, rast_tif)
        rm(r)
        rm(r_tmp)
    }
    else {
        terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
    }
    r <- terra::rast(rast_tif)
}
debug: if (fs::file_exists(rast_tif)) {
    r_tmp_tif <- tempfile(fileext = ".tif")
    r_tmp <- c(rast(rast_tif), r)
    r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
    terra::writeRaster(r_tmp, r_tmp_tif)
    fs::file_delete(rast_tif)
    fs::file_move(r_tmp_tif, rast_tif)
    rm(r)
    rm(r_tmp)
} else {
    terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
}
debug: terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
debug: r <- terra::rast(rast_tif)
debug: d_r <- mutate(tidyr::pivot_longer(sf::st_drop_geometry(sf::st_as_sf(terra::zonal(x = r, 
    z = terra::vect(dplyr::select(sf_zones, dplyr::all_of(fld_zones))), 
    fun = zonal_fun, exact = T, na.rm = T, as.polygons = T))), 
    cols = -dplyr::any_of(fld_zones), names_to = "lyr", values_to = zonal_fun), 
    time = readr::parse_datetime(str_replace(lyr, glue("{var}\\|(.*)"), 
        "\\1")))
debug: if (!is.null(zonal_csv)) write_csv(d_r, zonal_csv)
debug: write_csv(d_r, zonal_csv)
debug: if (!keep_nc) unlink(dir_nc, recursive = T)
debug: unlink(dir_nc, recursive = T)
debug: return(d_r)
Downloading 1 requests, up to 114 time slices each
Called from: extractr::ed_extract(ed, var = v, sf_zones = ply, bbox = bb, 
    mask_tif = F, rast_tif = glue("{dir_out}/{nms}/{yr}.tif"), 
    zonal_fun = "mean", zonal_csv = glue("{dir_out}/{nms}/{yr}.csv"), 
    dir_nc = glue("{dir_out}/{nms}/{yr}_nc"), keep_nc = F, n_max_vals_per_req = 1e+05, 
    time_min = time_min, time_max = time_max, verbose = T)
debug: while (i_req <= n_reqs) {
    i_t_beg <- (i_req - 1) * n_t_per_req + 1
    i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
    t_req <- times_todo[c(i_t_beg, i_t_end)]
    t_req_str <- format_ISO8601(t_req, usetz = "Z")
    if (verbose) 
        message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
    ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
        ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
        0), nc)
    unlink(ncs0)
    nc_retry <- T
    nc_n_try <- 1
    n_max_retries
    while (nc_retry) {
        res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
            url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
                bbox[["xmax"]]), latitude = c(bbox[["ymin"]], 
                bbox[["ymax"]]), time = t_req_str, fmt = "nc", 
            store = rerddap::disk(path = dir_nc)))
        if (inherits(res, "try-error")) {
            err <- attr(res, "condition")
            msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
            nc_n_try <- nc_n_try + 1
            if (nc_n_try > n_max_retries) {
                stop(msg)
            }
            else {
                message(msg, "\nRETRYing...")
                Sys.sleep(1)
            }
        }
        else {
            nc_retry <- F
        }
    }
    i_req <- i_req + 1
}
debug: i_t_beg <- (i_req - 1) * n_t_per_req + 1
debug: i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
debug: t_req <- times_todo[c(i_t_beg, i_t_end)]
debug: t_req_str <- format_ISO8601(t_req, usetz = "Z")
debug: if (verbose) message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
debug: message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
Fetching request 1 of 1 (2019-01-01 to 2019-12-01) ~ 19:41:58 UTC
debug: ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
    0), nc)
debug: unlink(ncs0)
debug: nc_retry <- T
debug: nc_n_try <- 1
debug: n_max_retries
debug: while (nc_retry) {
    res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
        url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
            bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
        time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
    if (inherits(res, "try-error")) {
        err <- attr(res, "condition")
        msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
        nc_n_try <- nc_n_try + 1
        if (nc_n_try > n_max_retries) {
            stop(msg)
        }
        else {
            message(msg, "\nRETRYing...")
            Sys.sleep(1)
        }
    }
    else {
        nc_retry <- F
    }
}
debug: res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
    url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
        bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
    time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
debug: if (inherits(res, "try-error")) {
    err <- attr(res, "condition")
    msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
    nc_n_try <- nc_n_try + 1
    if (nc_n_try > n_max_retries) {
        stop(msg)
    }
    else {
        message(msg, "\nRETRYing...")
        Sys.sleep(1)
    }
} else {
    nc_retry <- F
}
debug: nc_retry <- F
debug: (while) nc_retry
debug: i_req <- i_req + 1
debug: (while) i_req <= n_reqs
debug: ncs <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size > 
    0), nc)
debug: r <- terra::rast(ncs)
debug: stopifnot(all(class(terra::time(r)) %in% c("POSIXct", "POSIXt")))
debug: idx <- dplyr::pull(dplyr::filter(dplyr::arrange(dplyr::tibble(idx = 1:terra::nlyr(r), 
    time = terra::time(r)), time), !duplicated(time)), idx)
debug: r <- terra::subset(r, idx)
debug: stopifnot(terra::crs(r, proj = T) == wgs84)
debug: if (mask_tif) r <- terra::mask(r, sf_zones)
debug: lyrs <- glue("{var}|{terra::time(r)}")
debug: if (length(dims_other) > 0 && !all(length(dims[dims_other]) == 
    1)) stop(glue("Other dimensions not yet supported: {paste(dims_other, collapse = ',')}"))
debug: names(r) <- lyrs
debug: if (!is.null(rast_tif)) {
    if (fs::file_exists(rast_tif)) {
        r_tmp_tif <- tempfile(fileext = ".tif")
        r_tmp <- c(rast(rast_tif), r)
        r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
        terra::writeRaster(r_tmp, r_tmp_tif)
        fs::file_delete(rast_tif)
        fs::file_move(r_tmp_tif, rast_tif)
        rm(r)
        rm(r_tmp)
    }
    else {
        terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
    }
    r <- terra::rast(rast_tif)
}
debug: if (fs::file_exists(rast_tif)) {
    r_tmp_tif <- tempfile(fileext = ".tif")
    r_tmp <- c(rast(rast_tif), r)
    r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
    terra::writeRaster(r_tmp, r_tmp_tif)
    fs::file_delete(rast_tif)
    fs::file_move(r_tmp_tif, rast_tif)
    rm(r)
    rm(r_tmp)
} else {
    terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
}
debug: terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
debug: r <- terra::rast(rast_tif)
debug: d_r <- mutate(tidyr::pivot_longer(sf::st_drop_geometry(sf::st_as_sf(terra::zonal(x = r, 
    z = terra::vect(dplyr::select(sf_zones, dplyr::all_of(fld_zones))), 
    fun = zonal_fun, exact = T, na.rm = T, as.polygons = T))), 
    cols = -dplyr::any_of(fld_zones), names_to = "lyr", values_to = zonal_fun), 
    time = readr::parse_datetime(str_replace(lyr, glue("{var}\\|(.*)"), 
        "\\1")))
debug: if (!is.null(zonal_csv)) write_csv(d_r, zonal_csv)
debug: write_csv(d_r, zonal_csv)
debug: if (!keep_nc) unlink(dir_nc, recursive = T)
debug: unlink(dir_nc, recursive = T)
debug: return(d_r)
Downloading 1 requests, up to 114 time slices each
Called from: extractr::ed_extract(ed, var = v, sf_zones = ply, bbox = bb, 
    mask_tif = F, rast_tif = glue("{dir_out}/{nms}/{yr}.tif"), 
    zonal_fun = "mean", zonal_csv = glue("{dir_out}/{nms}/{yr}.csv"), 
    dir_nc = glue("{dir_out}/{nms}/{yr}_nc"), keep_nc = F, n_max_vals_per_req = 1e+05, 
    time_min = time_min, time_max = time_max, verbose = T)
debug: while (i_req <= n_reqs) {
    i_t_beg <- (i_req - 1) * n_t_per_req + 1
    i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
    t_req <- times_todo[c(i_t_beg, i_t_end)]
    t_req_str <- format_ISO8601(t_req, usetz = "Z")
    if (verbose) 
        message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
    ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
        ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
        0), nc)
    unlink(ncs0)
    nc_retry <- T
    nc_n_try <- 1
    n_max_retries
    while (nc_retry) {
        res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
            url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
                bbox[["xmax"]]), latitude = c(bbox[["ymin"]], 
                bbox[["ymax"]]), time = t_req_str, fmt = "nc", 
            store = rerddap::disk(path = dir_nc)))
        if (inherits(res, "try-error")) {
            err <- attr(res, "condition")
            msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
            nc_n_try <- nc_n_try + 1
            if (nc_n_try > n_max_retries) {
                stop(msg)
            }
            else {
                message(msg, "\nRETRYing...")
                Sys.sleep(1)
            }
        }
        else {
            nc_retry <- F
        }
    }
    i_req <- i_req + 1
}
debug: i_t_beg <- (i_req - 1) * n_t_per_req + 1
debug: i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
debug: t_req <- times_todo[c(i_t_beg, i_t_end)]
debug: t_req_str <- format_ISO8601(t_req, usetz = "Z")
debug: if (verbose) message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
debug: message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
Fetching request 1 of 1 (2020-01-01 to 2020-12-01) ~ 19:42:00 UTC
debug: ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
    0), nc)
debug: unlink(ncs0)
debug: nc_retry <- T
debug: nc_n_try <- 1
debug: n_max_retries
debug: while (nc_retry) {
    res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
        url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
            bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
        time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
    if (inherits(res, "try-error")) {
        err <- attr(res, "condition")
        msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
        nc_n_try <- nc_n_try + 1
        if (nc_n_try > n_max_retries) {
            stop(msg)
        }
        else {
            message(msg, "\nRETRYing...")
            Sys.sleep(1)
        }
    }
    else {
        nc_retry <- F
    }
}
debug: res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
    url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
        bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
    time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
debug: if (inherits(res, "try-error")) {
    err <- attr(res, "condition")
    msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
    nc_n_try <- nc_n_try + 1
    if (nc_n_try > n_max_retries) {
        stop(msg)
    }
    else {
        message(msg, "\nRETRYing...")
        Sys.sleep(1)
    }
} else {
    nc_retry <- F
}
debug: nc_retry <- F
debug: (while) nc_retry
debug: i_req <- i_req + 1
debug: (while) i_req <= n_reqs
debug: ncs <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size > 
    0), nc)
debug: r <- terra::rast(ncs)
debug: stopifnot(all(class(terra::time(r)) %in% c("POSIXct", "POSIXt")))
debug: idx <- dplyr::pull(dplyr::filter(dplyr::arrange(dplyr::tibble(idx = 1:terra::nlyr(r), 
    time = terra::time(r)), time), !duplicated(time)), idx)
debug: r <- terra::subset(r, idx)
debug: stopifnot(terra::crs(r, proj = T) == wgs84)
debug: if (mask_tif) r <- terra::mask(r, sf_zones)
debug: lyrs <- glue("{var}|{terra::time(r)}")
debug: if (length(dims_other) > 0 && !all(length(dims[dims_other]) == 
    1)) stop(glue("Other dimensions not yet supported: {paste(dims_other, collapse = ',')}"))
debug: names(r) <- lyrs
debug: if (!is.null(rast_tif)) {
    if (fs::file_exists(rast_tif)) {
        r_tmp_tif <- tempfile(fileext = ".tif")
        r_tmp <- c(rast(rast_tif), r)
        r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
        terra::writeRaster(r_tmp, r_tmp_tif)
        fs::file_delete(rast_tif)
        fs::file_move(r_tmp_tif, rast_tif)
        rm(r)
        rm(r_tmp)
    }
    else {
        terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
    }
    r <- terra::rast(rast_tif)
}
debug: if (fs::file_exists(rast_tif)) {
    r_tmp_tif <- tempfile(fileext = ".tif")
    r_tmp <- c(rast(rast_tif), r)
    r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
    terra::writeRaster(r_tmp, r_tmp_tif)
    fs::file_delete(rast_tif)
    fs::file_move(r_tmp_tif, rast_tif)
    rm(r)
    rm(r_tmp)
} else {
    terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
}
debug: terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
debug: r <- terra::rast(rast_tif)
debug: d_r <- mutate(tidyr::pivot_longer(sf::st_drop_geometry(sf::st_as_sf(terra::zonal(x = r, 
    z = terra::vect(dplyr::select(sf_zones, dplyr::all_of(fld_zones))), 
    fun = zonal_fun, exact = T, na.rm = T, as.polygons = T))), 
    cols = -dplyr::any_of(fld_zones), names_to = "lyr", values_to = zonal_fun), 
    time = readr::parse_datetime(str_replace(lyr, glue("{var}\\|(.*)"), 
        "\\1")))
debug: if (!is.null(zonal_csv)) write_csv(d_r, zonal_csv)
debug: write_csv(d_r, zonal_csv)
debug: if (!keep_nc) unlink(dir_nc, recursive = T)
debug: unlink(dir_nc, recursive = T)
debug: return(d_r)
Downloading 1 requests, up to 114 time slices each
Called from: extractr::ed_extract(ed, var = v, sf_zones = ply, bbox = bb, 
    mask_tif = F, rast_tif = glue("{dir_out}/{nms}/{yr}.tif"), 
    zonal_fun = "mean", zonal_csv = glue("{dir_out}/{nms}/{yr}.csv"), 
    dir_nc = glue("{dir_out}/{nms}/{yr}_nc"), keep_nc = F, n_max_vals_per_req = 1e+05, 
    time_min = time_min, time_max = time_max, verbose = T)
debug: while (i_req <= n_reqs) {
    i_t_beg <- (i_req - 1) * n_t_per_req + 1
    i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
    t_req <- times_todo[c(i_t_beg, i_t_end)]
    t_req_str <- format_ISO8601(t_req, usetz = "Z")
    if (verbose) 
        message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
    ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
        ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
        0), nc)
    unlink(ncs0)
    nc_retry <- T
    nc_n_try <- 1
    n_max_retries
    while (nc_retry) {
        res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
            url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
                bbox[["xmax"]]), latitude = c(bbox[["ymin"]], 
                bbox[["ymax"]]), time = t_req_str, fmt = "nc", 
            store = rerddap::disk(path = dir_nc)))
        if (inherits(res, "try-error")) {
            err <- attr(res, "condition")
            msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
            nc_n_try <- nc_n_try + 1
            if (nc_n_try > n_max_retries) {
                stop(msg)
            }
            else {
                message(msg, "\nRETRYing...")
                Sys.sleep(1)
            }
        }
        else {
            nc_retry <- F
        }
    }
    i_req <- i_req + 1
}
debug: i_t_beg <- (i_req - 1) * n_t_per_req + 1
debug: i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
debug: t_req <- times_todo[c(i_t_beg, i_t_end)]
debug: t_req_str <- format_ISO8601(t_req, usetz = "Z")
debug: if (verbose) message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
debug: message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
Fetching request 1 of 1 (2021-01-01 to 2021-12-01) ~ 19:42:02 UTC
debug: ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
    0), nc)
debug: unlink(ncs0)
debug: nc_retry <- T
debug: nc_n_try <- 1
debug: n_max_retries
debug: while (nc_retry) {
    res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
        url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
            bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
        time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
    if (inherits(res, "try-error")) {
        err <- attr(res, "condition")
        msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
        nc_n_try <- nc_n_try + 1
        if (nc_n_try > n_max_retries) {
            stop(msg)
        }
        else {
            message(msg, "\nRETRYing...")
            Sys.sleep(1)
        }
    }
    else {
        nc_retry <- F
    }
}
debug: res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
    url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
        bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
    time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
debug: if (inherits(res, "try-error")) {
    err <- attr(res, "condition")
    msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
    nc_n_try <- nc_n_try + 1
    if (nc_n_try > n_max_retries) {
        stop(msg)
    }
    else {
        message(msg, "\nRETRYing...")
        Sys.sleep(1)
    }
} else {
    nc_retry <- F
}
debug: nc_retry <- F
debug: (while) nc_retry
debug: i_req <- i_req + 1
debug: (while) i_req <= n_reqs
debug: ncs <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size > 
    0), nc)
debug: r <- terra::rast(ncs)
debug: stopifnot(all(class(terra::time(r)) %in% c("POSIXct", "POSIXt")))
debug: idx <- dplyr::pull(dplyr::filter(dplyr::arrange(dplyr::tibble(idx = 1:terra::nlyr(r), 
    time = terra::time(r)), time), !duplicated(time)), idx)
debug: r <- terra::subset(r, idx)
debug: stopifnot(terra::crs(r, proj = T) == wgs84)
debug: if (mask_tif) r <- terra::mask(r, sf_zones)
debug: lyrs <- glue("{var}|{terra::time(r)}")
debug: if (length(dims_other) > 0 && !all(length(dims[dims_other]) == 
    1)) stop(glue("Other dimensions not yet supported: {paste(dims_other, collapse = ',')}"))
debug: names(r) <- lyrs
debug: if (!is.null(rast_tif)) {
    if (fs::file_exists(rast_tif)) {
        r_tmp_tif <- tempfile(fileext = ".tif")
        r_tmp <- c(rast(rast_tif), r)
        r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
        terra::writeRaster(r_tmp, r_tmp_tif)
        fs::file_delete(rast_tif)
        fs::file_move(r_tmp_tif, rast_tif)
        rm(r)
        rm(r_tmp)
    }
    else {
        terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
    }
    r <- terra::rast(rast_tif)
}
debug: if (fs::file_exists(rast_tif)) {
    r_tmp_tif <- tempfile(fileext = ".tif")
    r_tmp <- c(rast(rast_tif), r)
    r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
    terra::writeRaster(r_tmp, r_tmp_tif)
    fs::file_delete(rast_tif)
    fs::file_move(r_tmp_tif, rast_tif)
    rm(r)
    rm(r_tmp)
} else {
    terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
}
debug: terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
debug: r <- terra::rast(rast_tif)
debug: d_r <- mutate(tidyr::pivot_longer(sf::st_drop_geometry(sf::st_as_sf(terra::zonal(x = r, 
    z = terra::vect(dplyr::select(sf_zones, dplyr::all_of(fld_zones))), 
    fun = zonal_fun, exact = T, na.rm = T, as.polygons = T))), 
    cols = -dplyr::any_of(fld_zones), names_to = "lyr", values_to = zonal_fun), 
    time = readr::parse_datetime(str_replace(lyr, glue("{var}\\|(.*)"), 
        "\\1")))
debug: if (!is.null(zonal_csv)) write_csv(d_r, zonal_csv)
debug: write_csv(d_r, zonal_csv)
debug: if (!keep_nc) unlink(dir_nc, recursive = T)
debug: unlink(dir_nc, recursive = T)
debug: return(d_r)
Downloading 1 requests, up to 114 time slices each
Called from: extractr::ed_extract(ed, var = v, sf_zones = ply, bbox = bb, 
    mask_tif = F, rast_tif = glue("{dir_out}/{nms}/{yr}.tif"), 
    zonal_fun = "mean", zonal_csv = glue("{dir_out}/{nms}/{yr}.csv"), 
    dir_nc = glue("{dir_out}/{nms}/{yr}_nc"), keep_nc = F, n_max_vals_per_req = 1e+05, 
    time_min = time_min, time_max = time_max, verbose = T)
debug: while (i_req <= n_reqs) {
    i_t_beg <- (i_req - 1) * n_t_per_req + 1
    i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
    t_req <- times_todo[c(i_t_beg, i_t_end)]
    t_req_str <- format_ISO8601(t_req, usetz = "Z")
    if (verbose) 
        message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
    ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
        ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
        0), nc)
    unlink(ncs0)
    nc_retry <- T
    nc_n_try <- 1
    n_max_retries
    while (nc_retry) {
        res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
            url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
                bbox[["xmax"]]), latitude = c(bbox[["ymin"]], 
                bbox[["ymax"]]), time = t_req_str, fmt = "nc", 
            store = rerddap::disk(path = dir_nc)))
        if (inherits(res, "try-error")) {
            err <- attr(res, "condition")
            msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
            nc_n_try <- nc_n_try + 1
            if (nc_n_try > n_max_retries) {
                stop(msg)
            }
            else {
                message(msg, "\nRETRYing...")
                Sys.sleep(1)
            }
        }
        else {
            nc_retry <- F
        }
    }
    i_req <- i_req + 1
}
debug: i_t_beg <- (i_req - 1) * n_t_per_req + 1
debug: i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
debug: t_req <- times_todo[c(i_t_beg, i_t_end)]
debug: t_req_str <- format_ISO8601(t_req, usetz = "Z")
debug: if (verbose) message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
debug: message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
Fetching request 1 of 1 (2022-01-01 to 2022-12-01) ~ 19:42:04 UTC
debug: ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
    0), nc)
debug: unlink(ncs0)
debug: nc_retry <- T
debug: nc_n_try <- 1
debug: n_max_retries
debug: while (nc_retry) {
    res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
        url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
            bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
        time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
    if (inherits(res, "try-error")) {
        err <- attr(res, "condition")
        msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
        nc_n_try <- nc_n_try + 1
        if (nc_n_try > n_max_retries) {
            stop(msg)
        }
        else {
            message(msg, "\nRETRYing...")
            Sys.sleep(1)
        }
    }
    else {
        nc_retry <- F
    }
}
debug: res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
    url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
        bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
    time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
debug: if (inherits(res, "try-error")) {
    err <- attr(res, "condition")
    msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
    nc_n_try <- nc_n_try + 1
    if (nc_n_try > n_max_retries) {
        stop(msg)
    }
    else {
        message(msg, "\nRETRYing...")
        Sys.sleep(1)
    }
} else {
    nc_retry <- F
}
debug: nc_retry <- F
debug: (while) nc_retry
debug: i_req <- i_req + 1
debug: (while) i_req <= n_reqs
debug: ncs <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size > 
    0), nc)
debug: r <- terra::rast(ncs)
debug: stopifnot(all(class(terra::time(r)) %in% c("POSIXct", "POSIXt")))
debug: idx <- dplyr::pull(dplyr::filter(dplyr::arrange(dplyr::tibble(idx = 1:terra::nlyr(r), 
    time = terra::time(r)), time), !duplicated(time)), idx)
debug: r <- terra::subset(r, idx)
debug: stopifnot(terra::crs(r, proj = T) == wgs84)
debug: if (mask_tif) r <- terra::mask(r, sf_zones)
debug: lyrs <- glue("{var}|{terra::time(r)}")
debug: if (length(dims_other) > 0 && !all(length(dims[dims_other]) == 
    1)) stop(glue("Other dimensions not yet supported: {paste(dims_other, collapse = ',')}"))
debug: names(r) <- lyrs
debug: if (!is.null(rast_tif)) {
    if (fs::file_exists(rast_tif)) {
        r_tmp_tif <- tempfile(fileext = ".tif")
        r_tmp <- c(rast(rast_tif), r)
        r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
        terra::writeRaster(r_tmp, r_tmp_tif)
        fs::file_delete(rast_tif)
        fs::file_move(r_tmp_tif, rast_tif)
        rm(r)
        rm(r_tmp)
    }
    else {
        terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
    }
    r <- terra::rast(rast_tif)
}
debug: if (fs::file_exists(rast_tif)) {
    r_tmp_tif <- tempfile(fileext = ".tif")
    r_tmp <- c(rast(rast_tif), r)
    r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
    terra::writeRaster(r_tmp, r_tmp_tif)
    fs::file_delete(rast_tif)
    fs::file_move(r_tmp_tif, rast_tif)
    rm(r)
    rm(r_tmp)
} else {
    terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
}
debug: terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
debug: r <- terra::rast(rast_tif)
debug: d_r <- mutate(tidyr::pivot_longer(sf::st_drop_geometry(sf::st_as_sf(terra::zonal(x = r, 
    z = terra::vect(dplyr::select(sf_zones, dplyr::all_of(fld_zones))), 
    fun = zonal_fun, exact = T, na.rm = T, as.polygons = T))), 
    cols = -dplyr::any_of(fld_zones), names_to = "lyr", values_to = zonal_fun), 
    time = readr::parse_datetime(str_replace(lyr, glue("{var}\\|(.*)"), 
        "\\1")))
debug: if (!is.null(zonal_csv)) write_csv(d_r, zonal_csv)
debug: write_csv(d_r, zonal_csv)
debug: if (!keep_nc) unlink(dir_nc, recursive = T)
debug: unlink(dir_nc, recursive = T)
debug: return(d_r)
Downloading 1 requests, up to 114 time slices each
Called from: extractr::ed_extract(ed, var = v, sf_zones = ply, bbox = bb, 
    mask_tif = F, rast_tif = glue("{dir_out}/{nms}/{yr}.tif"), 
    zonal_fun = "mean", zonal_csv = glue("{dir_out}/{nms}/{yr}.csv"), 
    dir_nc = glue("{dir_out}/{nms}/{yr}_nc"), keep_nc = F, n_max_vals_per_req = 1e+05, 
    time_min = time_min, time_max = time_max, verbose = T)
debug: while (i_req <= n_reqs) {
    i_t_beg <- (i_req - 1) * n_t_per_req + 1
    i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
    t_req <- times_todo[c(i_t_beg, i_t_end)]
    t_req_str <- format_ISO8601(t_req, usetz = "Z")
    if (verbose) 
        message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
    ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
        ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
        0), nc)
    unlink(ncs0)
    nc_retry <- T
    nc_n_try <- 1
    n_max_retries
    while (nc_retry) {
        res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
            url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
                bbox[["xmax"]]), latitude = c(bbox[["ymin"]], 
                bbox[["ymax"]]), time = t_req_str, fmt = "nc", 
            store = rerddap::disk(path = dir_nc)))
        if (inherits(res, "try-error")) {
            err <- attr(res, "condition")
            msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
            nc_n_try <- nc_n_try + 1
            if (nc_n_try > n_max_retries) {
                stop(msg)
            }
            else {
                message(msg, "\nRETRYing...")
                Sys.sleep(1)
            }
        }
        else {
            nc_retry <- F
        }
    }
    i_req <- i_req + 1
}
debug: i_t_beg <- (i_req - 1) * n_t_per_req + 1
debug: i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
debug: t_req <- times_todo[c(i_t_beg, i_t_end)]
debug: t_req_str <- format_ISO8601(t_req, usetz = "Z")
debug: if (verbose) message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
debug: message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
Fetching request 1 of 1 (2023-01-01 to 2023-12-01) ~ 19:42:06 UTC
debug: ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
    0), nc)
debug: unlink(ncs0)
debug: nc_retry <- T
debug: nc_n_try <- 1
debug: n_max_retries
debug: while (nc_retry) {
    res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
        url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
            bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
        time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
    if (inherits(res, "try-error")) {
        err <- attr(res, "condition")
        msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
        nc_n_try <- nc_n_try + 1
        if (nc_n_try > n_max_retries) {
            stop(msg)
        }
        else {
            message(msg, "\nRETRYing...")
            Sys.sleep(1)
        }
    }
    else {
        nc_retry <- F
    }
}
debug: res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
    url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
        bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
    time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
debug: if (inherits(res, "try-error")) {
    err <- attr(res, "condition")
    msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
    nc_n_try <- nc_n_try + 1
    if (nc_n_try > n_max_retries) {
        stop(msg)
    }
    else {
        message(msg, "\nRETRYing...")
        Sys.sleep(1)
    }
} else {
    nc_retry <- F
}
debug: nc_retry <- F
debug: (while) nc_retry
debug: i_req <- i_req + 1
debug: (while) i_req <= n_reqs
debug: ncs <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size > 
    0), nc)
debug: r <- terra::rast(ncs)
debug: stopifnot(all(class(terra::time(r)) %in% c("POSIXct", "POSIXt")))
debug: idx <- dplyr::pull(dplyr::filter(dplyr::arrange(dplyr::tibble(idx = 1:terra::nlyr(r), 
    time = terra::time(r)), time), !duplicated(time)), idx)
debug: r <- terra::subset(r, idx)
debug: stopifnot(terra::crs(r, proj = T) == wgs84)
debug: if (mask_tif) r <- terra::mask(r, sf_zones)
debug: lyrs <- glue("{var}|{terra::time(r)}")
debug: if (length(dims_other) > 0 && !all(length(dims[dims_other]) == 
    1)) stop(glue("Other dimensions not yet supported: {paste(dims_other, collapse = ',')}"))
debug: names(r) <- lyrs
debug: if (!is.null(rast_tif)) {
    if (fs::file_exists(rast_tif)) {
        r_tmp_tif <- tempfile(fileext = ".tif")
        r_tmp <- c(rast(rast_tif), r)
        r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
        terra::writeRaster(r_tmp, r_tmp_tif)
        fs::file_delete(rast_tif)
        fs::file_move(r_tmp_tif, rast_tif)
        rm(r)
        rm(r_tmp)
    }
    else {
        terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
    }
    r <- terra::rast(rast_tif)
}
debug: if (fs::file_exists(rast_tif)) {
    r_tmp_tif <- tempfile(fileext = ".tif")
    r_tmp <- c(rast(rast_tif), r)
    r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
    terra::writeRaster(r_tmp, r_tmp_tif)
    fs::file_delete(rast_tif)
    fs::file_move(r_tmp_tif, rast_tif)
    rm(r)
    rm(r_tmp)
} else {
    terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
}
debug: terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
debug: r <- terra::rast(rast_tif)
debug: d_r <- mutate(tidyr::pivot_longer(sf::st_drop_geometry(sf::st_as_sf(terra::zonal(x = r, 
    z = terra::vect(dplyr::select(sf_zones, dplyr::all_of(fld_zones))), 
    fun = zonal_fun, exact = T, na.rm = T, as.polygons = T))), 
    cols = -dplyr::any_of(fld_zones), names_to = "lyr", values_to = zonal_fun), 
    time = readr::parse_datetime(str_replace(lyr, glue("{var}\\|(.*)"), 
        "\\1")))
debug: if (!is.null(zonal_csv)) write_csv(d_r, zonal_csv)
debug: write_csv(d_r, zonal_csv)
debug: if (!keep_nc) unlink(dir_nc, recursive = T)
debug: unlink(dir_nc, recursive = T)
debug: return(d_r)
Downloading 1 requests, up to 114 time slices each
Called from: extractr::ed_extract(ed, var = v, sf_zones = ply, bbox = bb, 
    mask_tif = F, rast_tif = glue("{dir_out}/{nms}/{yr}.tif"), 
    zonal_fun = "mean", zonal_csv = glue("{dir_out}/{nms}/{yr}.csv"), 
    dir_nc = glue("{dir_out}/{nms}/{yr}_nc"), keep_nc = F, n_max_vals_per_req = 1e+05, 
    time_min = time_min, time_max = time_max, verbose = T)
debug: while (i_req <= n_reqs) {
    i_t_beg <- (i_req - 1) * n_t_per_req + 1
    i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
    t_req <- times_todo[c(i_t_beg, i_t_end)]
    t_req_str <- format_ISO8601(t_req, usetz = "Z")
    if (verbose) 
        message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
    ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
        ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
        0), nc)
    unlink(ncs0)
    nc_retry <- T
    nc_n_try <- 1
    n_max_retries
    while (nc_retry) {
        res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
            url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
                bbox[["xmax"]]), latitude = c(bbox[["ymin"]], 
                bbox[["ymax"]]), time = t_req_str, fmt = "nc", 
            store = rerddap::disk(path = dir_nc)))
        if (inherits(res, "try-error")) {
            err <- attr(res, "condition")
            msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
            nc_n_try <- nc_n_try + 1
            if (nc_n_try > n_max_retries) {
                stop(msg)
            }
            else {
                message(msg, "\nRETRYing...")
                Sys.sleep(1)
            }
        }
        else {
            nc_retry <- F
        }
    }
    i_req <- i_req + 1
}
debug: i_t_beg <- (i_req - 1) * n_t_per_req + 1
debug: i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
debug: t_req <- times_todo[c(i_t_beg, i_t_end)]
debug: t_req_str <- format_ISO8601(t_req, usetz = "Z")
debug: if (verbose) message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
debug: message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
Fetching request 1 of 1 (2024-01-01 to 2024-12-01) ~ 19:42:08 UTC
debug: ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
    0), nc)
debug: unlink(ncs0)
debug: nc_retry <- T
debug: nc_n_try <- 1
debug: n_max_retries
debug: while (nc_retry) {
    res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
        url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
            bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
        time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
    if (inherits(res, "try-error")) {
        err <- attr(res, "condition")
        msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
        nc_n_try <- nc_n_try + 1
        if (nc_n_try > n_max_retries) {
            stop(msg)
        }
        else {
            message(msg, "\nRETRYing...")
            Sys.sleep(1)
        }
    }
    else {
        nc_retry <- F
    }
}
debug: res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
    url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
        bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
    time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
debug: if (inherits(res, "try-error")) {
    err <- attr(res, "condition")
    msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
    nc_n_try <- nc_n_try + 1
    if (nc_n_try > n_max_retries) {
        stop(msg)
    }
    else {
        message(msg, "\nRETRYing...")
        Sys.sleep(1)
    }
} else {
    nc_retry <- F
}
debug: nc_retry <- F
debug: (while) nc_retry
debug: i_req <- i_req + 1
debug: (while) i_req <= n_reqs
debug: ncs <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size > 
    0), nc)
debug: r <- terra::rast(ncs)
debug: stopifnot(all(class(terra::time(r)) %in% c("POSIXct", "POSIXt")))
debug: idx <- dplyr::pull(dplyr::filter(dplyr::arrange(dplyr::tibble(idx = 1:terra::nlyr(r), 
    time = terra::time(r)), time), !duplicated(time)), idx)
debug: r <- terra::subset(r, idx)
debug: stopifnot(terra::crs(r, proj = T) == wgs84)
debug: if (mask_tif) r <- terra::mask(r, sf_zones)
debug: lyrs <- glue("{var}|{terra::time(r)}")
debug: if (length(dims_other) > 0 && !all(length(dims[dims_other]) == 
    1)) stop(glue("Other dimensions not yet supported: {paste(dims_other, collapse = ',')}"))
debug: names(r) <- lyrs
debug: if (!is.null(rast_tif)) {
    if (fs::file_exists(rast_tif)) {
        r_tmp_tif <- tempfile(fileext = ".tif")
        r_tmp <- c(rast(rast_tif), r)
        r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
        terra::writeRaster(r_tmp, r_tmp_tif)
        fs::file_delete(rast_tif)
        fs::file_move(r_tmp_tif, rast_tif)
        rm(r)
        rm(r_tmp)
    }
    else {
        terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
    }
    r <- terra::rast(rast_tif)
}
debug: if (fs::file_exists(rast_tif)) {
    r_tmp_tif <- tempfile(fileext = ".tif")
    r_tmp <- c(rast(rast_tif), r)
    r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
    terra::writeRaster(r_tmp, r_tmp_tif)
    fs::file_delete(rast_tif)
    fs::file_move(r_tmp_tif, rast_tif)
    rm(r)
    rm(r_tmp)
} else {
    terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
}
debug: terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
debug: r <- terra::rast(rast_tif)
debug: d_r <- mutate(tidyr::pivot_longer(sf::st_drop_geometry(sf::st_as_sf(terra::zonal(x = r, 
    z = terra::vect(dplyr::select(sf_zones, dplyr::all_of(fld_zones))), 
    fun = zonal_fun, exact = T, na.rm = T, as.polygons = T))), 
    cols = -dplyr::any_of(fld_zones), names_to = "lyr", values_to = zonal_fun), 
    time = readr::parse_datetime(str_replace(lyr, glue("{var}\\|(.*)"), 
        "\\1")))
debug: if (!is.null(zonal_csv)) write_csv(d_r, zonal_csv)
debug: write_csv(d_r, zonal_csv)
debug: if (!keep_nc) unlink(dir_nc, recursive = T)
debug: unlink(dir_nc, recursive = T)
debug: return(d_r)
Downloading 1 requests, up to 114 time slices each
Called from: extractr::ed_extract(ed, var = v, sf_zones = ply, bbox = bb, 
    mask_tif = F, rast_tif = glue("{dir_out}/{nms}/{yr}.tif"), 
    zonal_fun = "mean", zonal_csv = glue("{dir_out}/{nms}/{yr}.csv"), 
    dir_nc = glue("{dir_out}/{nms}/{yr}_nc"), keep_nc = F, n_max_vals_per_req = 1e+05, 
    time_min = time_min, time_max = time_max, verbose = T)
debug: while (i_req <= n_reqs) {
    i_t_beg <- (i_req - 1) * n_t_per_req + 1
    i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
    t_req <- times_todo[c(i_t_beg, i_t_end)]
    t_req_str <- format_ISO8601(t_req, usetz = "Z")
    if (verbose) 
        message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
    ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
        ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
        0), nc)
    unlink(ncs0)
    nc_retry <- T
    nc_n_try <- 1
    n_max_retries
    while (nc_retry) {
        res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
            url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
                bbox[["xmax"]]), latitude = c(bbox[["ymin"]], 
                bbox[["ymax"]]), time = t_req_str, fmt = "nc", 
            store = rerddap::disk(path = dir_nc)))
        if (inherits(res, "try-error")) {
            err <- attr(res, "condition")
            msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
            nc_n_try <- nc_n_try + 1
            if (nc_n_try > n_max_retries) {
                stop(msg)
            }
            else {
                message(msg, "\nRETRYing...")
                Sys.sleep(1)
            }
        }
        else {
            nc_retry <- F
        }
    }
    i_req <- i_req + 1
}
debug: i_t_beg <- (i_req - 1) * n_t_per_req + 1
debug: i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
debug: t_req <- times_todo[c(i_t_beg, i_t_end)]
debug: t_req_str <- format_ISO8601(t_req, usetz = "Z")
debug: if (verbose) message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
debug: message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
Fetching request 1 of 1 (2025-01-01 to 2025-07-01) ~ 19:42:10 UTC
debug: ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
    0), nc)
debug: unlink(ncs0)
debug: nc_retry <- T
debug: nc_n_try <- 1
debug: n_max_retries
debug: while (nc_retry) {
    res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
        url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
            bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
        time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
    if (inherits(res, "try-error")) {
        err <- attr(res, "condition")
        msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
        nc_n_try <- nc_n_try + 1
        if (nc_n_try > n_max_retries) {
            stop(msg)
        }
        else {
            message(msg, "\nRETRYing...")
            Sys.sleep(1)
        }
    }
    else {
        nc_retry <- F
    }
}
debug: res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
    url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
        bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
    time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
debug: if (inherits(res, "try-error")) {
    err <- attr(res, "condition")
    msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
    nc_n_try <- nc_n_try + 1
    if (nc_n_try > n_max_retries) {
        stop(msg)
    }
    else {
        message(msg, "\nRETRYing...")
        Sys.sleep(1)
    }
} else {
    nc_retry <- F
}
debug: nc_retry <- F
debug: (while) nc_retry
debug: i_req <- i_req + 1
debug: (while) i_req <= n_reqs
debug: ncs <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size > 
    0), nc)
debug: r <- terra::rast(ncs)
debug: stopifnot(all(class(terra::time(r)) %in% c("POSIXct", "POSIXt")))
debug: idx <- dplyr::pull(dplyr::filter(dplyr::arrange(dplyr::tibble(idx = 1:terra::nlyr(r), 
    time = terra::time(r)), time), !duplicated(time)), idx)
debug: r <- terra::subset(r, idx)
debug: stopifnot(terra::crs(r, proj = T) == wgs84)
debug: if (mask_tif) r <- terra::mask(r, sf_zones)
debug: lyrs <- glue("{var}|{terra::time(r)}")
debug: if (length(dims_other) > 0 && !all(length(dims[dims_other]) == 
    1)) stop(glue("Other dimensions not yet supported: {paste(dims_other, collapse = ',')}"))
debug: names(r) <- lyrs
debug: if (!is.null(rast_tif)) {
    if (fs::file_exists(rast_tif)) {
        r_tmp_tif <- tempfile(fileext = ".tif")
        r_tmp <- c(rast(rast_tif), r)
        r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
        terra::writeRaster(r_tmp, r_tmp_tif)
        fs::file_delete(rast_tif)
        fs::file_move(r_tmp_tif, rast_tif)
        rm(r)
        rm(r_tmp)
    }
    else {
        terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
    }
    r <- terra::rast(rast_tif)
}
debug: if (fs::file_exists(rast_tif)) {
    r_tmp_tif <- tempfile(fileext = ".tif")
    r_tmp <- c(rast(rast_tif), r)
    r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
    terra::writeRaster(r_tmp, r_tmp_tif)
    fs::file_delete(rast_tif)
    fs::file_move(r_tmp_tif, rast_tif)
    rm(r)
    rm(r_tmp)
} else {
    terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
}
debug: terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
debug: r <- terra::rast(rast_tif)
debug: d_r <- mutate(tidyr::pivot_longer(sf::st_drop_geometry(sf::st_as_sf(terra::zonal(x = r, 
    z = terra::vect(dplyr::select(sf_zones, dplyr::all_of(fld_zones))), 
    fun = zonal_fun, exact = T, na.rm = T, as.polygons = T))), 
    cols = -dplyr::any_of(fld_zones), names_to = "lyr", values_to = zonal_fun), 
    time = readr::parse_datetime(str_replace(lyr, glue("{var}\\|(.*)"), 
        "\\1")))
debug: if (!is.null(zonal_csv)) write_csv(d_r, zonal_csv)
debug: write_csv(d_r, zonal_csv)
debug: if (!keep_nc) unlink(dir_nc, recursive = T)
debug: unlink(dir_nc, recursive = T)
debug: return(d_r)
Downloading 1 requests, up to 1785 time slices each
Called from: extractr::ed_extract(ed, var = v, sf_zones = ply, bbox = bb, 
    mask_tif = F, rast_tif = glue("{dir_out}/{nms}/{yr}.tif"), 
    zonal_fun = "mean", zonal_csv = glue("{dir_out}/{nms}/{yr}.csv"), 
    dir_nc = glue("{dir_out}/{nms}/{yr}_nc"), keep_nc = F, n_max_vals_per_req = 1e+05, 
    time_min = time_min, time_max = time_max, verbose = T)
debug: while (i_req <= n_reqs) {
    i_t_beg <- (i_req - 1) * n_t_per_req + 1
    i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
    t_req <- times_todo[c(i_t_beg, i_t_end)]
    t_req_str <- format_ISO8601(t_req, usetz = "Z")
    if (verbose) 
        message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
    ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
        ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
        0), nc)
    unlink(ncs0)
    nc_retry <- T
    nc_n_try <- 1
    n_max_retries
    while (nc_retry) {
        res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
            url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
                bbox[["xmax"]]), latitude = c(bbox[["ymin"]], 
                bbox[["ymax"]]), time = t_req_str, fmt = "nc", 
            store = rerddap::disk(path = dir_nc)))
        if (inherits(res, "try-error")) {
            err <- attr(res, "condition")
            msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
            nc_n_try <- nc_n_try + 1
            if (nc_n_try > n_max_retries) {
                stop(msg)
            }
            else {
                message(msg, "\nRETRYing...")
                Sys.sleep(1)
            }
        }
        else {
            nc_retry <- F
        }
    }
    i_req <- i_req + 1
}
debug: i_t_beg <- (i_req - 1) * n_t_per_req + 1
debug: i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
debug: t_req <- times_todo[c(i_t_beg, i_t_end)]
debug: t_req_str <- format_ISO8601(t_req, usetz = "Z")
debug: if (verbose) message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
debug: message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
Fetching request 1 of 1 (1998-01-01 to 1998-12-01) ~ 19:42:12 UTC
debug: ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
    0), nc)
debug: unlink(ncs0)
debug: nc_retry <- T
debug: nc_n_try <- 1
debug: n_max_retries
debug: while (nc_retry) {
    res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
        url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
            bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
        time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
    if (inherits(res, "try-error")) {
        err <- attr(res, "condition")
        msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
        nc_n_try <- nc_n_try + 1
        if (nc_n_try > n_max_retries) {
            stop(msg)
        }
        else {
            message(msg, "\nRETRYing...")
            Sys.sleep(1)
        }
    }
    else {
        nc_retry <- F
    }
}
debug: res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
    url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
        bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
    time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
debug: if (inherits(res, "try-error")) {
    err <- attr(res, "condition")
    msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
    nc_n_try <- nc_n_try + 1
    if (nc_n_try > n_max_retries) {
        stop(msg)
    }
    else {
        message(msg, "\nRETRYing...")
        Sys.sleep(1)
    }
} else {
    nc_retry <- F
}
debug: nc_retry <- F
debug: (while) nc_retry
debug: i_req <- i_req + 1
debug: (while) i_req <= n_reqs
debug: ncs <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size > 
    0), nc)
debug: r <- terra::rast(ncs)
debug: stopifnot(all(class(terra::time(r)) %in% c("POSIXct", "POSIXt")))
debug: idx <- dplyr::pull(dplyr::filter(dplyr::arrange(dplyr::tibble(idx = 1:terra::nlyr(r), 
    time = terra::time(r)), time), !duplicated(time)), idx)
debug: r <- terra::subset(r, idx)
debug: stopifnot(terra::crs(r, proj = T) == wgs84)
debug: if (mask_tif) r <- terra::mask(r, sf_zones)
debug: lyrs <- glue("{var}|{terra::time(r)}")
debug: if (length(dims_other) > 0 && !all(length(dims[dims_other]) == 
    1)) stop(glue("Other dimensions not yet supported: {paste(dims_other, collapse = ',')}"))
debug: names(r) <- lyrs
debug: if (!is.null(rast_tif)) {
    if (fs::file_exists(rast_tif)) {
        r_tmp_tif <- tempfile(fileext = ".tif")
        r_tmp <- c(rast(rast_tif), r)
        r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
        terra::writeRaster(r_tmp, r_tmp_tif)
        fs::file_delete(rast_tif)
        fs::file_move(r_tmp_tif, rast_tif)
        rm(r)
        rm(r_tmp)
    }
    else {
        terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
    }
    r <- terra::rast(rast_tif)
}
debug: if (fs::file_exists(rast_tif)) {
    r_tmp_tif <- tempfile(fileext = ".tif")
    r_tmp <- c(rast(rast_tif), r)
    r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
    terra::writeRaster(r_tmp, r_tmp_tif)
    fs::file_delete(rast_tif)
    fs::file_move(r_tmp_tif, rast_tif)
    rm(r)
    rm(r_tmp)
} else {
    terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
}
debug: terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
debug: r <- terra::rast(rast_tif)
debug: d_r <- mutate(tidyr::pivot_longer(sf::st_drop_geometry(sf::st_as_sf(terra::zonal(x = r, 
    z = terra::vect(dplyr::select(sf_zones, dplyr::all_of(fld_zones))), 
    fun = zonal_fun, exact = T, na.rm = T, as.polygons = T))), 
    cols = -dplyr::any_of(fld_zones), names_to = "lyr", values_to = zonal_fun), 
    time = readr::parse_datetime(str_replace(lyr, glue("{var}\\|(.*)"), 
        "\\1")))
debug: if (!is.null(zonal_csv)) write_csv(d_r, zonal_csv)
debug: write_csv(d_r, zonal_csv)
debug: if (!keep_nc) unlink(dir_nc, recursive = T)
debug: unlink(dir_nc, recursive = T)
debug: return(d_r)
Downloading 1 requests, up to 1785 time slices each
Called from: extractr::ed_extract(ed, var = v, sf_zones = ply, bbox = bb, 
    mask_tif = F, rast_tif = glue("{dir_out}/{nms}/{yr}.tif"), 
    zonal_fun = "mean", zonal_csv = glue("{dir_out}/{nms}/{yr}.csv"), 
    dir_nc = glue("{dir_out}/{nms}/{yr}_nc"), keep_nc = F, n_max_vals_per_req = 1e+05, 
    time_min = time_min, time_max = time_max, verbose = T)
debug: while (i_req <= n_reqs) {
    i_t_beg <- (i_req - 1) * n_t_per_req + 1
    i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
    t_req <- times_todo[c(i_t_beg, i_t_end)]
    t_req_str <- format_ISO8601(t_req, usetz = "Z")
    if (verbose) 
        message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
    ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
        ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
        0), nc)
    unlink(ncs0)
    nc_retry <- T
    nc_n_try <- 1
    n_max_retries
    while (nc_retry) {
        res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
            url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
                bbox[["xmax"]]), latitude = c(bbox[["ymin"]], 
                bbox[["ymax"]]), time = t_req_str, fmt = "nc", 
            store = rerddap::disk(path = dir_nc)))
        if (inherits(res, "try-error")) {
            err <- attr(res, "condition")
            msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
            nc_n_try <- nc_n_try + 1
            if (nc_n_try > n_max_retries) {
                stop(msg)
            }
            else {
                message(msg, "\nRETRYing...")
                Sys.sleep(1)
            }
        }
        else {
            nc_retry <- F
        }
    }
    i_req <- i_req + 1
}
debug: i_t_beg <- (i_req - 1) * n_t_per_req + 1
debug: i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
debug: t_req <- times_todo[c(i_t_beg, i_t_end)]
debug: t_req_str <- format_ISO8601(t_req, usetz = "Z")
debug: if (verbose) message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
debug: message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
Fetching request 1 of 1 (1999-01-01 to 1999-12-01) ~ 19:42:13 UTC
debug: ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
    0), nc)
debug: unlink(ncs0)
debug: nc_retry <- T
debug: nc_n_try <- 1
debug: n_max_retries
debug: while (nc_retry) {
    res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
        url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
            bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
        time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
    if (inherits(res, "try-error")) {
        err <- attr(res, "condition")
        msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
        nc_n_try <- nc_n_try + 1
        if (nc_n_try > n_max_retries) {
            stop(msg)
        }
        else {
            message(msg, "\nRETRYing...")
            Sys.sleep(1)
        }
    }
    else {
        nc_retry <- F
    }
}
debug: res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
    url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
        bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
    time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
debug: if (inherits(res, "try-error")) {
    err <- attr(res, "condition")
    msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
    nc_n_try <- nc_n_try + 1
    if (nc_n_try > n_max_retries) {
        stop(msg)
    }
    else {
        message(msg, "\nRETRYing...")
        Sys.sleep(1)
    }
} else {
    nc_retry <- F
}
debug: nc_retry <- F
debug: (while) nc_retry
debug: i_req <- i_req + 1
debug: (while) i_req <= n_reqs
debug: ncs <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size > 
    0), nc)
debug: r <- terra::rast(ncs)
debug: stopifnot(all(class(terra::time(r)) %in% c("POSIXct", "POSIXt")))
debug: idx <- dplyr::pull(dplyr::filter(dplyr::arrange(dplyr::tibble(idx = 1:terra::nlyr(r), 
    time = terra::time(r)), time), !duplicated(time)), idx)
debug: r <- terra::subset(r, idx)
debug: stopifnot(terra::crs(r, proj = T) == wgs84)
debug: if (mask_tif) r <- terra::mask(r, sf_zones)
debug: lyrs <- glue("{var}|{terra::time(r)}")
debug: if (length(dims_other) > 0 && !all(length(dims[dims_other]) == 
    1)) stop(glue("Other dimensions not yet supported: {paste(dims_other, collapse = ',')}"))
debug: names(r) <- lyrs
debug: if (!is.null(rast_tif)) {
    if (fs::file_exists(rast_tif)) {
        r_tmp_tif <- tempfile(fileext = ".tif")
        r_tmp <- c(rast(rast_tif), r)
        r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
        terra::writeRaster(r_tmp, r_tmp_tif)
        fs::file_delete(rast_tif)
        fs::file_move(r_tmp_tif, rast_tif)
        rm(r)
        rm(r_tmp)
    }
    else {
        terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
    }
    r <- terra::rast(rast_tif)
}
debug: if (fs::file_exists(rast_tif)) {
    r_tmp_tif <- tempfile(fileext = ".tif")
    r_tmp <- c(rast(rast_tif), r)
    r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
    terra::writeRaster(r_tmp, r_tmp_tif)
    fs::file_delete(rast_tif)
    fs::file_move(r_tmp_tif, rast_tif)
    rm(r)
    rm(r_tmp)
} else {
    terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
}
debug: terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
debug: r <- terra::rast(rast_tif)
debug: d_r <- mutate(tidyr::pivot_longer(sf::st_drop_geometry(sf::st_as_sf(terra::zonal(x = r, 
    z = terra::vect(dplyr::select(sf_zones, dplyr::all_of(fld_zones))), 
    fun = zonal_fun, exact = T, na.rm = T, as.polygons = T))), 
    cols = -dplyr::any_of(fld_zones), names_to = "lyr", values_to = zonal_fun), 
    time = readr::parse_datetime(str_replace(lyr, glue("{var}\\|(.*)"), 
        "\\1")))
debug: if (!is.null(zonal_csv)) write_csv(d_r, zonal_csv)
debug: write_csv(d_r, zonal_csv)
debug: if (!keep_nc) unlink(dir_nc, recursive = T)
debug: unlink(dir_nc, recursive = T)
debug: return(d_r)
Downloading 1 requests, up to 1785 time slices each
Called from: extractr::ed_extract(ed, var = v, sf_zones = ply, bbox = bb, 
    mask_tif = F, rast_tif = glue("{dir_out}/{nms}/{yr}.tif"), 
    zonal_fun = "mean", zonal_csv = glue("{dir_out}/{nms}/{yr}.csv"), 
    dir_nc = glue("{dir_out}/{nms}/{yr}_nc"), keep_nc = F, n_max_vals_per_req = 1e+05, 
    time_min = time_min, time_max = time_max, verbose = T)
debug: while (i_req <= n_reqs) {
    i_t_beg <- (i_req - 1) * n_t_per_req + 1
    i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
    t_req <- times_todo[c(i_t_beg, i_t_end)]
    t_req_str <- format_ISO8601(t_req, usetz = "Z")
    if (verbose) 
        message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
    ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
        ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
        0), nc)
    unlink(ncs0)
    nc_retry <- T
    nc_n_try <- 1
    n_max_retries
    while (nc_retry) {
        res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
            url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
                bbox[["xmax"]]), latitude = c(bbox[["ymin"]], 
                bbox[["ymax"]]), time = t_req_str, fmt = "nc", 
            store = rerddap::disk(path = dir_nc)))
        if (inherits(res, "try-error")) {
            err <- attr(res, "condition")
            msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
            nc_n_try <- nc_n_try + 1
            if (nc_n_try > n_max_retries) {
                stop(msg)
            }
            else {
                message(msg, "\nRETRYing...")
                Sys.sleep(1)
            }
        }
        else {
            nc_retry <- F
        }
    }
    i_req <- i_req + 1
}
debug: i_t_beg <- (i_req - 1) * n_t_per_req + 1
debug: i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
debug: t_req <- times_todo[c(i_t_beg, i_t_end)]
debug: t_req_str <- format_ISO8601(t_req, usetz = "Z")
debug: if (verbose) message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
debug: message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
Fetching request 1 of 1 (2000-01-01 to 2000-12-01) ~ 19:42:15 UTC
debug: ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
    0), nc)
debug: unlink(ncs0)
debug: nc_retry <- T
debug: nc_n_try <- 1
debug: n_max_retries
debug: while (nc_retry) {
    res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
        url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
            bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
        time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
    if (inherits(res, "try-error")) {
        err <- attr(res, "condition")
        msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
        nc_n_try <- nc_n_try + 1
        if (nc_n_try > n_max_retries) {
            stop(msg)
        }
        else {
            message(msg, "\nRETRYing...")
            Sys.sleep(1)
        }
    }
    else {
        nc_retry <- F
    }
}
debug: res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
    url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
        bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
    time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
debug: if (inherits(res, "try-error")) {
    err <- attr(res, "condition")
    msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
    nc_n_try <- nc_n_try + 1
    if (nc_n_try > n_max_retries) {
        stop(msg)
    }
    else {
        message(msg, "\nRETRYing...")
        Sys.sleep(1)
    }
} else {
    nc_retry <- F
}
debug: nc_retry <- F
debug: (while) nc_retry
debug: i_req <- i_req + 1
debug: (while) i_req <= n_reqs
debug: ncs <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size > 
    0), nc)
debug: r <- terra::rast(ncs)
debug: stopifnot(all(class(terra::time(r)) %in% c("POSIXct", "POSIXt")))
debug: idx <- dplyr::pull(dplyr::filter(dplyr::arrange(dplyr::tibble(idx = 1:terra::nlyr(r), 
    time = terra::time(r)), time), !duplicated(time)), idx)
debug: r <- terra::subset(r, idx)
debug: stopifnot(terra::crs(r, proj = T) == wgs84)
debug: if (mask_tif) r <- terra::mask(r, sf_zones)
debug: lyrs <- glue("{var}|{terra::time(r)}")
debug: if (length(dims_other) > 0 && !all(length(dims[dims_other]) == 
    1)) stop(glue("Other dimensions not yet supported: {paste(dims_other, collapse = ',')}"))
debug: names(r) <- lyrs
debug: if (!is.null(rast_tif)) {
    if (fs::file_exists(rast_tif)) {
        r_tmp_tif <- tempfile(fileext = ".tif")
        r_tmp <- c(rast(rast_tif), r)
        r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
        terra::writeRaster(r_tmp, r_tmp_tif)
        fs::file_delete(rast_tif)
        fs::file_move(r_tmp_tif, rast_tif)
        rm(r)
        rm(r_tmp)
    }
    else {
        terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
    }
    r <- terra::rast(rast_tif)
}
debug: if (fs::file_exists(rast_tif)) {
    r_tmp_tif <- tempfile(fileext = ".tif")
    r_tmp <- c(rast(rast_tif), r)
    r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
    terra::writeRaster(r_tmp, r_tmp_tif)
    fs::file_delete(rast_tif)
    fs::file_move(r_tmp_tif, rast_tif)
    rm(r)
    rm(r_tmp)
} else {
    terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
}
debug: terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
debug: r <- terra::rast(rast_tif)
debug: d_r <- mutate(tidyr::pivot_longer(sf::st_drop_geometry(sf::st_as_sf(terra::zonal(x = r, 
    z = terra::vect(dplyr::select(sf_zones, dplyr::all_of(fld_zones))), 
    fun = zonal_fun, exact = T, na.rm = T, as.polygons = T))), 
    cols = -dplyr::any_of(fld_zones), names_to = "lyr", values_to = zonal_fun), 
    time = readr::parse_datetime(str_replace(lyr, glue("{var}\\|(.*)"), 
        "\\1")))
debug: if (!is.null(zonal_csv)) write_csv(d_r, zonal_csv)
debug: write_csv(d_r, zonal_csv)
debug: if (!keep_nc) unlink(dir_nc, recursive = T)
debug: unlink(dir_nc, recursive = T)
debug: return(d_r)
Downloading 1 requests, up to 1785 time slices each
Called from: extractr::ed_extract(ed, var = v, sf_zones = ply, bbox = bb, 
    mask_tif = F, rast_tif = glue("{dir_out}/{nms}/{yr}.tif"), 
    zonal_fun = "mean", zonal_csv = glue("{dir_out}/{nms}/{yr}.csv"), 
    dir_nc = glue("{dir_out}/{nms}/{yr}_nc"), keep_nc = F, n_max_vals_per_req = 1e+05, 
    time_min = time_min, time_max = time_max, verbose = T)
debug: while (i_req <= n_reqs) {
    i_t_beg <- (i_req - 1) * n_t_per_req + 1
    i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
    t_req <- times_todo[c(i_t_beg, i_t_end)]
    t_req_str <- format_ISO8601(t_req, usetz = "Z")
    if (verbose) 
        message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
    ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
        ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
        0), nc)
    unlink(ncs0)
    nc_retry <- T
    nc_n_try <- 1
    n_max_retries
    while (nc_retry) {
        res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
            url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
                bbox[["xmax"]]), latitude = c(bbox[["ymin"]], 
                bbox[["ymax"]]), time = t_req_str, fmt = "nc", 
            store = rerddap::disk(path = dir_nc)))
        if (inherits(res, "try-error")) {
            err <- attr(res, "condition")
            msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
            nc_n_try <- nc_n_try + 1
            if (nc_n_try > n_max_retries) {
                stop(msg)
            }
            else {
                message(msg, "\nRETRYing...")
                Sys.sleep(1)
            }
        }
        else {
            nc_retry <- F
        }
    }
    i_req <- i_req + 1
}
debug: i_t_beg <- (i_req - 1) * n_t_per_req + 1
debug: i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
debug: t_req <- times_todo[c(i_t_beg, i_t_end)]
debug: t_req_str <- format_ISO8601(t_req, usetz = "Z")
debug: if (verbose) message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
debug: message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
Fetching request 1 of 1 (2001-01-01 to 2001-12-01) ~ 19:42:17 UTC
debug: ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
    0), nc)
debug: unlink(ncs0)
debug: nc_retry <- T
debug: nc_n_try <- 1
debug: n_max_retries
debug: while (nc_retry) {
    res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
        url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
            bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
        time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
    if (inherits(res, "try-error")) {
        err <- attr(res, "condition")
        msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
        nc_n_try <- nc_n_try + 1
        if (nc_n_try > n_max_retries) {
            stop(msg)
        }
        else {
            message(msg, "\nRETRYing...")
            Sys.sleep(1)
        }
    }
    else {
        nc_retry <- F
    }
}
debug: res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
    url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
        bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
    time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
debug: if (inherits(res, "try-error")) {
    err <- attr(res, "condition")
    msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
    nc_n_try <- nc_n_try + 1
    if (nc_n_try > n_max_retries) {
        stop(msg)
    }
    else {
        message(msg, "\nRETRYing...")
        Sys.sleep(1)
    }
} else {
    nc_retry <- F
}
debug: nc_retry <- F
debug: (while) nc_retry
debug: i_req <- i_req + 1
debug: (while) i_req <= n_reqs
debug: ncs <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size > 
    0), nc)
debug: r <- terra::rast(ncs)
debug: stopifnot(all(class(terra::time(r)) %in% c("POSIXct", "POSIXt")))
debug: idx <- dplyr::pull(dplyr::filter(dplyr::arrange(dplyr::tibble(idx = 1:terra::nlyr(r), 
    time = terra::time(r)), time), !duplicated(time)), idx)
debug: r <- terra::subset(r, idx)
debug: stopifnot(terra::crs(r, proj = T) == wgs84)
debug: if (mask_tif) r <- terra::mask(r, sf_zones)
debug: lyrs <- glue("{var}|{terra::time(r)}")
debug: if (length(dims_other) > 0 && !all(length(dims[dims_other]) == 
    1)) stop(glue("Other dimensions not yet supported: {paste(dims_other, collapse = ',')}"))
debug: names(r) <- lyrs
debug: if (!is.null(rast_tif)) {
    if (fs::file_exists(rast_tif)) {
        r_tmp_tif <- tempfile(fileext = ".tif")
        r_tmp <- c(rast(rast_tif), r)
        r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
        terra::writeRaster(r_tmp, r_tmp_tif)
        fs::file_delete(rast_tif)
        fs::file_move(r_tmp_tif, rast_tif)
        rm(r)
        rm(r_tmp)
    }
    else {
        terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
    }
    r <- terra::rast(rast_tif)
}
debug: if (fs::file_exists(rast_tif)) {
    r_tmp_tif <- tempfile(fileext = ".tif")
    r_tmp <- c(rast(rast_tif), r)
    r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
    terra::writeRaster(r_tmp, r_tmp_tif)
    fs::file_delete(rast_tif)
    fs::file_move(r_tmp_tif, rast_tif)
    rm(r)
    rm(r_tmp)
} else {
    terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
}
debug: terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
debug: r <- terra::rast(rast_tif)
debug: d_r <- mutate(tidyr::pivot_longer(sf::st_drop_geometry(sf::st_as_sf(terra::zonal(x = r, 
    z = terra::vect(dplyr::select(sf_zones, dplyr::all_of(fld_zones))), 
    fun = zonal_fun, exact = T, na.rm = T, as.polygons = T))), 
    cols = -dplyr::any_of(fld_zones), names_to = "lyr", values_to = zonal_fun), 
    time = readr::parse_datetime(str_replace(lyr, glue("{var}\\|(.*)"), 
        "\\1")))
debug: if (!is.null(zonal_csv)) write_csv(d_r, zonal_csv)
debug: write_csv(d_r, zonal_csv)
debug: if (!keep_nc) unlink(dir_nc, recursive = T)
debug: unlink(dir_nc, recursive = T)
debug: return(d_r)
Downloading 1 requests, up to 1785 time slices each
Called from: extractr::ed_extract(ed, var = v, sf_zones = ply, bbox = bb, 
    mask_tif = F, rast_tif = glue("{dir_out}/{nms}/{yr}.tif"), 
    zonal_fun = "mean", zonal_csv = glue("{dir_out}/{nms}/{yr}.csv"), 
    dir_nc = glue("{dir_out}/{nms}/{yr}_nc"), keep_nc = F, n_max_vals_per_req = 1e+05, 
    time_min = time_min, time_max = time_max, verbose = T)
debug: while (i_req <= n_reqs) {
    i_t_beg <- (i_req - 1) * n_t_per_req + 1
    i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
    t_req <- times_todo[c(i_t_beg, i_t_end)]
    t_req_str <- format_ISO8601(t_req, usetz = "Z")
    if (verbose) 
        message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
    ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
        ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
        0), nc)
    unlink(ncs0)
    nc_retry <- T
    nc_n_try <- 1
    n_max_retries
    while (nc_retry) {
        res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
            url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
                bbox[["xmax"]]), latitude = c(bbox[["ymin"]], 
                bbox[["ymax"]]), time = t_req_str, fmt = "nc", 
            store = rerddap::disk(path = dir_nc)))
        if (inherits(res, "try-error")) {
            err <- attr(res, "condition")
            msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
            nc_n_try <- nc_n_try + 1
            if (nc_n_try > n_max_retries) {
                stop(msg)
            }
            else {
                message(msg, "\nRETRYing...")
                Sys.sleep(1)
            }
        }
        else {
            nc_retry <- F
        }
    }
    i_req <- i_req + 1
}
debug: i_t_beg <- (i_req - 1) * n_t_per_req + 1
debug: i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
debug: t_req <- times_todo[c(i_t_beg, i_t_end)]
debug: t_req_str <- format_ISO8601(t_req, usetz = "Z")
debug: if (verbose) message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
debug: message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
Fetching request 1 of 1 (2002-01-01 to 2002-12-01) ~ 19:42:18 UTC
debug: ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
    0), nc)
debug: unlink(ncs0)
debug: nc_retry <- T
debug: nc_n_try <- 1
debug: n_max_retries
debug: while (nc_retry) {
    res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
        url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
            bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
        time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
    if (inherits(res, "try-error")) {
        err <- attr(res, "condition")
        msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
        nc_n_try <- nc_n_try + 1
        if (nc_n_try > n_max_retries) {
            stop(msg)
        }
        else {
            message(msg, "\nRETRYing...")
            Sys.sleep(1)
        }
    }
    else {
        nc_retry <- F
    }
}
debug: res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
    url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
        bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
    time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
debug: if (inherits(res, "try-error")) {
    err <- attr(res, "condition")
    msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
    nc_n_try <- nc_n_try + 1
    if (nc_n_try > n_max_retries) {
        stop(msg)
    }
    else {
        message(msg, "\nRETRYing...")
        Sys.sleep(1)
    }
} else {
    nc_retry <- F
}
debug: nc_retry <- F
debug: (while) nc_retry
debug: i_req <- i_req + 1
debug: (while) i_req <= n_reqs
debug: ncs <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size > 
    0), nc)
debug: r <- terra::rast(ncs)
debug: stopifnot(all(class(terra::time(r)) %in% c("POSIXct", "POSIXt")))
debug: idx <- dplyr::pull(dplyr::filter(dplyr::arrange(dplyr::tibble(idx = 1:terra::nlyr(r), 
    time = terra::time(r)), time), !duplicated(time)), idx)
debug: r <- terra::subset(r, idx)
debug: stopifnot(terra::crs(r, proj = T) == wgs84)
debug: if (mask_tif) r <- terra::mask(r, sf_zones)
debug: lyrs <- glue("{var}|{terra::time(r)}")
debug: if (length(dims_other) > 0 && !all(length(dims[dims_other]) == 
    1)) stop(glue("Other dimensions not yet supported: {paste(dims_other, collapse = ',')}"))
debug: names(r) <- lyrs
debug: if (!is.null(rast_tif)) {
    if (fs::file_exists(rast_tif)) {
        r_tmp_tif <- tempfile(fileext = ".tif")
        r_tmp <- c(rast(rast_tif), r)
        r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
        terra::writeRaster(r_tmp, r_tmp_tif)
        fs::file_delete(rast_tif)
        fs::file_move(r_tmp_tif, rast_tif)
        rm(r)
        rm(r_tmp)
    }
    else {
        terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
    }
    r <- terra::rast(rast_tif)
}
debug: if (fs::file_exists(rast_tif)) {
    r_tmp_tif <- tempfile(fileext = ".tif")
    r_tmp <- c(rast(rast_tif), r)
    r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
    terra::writeRaster(r_tmp, r_tmp_tif)
    fs::file_delete(rast_tif)
    fs::file_move(r_tmp_tif, rast_tif)
    rm(r)
    rm(r_tmp)
} else {
    terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
}
debug: terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
debug: r <- terra::rast(rast_tif)
debug: d_r <- mutate(tidyr::pivot_longer(sf::st_drop_geometry(sf::st_as_sf(terra::zonal(x = r, 
    z = terra::vect(dplyr::select(sf_zones, dplyr::all_of(fld_zones))), 
    fun = zonal_fun, exact = T, na.rm = T, as.polygons = T))), 
    cols = -dplyr::any_of(fld_zones), names_to = "lyr", values_to = zonal_fun), 
    time = readr::parse_datetime(str_replace(lyr, glue("{var}\\|(.*)"), 
        "\\1")))
debug: if (!is.null(zonal_csv)) write_csv(d_r, zonal_csv)
debug: write_csv(d_r, zonal_csv)
debug: if (!keep_nc) unlink(dir_nc, recursive = T)
debug: unlink(dir_nc, recursive = T)
debug: return(d_r)
Downloading 1 requests, up to 1785 time slices each
Called from: extractr::ed_extract(ed, var = v, sf_zones = ply, bbox = bb, 
    mask_tif = F, rast_tif = glue("{dir_out}/{nms}/{yr}.tif"), 
    zonal_fun = "mean", zonal_csv = glue("{dir_out}/{nms}/{yr}.csv"), 
    dir_nc = glue("{dir_out}/{nms}/{yr}_nc"), keep_nc = F, n_max_vals_per_req = 1e+05, 
    time_min = time_min, time_max = time_max, verbose = T)
debug: while (i_req <= n_reqs) {
    i_t_beg <- (i_req - 1) * n_t_per_req + 1
    i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
    t_req <- times_todo[c(i_t_beg, i_t_end)]
    t_req_str <- format_ISO8601(t_req, usetz = "Z")
    if (verbose) 
        message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
    ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
        ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
        0), nc)
    unlink(ncs0)
    nc_retry <- T
    nc_n_try <- 1
    n_max_retries
    while (nc_retry) {
        res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
            url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
                bbox[["xmax"]]), latitude = c(bbox[["ymin"]], 
                bbox[["ymax"]]), time = t_req_str, fmt = "nc", 
            store = rerddap::disk(path = dir_nc)))
        if (inherits(res, "try-error")) {
            err <- attr(res, "condition")
            msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
            nc_n_try <- nc_n_try + 1
            if (nc_n_try > n_max_retries) {
                stop(msg)
            }
            else {
                message(msg, "\nRETRYing...")
                Sys.sleep(1)
            }
        }
        else {
            nc_retry <- F
        }
    }
    i_req <- i_req + 1
}
debug: i_t_beg <- (i_req - 1) * n_t_per_req + 1
debug: i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
debug: t_req <- times_todo[c(i_t_beg, i_t_end)]
debug: t_req_str <- format_ISO8601(t_req, usetz = "Z")
debug: if (verbose) message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
debug: message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
Fetching request 1 of 1 (2003-01-01 to 2003-12-01) ~ 19:42:20 UTC
debug: ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
    0), nc)
debug: unlink(ncs0)
debug: nc_retry <- T
debug: nc_n_try <- 1
debug: n_max_retries
debug: while (nc_retry) {
    res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
        url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
            bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
        time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
    if (inherits(res, "try-error")) {
        err <- attr(res, "condition")
        msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
        nc_n_try <- nc_n_try + 1
        if (nc_n_try > n_max_retries) {
            stop(msg)
        }
        else {
            message(msg, "\nRETRYing...")
            Sys.sleep(1)
        }
    }
    else {
        nc_retry <- F
    }
}
debug: res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
    url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
        bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
    time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
debug: if (inherits(res, "try-error")) {
    err <- attr(res, "condition")
    msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
    nc_n_try <- nc_n_try + 1
    if (nc_n_try > n_max_retries) {
        stop(msg)
    }
    else {
        message(msg, "\nRETRYing...")
        Sys.sleep(1)
    }
} else {
    nc_retry <- F
}
debug: nc_retry <- F
debug: (while) nc_retry
debug: i_req <- i_req + 1
debug: (while) i_req <= n_reqs
debug: ncs <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size > 
    0), nc)
debug: r <- terra::rast(ncs)
debug: stopifnot(all(class(terra::time(r)) %in% c("POSIXct", "POSIXt")))
debug: idx <- dplyr::pull(dplyr::filter(dplyr::arrange(dplyr::tibble(idx = 1:terra::nlyr(r), 
    time = terra::time(r)), time), !duplicated(time)), idx)
debug: r <- terra::subset(r, idx)
debug: stopifnot(terra::crs(r, proj = T) == wgs84)
debug: if (mask_tif) r <- terra::mask(r, sf_zones)
debug: lyrs <- glue("{var}|{terra::time(r)}")
debug: if (length(dims_other) > 0 && !all(length(dims[dims_other]) == 
    1)) stop(glue("Other dimensions not yet supported: {paste(dims_other, collapse = ',')}"))
debug: names(r) <- lyrs
debug: if (!is.null(rast_tif)) {
    if (fs::file_exists(rast_tif)) {
        r_tmp_tif <- tempfile(fileext = ".tif")
        r_tmp <- c(rast(rast_tif), r)
        r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
        terra::writeRaster(r_tmp, r_tmp_tif)
        fs::file_delete(rast_tif)
        fs::file_move(r_tmp_tif, rast_tif)
        rm(r)
        rm(r_tmp)
    }
    else {
        terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
    }
    r <- terra::rast(rast_tif)
}
debug: if (fs::file_exists(rast_tif)) {
    r_tmp_tif <- tempfile(fileext = ".tif")
    r_tmp <- c(rast(rast_tif), r)
    r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
    terra::writeRaster(r_tmp, r_tmp_tif)
    fs::file_delete(rast_tif)
    fs::file_move(r_tmp_tif, rast_tif)
    rm(r)
    rm(r_tmp)
} else {
    terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
}
debug: terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
debug: r <- terra::rast(rast_tif)
debug: d_r <- mutate(tidyr::pivot_longer(sf::st_drop_geometry(sf::st_as_sf(terra::zonal(x = r, 
    z = terra::vect(dplyr::select(sf_zones, dplyr::all_of(fld_zones))), 
    fun = zonal_fun, exact = T, na.rm = T, as.polygons = T))), 
    cols = -dplyr::any_of(fld_zones), names_to = "lyr", values_to = zonal_fun), 
    time = readr::parse_datetime(str_replace(lyr, glue("{var}\\|(.*)"), 
        "\\1")))
debug: if (!is.null(zonal_csv)) write_csv(d_r, zonal_csv)
debug: write_csv(d_r, zonal_csv)
debug: if (!keep_nc) unlink(dir_nc, recursive = T)
debug: unlink(dir_nc, recursive = T)
debug: return(d_r)
Downloading 1 requests, up to 1785 time slices each
Called from: extractr::ed_extract(ed, var = v, sf_zones = ply, bbox = bb, 
    mask_tif = F, rast_tif = glue("{dir_out}/{nms}/{yr}.tif"), 
    zonal_fun = "mean", zonal_csv = glue("{dir_out}/{nms}/{yr}.csv"), 
    dir_nc = glue("{dir_out}/{nms}/{yr}_nc"), keep_nc = F, n_max_vals_per_req = 1e+05, 
    time_min = time_min, time_max = time_max, verbose = T)
debug: while (i_req <= n_reqs) {
    i_t_beg <- (i_req - 1) * n_t_per_req + 1
    i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
    t_req <- times_todo[c(i_t_beg, i_t_end)]
    t_req_str <- format_ISO8601(t_req, usetz = "Z")
    if (verbose) 
        message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
    ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
        ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
        0), nc)
    unlink(ncs0)
    nc_retry <- T
    nc_n_try <- 1
    n_max_retries
    while (nc_retry) {
        res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
            url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
                bbox[["xmax"]]), latitude = c(bbox[["ymin"]], 
                bbox[["ymax"]]), time = t_req_str, fmt = "nc", 
            store = rerddap::disk(path = dir_nc)))
        if (inherits(res, "try-error")) {
            err <- attr(res, "condition")
            msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
            nc_n_try <- nc_n_try + 1
            if (nc_n_try > n_max_retries) {
                stop(msg)
            }
            else {
                message(msg, "\nRETRYing...")
                Sys.sleep(1)
            }
        }
        else {
            nc_retry <- F
        }
    }
    i_req <- i_req + 1
}
debug: i_t_beg <- (i_req - 1) * n_t_per_req + 1
debug: i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
debug: t_req <- times_todo[c(i_t_beg, i_t_end)]
debug: t_req_str <- format_ISO8601(t_req, usetz = "Z")
debug: if (verbose) message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
debug: message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
Fetching request 1 of 1 (2004-01-01 to 2004-12-01) ~ 19:42:22 UTC
debug: ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
    0), nc)
debug: unlink(ncs0)
debug: nc_retry <- T
debug: nc_n_try <- 1
debug: n_max_retries
debug: while (nc_retry) {
    res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
        url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
            bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
        time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
    if (inherits(res, "try-error")) {
        err <- attr(res, "condition")
        msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
        nc_n_try <- nc_n_try + 1
        if (nc_n_try > n_max_retries) {
            stop(msg)
        }
        else {
            message(msg, "\nRETRYing...")
            Sys.sleep(1)
        }
    }
    else {
        nc_retry <- F
    }
}
debug: res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
    url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
        bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
    time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
debug: if (inherits(res, "try-error")) {
    err <- attr(res, "condition")
    msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
    nc_n_try <- nc_n_try + 1
    if (nc_n_try > n_max_retries) {
        stop(msg)
    }
    else {
        message(msg, "\nRETRYing...")
        Sys.sleep(1)
    }
} else {
    nc_retry <- F
}
debug: nc_retry <- F
debug: (while) nc_retry
debug: i_req <- i_req + 1
debug: (while) i_req <= n_reqs
debug: ncs <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size > 
    0), nc)
debug: r <- terra::rast(ncs)
debug: stopifnot(all(class(terra::time(r)) %in% c("POSIXct", "POSIXt")))
debug: idx <- dplyr::pull(dplyr::filter(dplyr::arrange(dplyr::tibble(idx = 1:terra::nlyr(r), 
    time = terra::time(r)), time), !duplicated(time)), idx)
debug: r <- terra::subset(r, idx)
debug: stopifnot(terra::crs(r, proj = T) == wgs84)
debug: if (mask_tif) r <- terra::mask(r, sf_zones)
debug: lyrs <- glue("{var}|{terra::time(r)}")
debug: if (length(dims_other) > 0 && !all(length(dims[dims_other]) == 
    1)) stop(glue("Other dimensions not yet supported: {paste(dims_other, collapse = ',')}"))
debug: names(r) <- lyrs
debug: if (!is.null(rast_tif)) {
    if (fs::file_exists(rast_tif)) {
        r_tmp_tif <- tempfile(fileext = ".tif")
        r_tmp <- c(rast(rast_tif), r)
        r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
        terra::writeRaster(r_tmp, r_tmp_tif)
        fs::file_delete(rast_tif)
        fs::file_move(r_tmp_tif, rast_tif)
        rm(r)
        rm(r_tmp)
    }
    else {
        terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
    }
    r <- terra::rast(rast_tif)
}
debug: if (fs::file_exists(rast_tif)) {
    r_tmp_tif <- tempfile(fileext = ".tif")
    r_tmp <- c(rast(rast_tif), r)
    r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
    terra::writeRaster(r_tmp, r_tmp_tif)
    fs::file_delete(rast_tif)
    fs::file_move(r_tmp_tif, rast_tif)
    rm(r)
    rm(r_tmp)
} else {
    terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
}
debug: terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
debug: r <- terra::rast(rast_tif)
debug: d_r <- mutate(tidyr::pivot_longer(sf::st_drop_geometry(sf::st_as_sf(terra::zonal(x = r, 
    z = terra::vect(dplyr::select(sf_zones, dplyr::all_of(fld_zones))), 
    fun = zonal_fun, exact = T, na.rm = T, as.polygons = T))), 
    cols = -dplyr::any_of(fld_zones), names_to = "lyr", values_to = zonal_fun), 
    time = readr::parse_datetime(str_replace(lyr, glue("{var}\\|(.*)"), 
        "\\1")))
debug: if (!is.null(zonal_csv)) write_csv(d_r, zonal_csv)
debug: write_csv(d_r, zonal_csv)
debug: if (!keep_nc) unlink(dir_nc, recursive = T)
debug: unlink(dir_nc, recursive = T)
debug: return(d_r)
Downloading 1 requests, up to 1785 time slices each
Called from: extractr::ed_extract(ed, var = v, sf_zones = ply, bbox = bb, 
    mask_tif = F, rast_tif = glue("{dir_out}/{nms}/{yr}.tif"), 
    zonal_fun = "mean", zonal_csv = glue("{dir_out}/{nms}/{yr}.csv"), 
    dir_nc = glue("{dir_out}/{nms}/{yr}_nc"), keep_nc = F, n_max_vals_per_req = 1e+05, 
    time_min = time_min, time_max = time_max, verbose = T)
debug: while (i_req <= n_reqs) {
    i_t_beg <- (i_req - 1) * n_t_per_req + 1
    i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
    t_req <- times_todo[c(i_t_beg, i_t_end)]
    t_req_str <- format_ISO8601(t_req, usetz = "Z")
    if (verbose) 
        message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
    ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
        ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
        0), nc)
    unlink(ncs0)
    nc_retry <- T
    nc_n_try <- 1
    n_max_retries
    while (nc_retry) {
        res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
            url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
                bbox[["xmax"]]), latitude = c(bbox[["ymin"]], 
                bbox[["ymax"]]), time = t_req_str, fmt = "nc", 
            store = rerddap::disk(path = dir_nc)))
        if (inherits(res, "try-error")) {
            err <- attr(res, "condition")
            msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
            nc_n_try <- nc_n_try + 1
            if (nc_n_try > n_max_retries) {
                stop(msg)
            }
            else {
                message(msg, "\nRETRYing...")
                Sys.sleep(1)
            }
        }
        else {
            nc_retry <- F
        }
    }
    i_req <- i_req + 1
}
debug: i_t_beg <- (i_req - 1) * n_t_per_req + 1
debug: i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
debug: t_req <- times_todo[c(i_t_beg, i_t_end)]
debug: t_req_str <- format_ISO8601(t_req, usetz = "Z")
debug: if (verbose) message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
debug: message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
Fetching request 1 of 1 (2005-01-01 to 2005-12-01) ~ 19:42:23 UTC
debug: ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
    0), nc)
debug: unlink(ncs0)
debug: nc_retry <- T
debug: nc_n_try <- 1
debug: n_max_retries
debug: while (nc_retry) {
    res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
        url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
            bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
        time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
    if (inherits(res, "try-error")) {
        err <- attr(res, "condition")
        msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
        nc_n_try <- nc_n_try + 1
        if (nc_n_try > n_max_retries) {
            stop(msg)
        }
        else {
            message(msg, "\nRETRYing...")
            Sys.sleep(1)
        }
    }
    else {
        nc_retry <- F
    }
}
debug: res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
    url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
        bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
    time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
debug: if (inherits(res, "try-error")) {
    err <- attr(res, "condition")
    msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
    nc_n_try <- nc_n_try + 1
    if (nc_n_try > n_max_retries) {
        stop(msg)
    }
    else {
        message(msg, "\nRETRYing...")
        Sys.sleep(1)
    }
} else {
    nc_retry <- F
}
debug: nc_retry <- F
debug: (while) nc_retry
debug: i_req <- i_req + 1
debug: (while) i_req <= n_reqs
debug: ncs <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size > 
    0), nc)
debug: r <- terra::rast(ncs)
debug: stopifnot(all(class(terra::time(r)) %in% c("POSIXct", "POSIXt")))
debug: idx <- dplyr::pull(dplyr::filter(dplyr::arrange(dplyr::tibble(idx = 1:terra::nlyr(r), 
    time = terra::time(r)), time), !duplicated(time)), idx)
debug: r <- terra::subset(r, idx)
debug: stopifnot(terra::crs(r, proj = T) == wgs84)
debug: if (mask_tif) r <- terra::mask(r, sf_zones)
debug: lyrs <- glue("{var}|{terra::time(r)}")
debug: if (length(dims_other) > 0 && !all(length(dims[dims_other]) == 
    1)) stop(glue("Other dimensions not yet supported: {paste(dims_other, collapse = ',')}"))
debug: names(r) <- lyrs
debug: if (!is.null(rast_tif)) {
    if (fs::file_exists(rast_tif)) {
        r_tmp_tif <- tempfile(fileext = ".tif")
        r_tmp <- c(rast(rast_tif), r)
        r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
        terra::writeRaster(r_tmp, r_tmp_tif)
        fs::file_delete(rast_tif)
        fs::file_move(r_tmp_tif, rast_tif)
        rm(r)
        rm(r_tmp)
    }
    else {
        terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
    }
    r <- terra::rast(rast_tif)
}
debug: if (fs::file_exists(rast_tif)) {
    r_tmp_tif <- tempfile(fileext = ".tif")
    r_tmp <- c(rast(rast_tif), r)
    r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
    terra::writeRaster(r_tmp, r_tmp_tif)
    fs::file_delete(rast_tif)
    fs::file_move(r_tmp_tif, rast_tif)
    rm(r)
    rm(r_tmp)
} else {
    terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
}
debug: terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
debug: r <- terra::rast(rast_tif)
debug: d_r <- mutate(tidyr::pivot_longer(sf::st_drop_geometry(sf::st_as_sf(terra::zonal(x = r, 
    z = terra::vect(dplyr::select(sf_zones, dplyr::all_of(fld_zones))), 
    fun = zonal_fun, exact = T, na.rm = T, as.polygons = T))), 
    cols = -dplyr::any_of(fld_zones), names_to = "lyr", values_to = zonal_fun), 
    time = readr::parse_datetime(str_replace(lyr, glue("{var}\\|(.*)"), 
        "\\1")))
debug: if (!is.null(zonal_csv)) write_csv(d_r, zonal_csv)
debug: write_csv(d_r, zonal_csv)
debug: if (!keep_nc) unlink(dir_nc, recursive = T)
debug: unlink(dir_nc, recursive = T)
debug: return(d_r)
Downloading 1 requests, up to 1785 time slices each
Called from: extractr::ed_extract(ed, var = v, sf_zones = ply, bbox = bb, 
    mask_tif = F, rast_tif = glue("{dir_out}/{nms}/{yr}.tif"), 
    zonal_fun = "mean", zonal_csv = glue("{dir_out}/{nms}/{yr}.csv"), 
    dir_nc = glue("{dir_out}/{nms}/{yr}_nc"), keep_nc = F, n_max_vals_per_req = 1e+05, 
    time_min = time_min, time_max = time_max, verbose = T)
debug: while (i_req <= n_reqs) {
    i_t_beg <- (i_req - 1) * n_t_per_req + 1
    i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
    t_req <- times_todo[c(i_t_beg, i_t_end)]
    t_req_str <- format_ISO8601(t_req, usetz = "Z")
    if (verbose) 
        message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
    ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
        ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
        0), nc)
    unlink(ncs0)
    nc_retry <- T
    nc_n_try <- 1
    n_max_retries
    while (nc_retry) {
        res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
            url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
                bbox[["xmax"]]), latitude = c(bbox[["ymin"]], 
                bbox[["ymax"]]), time = t_req_str, fmt = "nc", 
            store = rerddap::disk(path = dir_nc)))
        if (inherits(res, "try-error")) {
            err <- attr(res, "condition")
            msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
            nc_n_try <- nc_n_try + 1
            if (nc_n_try > n_max_retries) {
                stop(msg)
            }
            else {
                message(msg, "\nRETRYing...")
                Sys.sleep(1)
            }
        }
        else {
            nc_retry <- F
        }
    }
    i_req <- i_req + 1
}
debug: i_t_beg <- (i_req - 1) * n_t_per_req + 1
debug: i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
debug: t_req <- times_todo[c(i_t_beg, i_t_end)]
debug: t_req_str <- format_ISO8601(t_req, usetz = "Z")
debug: if (verbose) message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
debug: message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
Fetching request 1 of 1 (2006-01-01 to 2006-12-01) ~ 19:42:25 UTC
debug: ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
    0), nc)
debug: unlink(ncs0)
debug: nc_retry <- T
debug: nc_n_try <- 1
debug: n_max_retries
debug: while (nc_retry) {
    res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
        url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
            bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
        time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
    if (inherits(res, "try-error")) {
        err <- attr(res, "condition")
        msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
        nc_n_try <- nc_n_try + 1
        if (nc_n_try > n_max_retries) {
            stop(msg)
        }
        else {
            message(msg, "\nRETRYing...")
            Sys.sleep(1)
        }
    }
    else {
        nc_retry <- F
    }
}
debug: res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
    url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
        bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
    time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
debug: if (inherits(res, "try-error")) {
    err <- attr(res, "condition")
    msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
    nc_n_try <- nc_n_try + 1
    if (nc_n_try > n_max_retries) {
        stop(msg)
    }
    else {
        message(msg, "\nRETRYing...")
        Sys.sleep(1)
    }
} else {
    nc_retry <- F
}
debug: nc_retry <- F
debug: (while) nc_retry
debug: i_req <- i_req + 1
debug: (while) i_req <= n_reqs
debug: ncs <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size > 
    0), nc)
debug: r <- terra::rast(ncs)
debug: stopifnot(all(class(terra::time(r)) %in% c("POSIXct", "POSIXt")))
debug: idx <- dplyr::pull(dplyr::filter(dplyr::arrange(dplyr::tibble(idx = 1:terra::nlyr(r), 
    time = terra::time(r)), time), !duplicated(time)), idx)
debug: r <- terra::subset(r, idx)
debug: stopifnot(terra::crs(r, proj = T) == wgs84)
debug: if (mask_tif) r <- terra::mask(r, sf_zones)
debug: lyrs <- glue("{var}|{terra::time(r)}")
debug: if (length(dims_other) > 0 && !all(length(dims[dims_other]) == 
    1)) stop(glue("Other dimensions not yet supported: {paste(dims_other, collapse = ',')}"))
debug: names(r) <- lyrs
debug: if (!is.null(rast_tif)) {
    if (fs::file_exists(rast_tif)) {
        r_tmp_tif <- tempfile(fileext = ".tif")
        r_tmp <- c(rast(rast_tif), r)
        r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
        terra::writeRaster(r_tmp, r_tmp_tif)
        fs::file_delete(rast_tif)
        fs::file_move(r_tmp_tif, rast_tif)
        rm(r)
        rm(r_tmp)
    }
    else {
        terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
    }
    r <- terra::rast(rast_tif)
}
debug: if (fs::file_exists(rast_tif)) {
    r_tmp_tif <- tempfile(fileext = ".tif")
    r_tmp <- c(rast(rast_tif), r)
    r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
    terra::writeRaster(r_tmp, r_tmp_tif)
    fs::file_delete(rast_tif)
    fs::file_move(r_tmp_tif, rast_tif)
    rm(r)
    rm(r_tmp)
} else {
    terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
}
debug: terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
debug: r <- terra::rast(rast_tif)
debug: d_r <- mutate(tidyr::pivot_longer(sf::st_drop_geometry(sf::st_as_sf(terra::zonal(x = r, 
    z = terra::vect(dplyr::select(sf_zones, dplyr::all_of(fld_zones))), 
    fun = zonal_fun, exact = T, na.rm = T, as.polygons = T))), 
    cols = -dplyr::any_of(fld_zones), names_to = "lyr", values_to = zonal_fun), 
    time = readr::parse_datetime(str_replace(lyr, glue("{var}\\|(.*)"), 
        "\\1")))
debug: if (!is.null(zonal_csv)) write_csv(d_r, zonal_csv)
debug: write_csv(d_r, zonal_csv)
debug: if (!keep_nc) unlink(dir_nc, recursive = T)
debug: unlink(dir_nc, recursive = T)
debug: return(d_r)
Downloading 1 requests, up to 1785 time slices each
Called from: extractr::ed_extract(ed, var = v, sf_zones = ply, bbox = bb, 
    mask_tif = F, rast_tif = glue("{dir_out}/{nms}/{yr}.tif"), 
    zonal_fun = "mean", zonal_csv = glue("{dir_out}/{nms}/{yr}.csv"), 
    dir_nc = glue("{dir_out}/{nms}/{yr}_nc"), keep_nc = F, n_max_vals_per_req = 1e+05, 
    time_min = time_min, time_max = time_max, verbose = T)
debug: while (i_req <= n_reqs) {
    i_t_beg <- (i_req - 1) * n_t_per_req + 1
    i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
    t_req <- times_todo[c(i_t_beg, i_t_end)]
    t_req_str <- format_ISO8601(t_req, usetz = "Z")
    if (verbose) 
        message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
    ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
        ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
        0), nc)
    unlink(ncs0)
    nc_retry <- T
    nc_n_try <- 1
    n_max_retries
    while (nc_retry) {
        res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
            url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
                bbox[["xmax"]]), latitude = c(bbox[["ymin"]], 
                bbox[["ymax"]]), time = t_req_str, fmt = "nc", 
            store = rerddap::disk(path = dir_nc)))
        if (inherits(res, "try-error")) {
            err <- attr(res, "condition")
            msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
            nc_n_try <- nc_n_try + 1
            if (nc_n_try > n_max_retries) {
                stop(msg)
            }
            else {
                message(msg, "\nRETRYing...")
                Sys.sleep(1)
            }
        }
        else {
            nc_retry <- F
        }
    }
    i_req <- i_req + 1
}
debug: i_t_beg <- (i_req - 1) * n_t_per_req + 1
debug: i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
debug: t_req <- times_todo[c(i_t_beg, i_t_end)]
debug: t_req_str <- format_ISO8601(t_req, usetz = "Z")
debug: if (verbose) message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
debug: message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
Fetching request 1 of 1 (2007-01-01 to 2007-12-01) ~ 19:42:26 UTC
debug: ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
    0), nc)
debug: unlink(ncs0)
debug: nc_retry <- T
debug: nc_n_try <- 1
debug: n_max_retries
debug: while (nc_retry) {
    res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
        url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
            bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
        time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
    if (inherits(res, "try-error")) {
        err <- attr(res, "condition")
        msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
        nc_n_try <- nc_n_try + 1
        if (nc_n_try > n_max_retries) {
            stop(msg)
        }
        else {
            message(msg, "\nRETRYing...")
            Sys.sleep(1)
        }
    }
    else {
        nc_retry <- F
    }
}
debug: res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
    url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
        bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
    time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
debug: if (inherits(res, "try-error")) {
    err <- attr(res, "condition")
    msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
    nc_n_try <- nc_n_try + 1
    if (nc_n_try > n_max_retries) {
        stop(msg)
    }
    else {
        message(msg, "\nRETRYing...")
        Sys.sleep(1)
    }
} else {
    nc_retry <- F
}
debug: nc_retry <- F
debug: (while) nc_retry
debug: i_req <- i_req + 1
debug: (while) i_req <= n_reqs
debug: ncs <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size > 
    0), nc)
debug: r <- terra::rast(ncs)
debug: stopifnot(all(class(terra::time(r)) %in% c("POSIXct", "POSIXt")))
debug: idx <- dplyr::pull(dplyr::filter(dplyr::arrange(dplyr::tibble(idx = 1:terra::nlyr(r), 
    time = terra::time(r)), time), !duplicated(time)), idx)
debug: r <- terra::subset(r, idx)
debug: stopifnot(terra::crs(r, proj = T) == wgs84)
debug: if (mask_tif) r <- terra::mask(r, sf_zones)
debug: lyrs <- glue("{var}|{terra::time(r)}")
debug: if (length(dims_other) > 0 && !all(length(dims[dims_other]) == 
    1)) stop(glue("Other dimensions not yet supported: {paste(dims_other, collapse = ',')}"))
debug: names(r) <- lyrs
debug: if (!is.null(rast_tif)) {
    if (fs::file_exists(rast_tif)) {
        r_tmp_tif <- tempfile(fileext = ".tif")
        r_tmp <- c(rast(rast_tif), r)
        r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
        terra::writeRaster(r_tmp, r_tmp_tif)
        fs::file_delete(rast_tif)
        fs::file_move(r_tmp_tif, rast_tif)
        rm(r)
        rm(r_tmp)
    }
    else {
        terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
    }
    r <- terra::rast(rast_tif)
}
debug: if (fs::file_exists(rast_tif)) {
    r_tmp_tif <- tempfile(fileext = ".tif")
    r_tmp <- c(rast(rast_tif), r)
    r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
    terra::writeRaster(r_tmp, r_tmp_tif)
    fs::file_delete(rast_tif)
    fs::file_move(r_tmp_tif, rast_tif)
    rm(r)
    rm(r_tmp)
} else {
    terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
}
debug: terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
debug: r <- terra::rast(rast_tif)
debug: d_r <- mutate(tidyr::pivot_longer(sf::st_drop_geometry(sf::st_as_sf(terra::zonal(x = r, 
    z = terra::vect(dplyr::select(sf_zones, dplyr::all_of(fld_zones))), 
    fun = zonal_fun, exact = T, na.rm = T, as.polygons = T))), 
    cols = -dplyr::any_of(fld_zones), names_to = "lyr", values_to = zonal_fun), 
    time = readr::parse_datetime(str_replace(lyr, glue("{var}\\|(.*)"), 
        "\\1")))
debug: if (!is.null(zonal_csv)) write_csv(d_r, zonal_csv)
debug: write_csv(d_r, zonal_csv)
debug: if (!keep_nc) unlink(dir_nc, recursive = T)
debug: unlink(dir_nc, recursive = T)
debug: return(d_r)
Downloading 1 requests, up to 1785 time slices each
Called from: extractr::ed_extract(ed, var = v, sf_zones = ply, bbox = bb, 
    mask_tif = F, rast_tif = glue("{dir_out}/{nms}/{yr}.tif"), 
    zonal_fun = "mean", zonal_csv = glue("{dir_out}/{nms}/{yr}.csv"), 
    dir_nc = glue("{dir_out}/{nms}/{yr}_nc"), keep_nc = F, n_max_vals_per_req = 1e+05, 
    time_min = time_min, time_max = time_max, verbose = T)
debug: while (i_req <= n_reqs) {
    i_t_beg <- (i_req - 1) * n_t_per_req + 1
    i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
    t_req <- times_todo[c(i_t_beg, i_t_end)]
    t_req_str <- format_ISO8601(t_req, usetz = "Z")
    if (verbose) 
        message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
    ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
        ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
        0), nc)
    unlink(ncs0)
    nc_retry <- T
    nc_n_try <- 1
    n_max_retries
    while (nc_retry) {
        res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
            url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
                bbox[["xmax"]]), latitude = c(bbox[["ymin"]], 
                bbox[["ymax"]]), time = t_req_str, fmt = "nc", 
            store = rerddap::disk(path = dir_nc)))
        if (inherits(res, "try-error")) {
            err <- attr(res, "condition")
            msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
            nc_n_try <- nc_n_try + 1
            if (nc_n_try > n_max_retries) {
                stop(msg)
            }
            else {
                message(msg, "\nRETRYing...")
                Sys.sleep(1)
            }
        }
        else {
            nc_retry <- F
        }
    }
    i_req <- i_req + 1
}
debug: i_t_beg <- (i_req - 1) * n_t_per_req + 1
debug: i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
debug: t_req <- times_todo[c(i_t_beg, i_t_end)]
debug: t_req_str <- format_ISO8601(t_req, usetz = "Z")
debug: if (verbose) message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
debug: message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
Fetching request 1 of 1 (2008-01-01 to 2008-12-01) ~ 19:42:28 UTC
debug: ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
    0), nc)
debug: unlink(ncs0)
debug: nc_retry <- T
debug: nc_n_try <- 1
debug: n_max_retries
debug: while (nc_retry) {
    res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
        url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
            bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
        time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
    if (inherits(res, "try-error")) {
        err <- attr(res, "condition")
        msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
        nc_n_try <- nc_n_try + 1
        if (nc_n_try > n_max_retries) {
            stop(msg)
        }
        else {
            message(msg, "\nRETRYing...")
            Sys.sleep(1)
        }
    }
    else {
        nc_retry <- F
    }
}
debug: res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
    url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
        bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
    time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
debug: if (inherits(res, "try-error")) {
    err <- attr(res, "condition")
    msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
    nc_n_try <- nc_n_try + 1
    if (nc_n_try > n_max_retries) {
        stop(msg)
    }
    else {
        message(msg, "\nRETRYing...")
        Sys.sleep(1)
    }
} else {
    nc_retry <- F
}
debug: nc_retry <- F
debug: (while) nc_retry
debug: i_req <- i_req + 1
debug: (while) i_req <= n_reqs
debug: ncs <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size > 
    0), nc)
debug: r <- terra::rast(ncs)
debug: stopifnot(all(class(terra::time(r)) %in% c("POSIXct", "POSIXt")))
debug: idx <- dplyr::pull(dplyr::filter(dplyr::arrange(dplyr::tibble(idx = 1:terra::nlyr(r), 
    time = terra::time(r)), time), !duplicated(time)), idx)
debug: r <- terra::subset(r, idx)
debug: stopifnot(terra::crs(r, proj = T) == wgs84)
debug: if (mask_tif) r <- terra::mask(r, sf_zones)
debug: lyrs <- glue("{var}|{terra::time(r)}")
debug: if (length(dims_other) > 0 && !all(length(dims[dims_other]) == 
    1)) stop(glue("Other dimensions not yet supported: {paste(dims_other, collapse = ',')}"))
debug: names(r) <- lyrs
debug: if (!is.null(rast_tif)) {
    if (fs::file_exists(rast_tif)) {
        r_tmp_tif <- tempfile(fileext = ".tif")
        r_tmp <- c(rast(rast_tif), r)
        r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
        terra::writeRaster(r_tmp, r_tmp_tif)
        fs::file_delete(rast_tif)
        fs::file_move(r_tmp_tif, rast_tif)
        rm(r)
        rm(r_tmp)
    }
    else {
        terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
    }
    r <- terra::rast(rast_tif)
}
debug: if (fs::file_exists(rast_tif)) {
    r_tmp_tif <- tempfile(fileext = ".tif")
    r_tmp <- c(rast(rast_tif), r)
    r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
    terra::writeRaster(r_tmp, r_tmp_tif)
    fs::file_delete(rast_tif)
    fs::file_move(r_tmp_tif, rast_tif)
    rm(r)
    rm(r_tmp)
} else {
    terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
}
debug: terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
debug: r <- terra::rast(rast_tif)
debug: d_r <- mutate(tidyr::pivot_longer(sf::st_drop_geometry(sf::st_as_sf(terra::zonal(x = r, 
    z = terra::vect(dplyr::select(sf_zones, dplyr::all_of(fld_zones))), 
    fun = zonal_fun, exact = T, na.rm = T, as.polygons = T))), 
    cols = -dplyr::any_of(fld_zones), names_to = "lyr", values_to = zonal_fun), 
    time = readr::parse_datetime(str_replace(lyr, glue("{var}\\|(.*)"), 
        "\\1")))
debug: if (!is.null(zonal_csv)) write_csv(d_r, zonal_csv)
debug: write_csv(d_r, zonal_csv)
debug: if (!keep_nc) unlink(dir_nc, recursive = T)
debug: unlink(dir_nc, recursive = T)
debug: return(d_r)
Downloading 1 requests, up to 1785 time slices each
Called from: extractr::ed_extract(ed, var = v, sf_zones = ply, bbox = bb, 
    mask_tif = F, rast_tif = glue("{dir_out}/{nms}/{yr}.tif"), 
    zonal_fun = "mean", zonal_csv = glue("{dir_out}/{nms}/{yr}.csv"), 
    dir_nc = glue("{dir_out}/{nms}/{yr}_nc"), keep_nc = F, n_max_vals_per_req = 1e+05, 
    time_min = time_min, time_max = time_max, verbose = T)
debug: while (i_req <= n_reqs) {
    i_t_beg <- (i_req - 1) * n_t_per_req + 1
    i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
    t_req <- times_todo[c(i_t_beg, i_t_end)]
    t_req_str <- format_ISO8601(t_req, usetz = "Z")
    if (verbose) 
        message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
    ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
        ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
        0), nc)
    unlink(ncs0)
    nc_retry <- T
    nc_n_try <- 1
    n_max_retries
    while (nc_retry) {
        res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
            url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
                bbox[["xmax"]]), latitude = c(bbox[["ymin"]], 
                bbox[["ymax"]]), time = t_req_str, fmt = "nc", 
            store = rerddap::disk(path = dir_nc)))
        if (inherits(res, "try-error")) {
            err <- attr(res, "condition")
            msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
            nc_n_try <- nc_n_try + 1
            if (nc_n_try > n_max_retries) {
                stop(msg)
            }
            else {
                message(msg, "\nRETRYing...")
                Sys.sleep(1)
            }
        }
        else {
            nc_retry <- F
        }
    }
    i_req <- i_req + 1
}
debug: i_t_beg <- (i_req - 1) * n_t_per_req + 1
debug: i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
debug: t_req <- times_todo[c(i_t_beg, i_t_end)]
debug: t_req_str <- format_ISO8601(t_req, usetz = "Z")
debug: if (verbose) message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
debug: message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
Fetching request 1 of 1 (2009-01-01 to 2009-12-01) ~ 19:42:30 UTC
debug: ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
    0), nc)
debug: unlink(ncs0)
debug: nc_retry <- T
debug: nc_n_try <- 1
debug: n_max_retries
debug: while (nc_retry) {
    res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
        url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
            bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
        time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
    if (inherits(res, "try-error")) {
        err <- attr(res, "condition")
        msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
        nc_n_try <- nc_n_try + 1
        if (nc_n_try > n_max_retries) {
            stop(msg)
        }
        else {
            message(msg, "\nRETRYing...")
            Sys.sleep(1)
        }
    }
    else {
        nc_retry <- F
    }
}
debug: res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
    url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
        bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
    time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
debug: if (inherits(res, "try-error")) {
    err <- attr(res, "condition")
    msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
    nc_n_try <- nc_n_try + 1
    if (nc_n_try > n_max_retries) {
        stop(msg)
    }
    else {
        message(msg, "\nRETRYing...")
        Sys.sleep(1)
    }
} else {
    nc_retry <- F
}
debug: nc_retry <- F
debug: (while) nc_retry
debug: i_req <- i_req + 1
debug: (while) i_req <= n_reqs
debug: ncs <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size > 
    0), nc)
debug: r <- terra::rast(ncs)
debug: stopifnot(all(class(terra::time(r)) %in% c("POSIXct", "POSIXt")))
debug: idx <- dplyr::pull(dplyr::filter(dplyr::arrange(dplyr::tibble(idx = 1:terra::nlyr(r), 
    time = terra::time(r)), time), !duplicated(time)), idx)
debug: r <- terra::subset(r, idx)
debug: stopifnot(terra::crs(r, proj = T) == wgs84)
debug: if (mask_tif) r <- terra::mask(r, sf_zones)
debug: lyrs <- glue("{var}|{terra::time(r)}")
debug: if (length(dims_other) > 0 && !all(length(dims[dims_other]) == 
    1)) stop(glue("Other dimensions not yet supported: {paste(dims_other, collapse = ',')}"))
debug: names(r) <- lyrs
debug: if (!is.null(rast_tif)) {
    if (fs::file_exists(rast_tif)) {
        r_tmp_tif <- tempfile(fileext = ".tif")
        r_tmp <- c(rast(rast_tif), r)
        r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
        terra::writeRaster(r_tmp, r_tmp_tif)
        fs::file_delete(rast_tif)
        fs::file_move(r_tmp_tif, rast_tif)
        rm(r)
        rm(r_tmp)
    }
    else {
        terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
    }
    r <- terra::rast(rast_tif)
}
debug: if (fs::file_exists(rast_tif)) {
    r_tmp_tif <- tempfile(fileext = ".tif")
    r_tmp <- c(rast(rast_tif), r)
    r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
    terra::writeRaster(r_tmp, r_tmp_tif)
    fs::file_delete(rast_tif)
    fs::file_move(r_tmp_tif, rast_tif)
    rm(r)
    rm(r_tmp)
} else {
    terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
}
debug: terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
debug: r <- terra::rast(rast_tif)
debug: d_r <- mutate(tidyr::pivot_longer(sf::st_drop_geometry(sf::st_as_sf(terra::zonal(x = r, 
    z = terra::vect(dplyr::select(sf_zones, dplyr::all_of(fld_zones))), 
    fun = zonal_fun, exact = T, na.rm = T, as.polygons = T))), 
    cols = -dplyr::any_of(fld_zones), names_to = "lyr", values_to = zonal_fun), 
    time = readr::parse_datetime(str_replace(lyr, glue("{var}\\|(.*)"), 
        "\\1")))
debug: if (!is.null(zonal_csv)) write_csv(d_r, zonal_csv)
debug: write_csv(d_r, zonal_csv)
debug: if (!keep_nc) unlink(dir_nc, recursive = T)
debug: unlink(dir_nc, recursive = T)
debug: return(d_r)
Downloading 1 requests, up to 1785 time slices each
Called from: extractr::ed_extract(ed, var = v, sf_zones = ply, bbox = bb, 
    mask_tif = F, rast_tif = glue("{dir_out}/{nms}/{yr}.tif"), 
    zonal_fun = "mean", zonal_csv = glue("{dir_out}/{nms}/{yr}.csv"), 
    dir_nc = glue("{dir_out}/{nms}/{yr}_nc"), keep_nc = F, n_max_vals_per_req = 1e+05, 
    time_min = time_min, time_max = time_max, verbose = T)
debug: while (i_req <= n_reqs) {
    i_t_beg <- (i_req - 1) * n_t_per_req + 1
    i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
    t_req <- times_todo[c(i_t_beg, i_t_end)]
    t_req_str <- format_ISO8601(t_req, usetz = "Z")
    if (verbose) 
        message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
    ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
        ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
        0), nc)
    unlink(ncs0)
    nc_retry <- T
    nc_n_try <- 1
    n_max_retries
    while (nc_retry) {
        res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
            url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
                bbox[["xmax"]]), latitude = c(bbox[["ymin"]], 
                bbox[["ymax"]]), time = t_req_str, fmt = "nc", 
            store = rerddap::disk(path = dir_nc)))
        if (inherits(res, "try-error")) {
            err <- attr(res, "condition")
            msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
            nc_n_try <- nc_n_try + 1
            if (nc_n_try > n_max_retries) {
                stop(msg)
            }
            else {
                message(msg, "\nRETRYing...")
                Sys.sleep(1)
            }
        }
        else {
            nc_retry <- F
        }
    }
    i_req <- i_req + 1
}
debug: i_t_beg <- (i_req - 1) * n_t_per_req + 1
debug: i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
debug: t_req <- times_todo[c(i_t_beg, i_t_end)]
debug: t_req_str <- format_ISO8601(t_req, usetz = "Z")
debug: if (verbose) message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
debug: message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
Fetching request 1 of 1 (2010-01-01 to 2010-12-01) ~ 19:42:31 UTC
debug: ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
    0), nc)
debug: unlink(ncs0)
debug: nc_retry <- T
debug: nc_n_try <- 1
debug: n_max_retries
debug: while (nc_retry) {
    res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
        url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
            bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
        time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
    if (inherits(res, "try-error")) {
        err <- attr(res, "condition")
        msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
        nc_n_try <- nc_n_try + 1
        if (nc_n_try > n_max_retries) {
            stop(msg)
        }
        else {
            message(msg, "\nRETRYing...")
            Sys.sleep(1)
        }
    }
    else {
        nc_retry <- F
    }
}
debug: res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
    url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
        bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
    time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
debug: if (inherits(res, "try-error")) {
    err <- attr(res, "condition")
    msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
    nc_n_try <- nc_n_try + 1
    if (nc_n_try > n_max_retries) {
        stop(msg)
    }
    else {
        message(msg, "\nRETRYing...")
        Sys.sleep(1)
    }
} else {
    nc_retry <- F
}
debug: nc_retry <- F
debug: (while) nc_retry
debug: i_req <- i_req + 1
debug: (while) i_req <= n_reqs
debug: ncs <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size > 
    0), nc)
debug: r <- terra::rast(ncs)
debug: stopifnot(all(class(terra::time(r)) %in% c("POSIXct", "POSIXt")))
debug: idx <- dplyr::pull(dplyr::filter(dplyr::arrange(dplyr::tibble(idx = 1:terra::nlyr(r), 
    time = terra::time(r)), time), !duplicated(time)), idx)
debug: r <- terra::subset(r, idx)
debug: stopifnot(terra::crs(r, proj = T) == wgs84)
debug: if (mask_tif) r <- terra::mask(r, sf_zones)
debug: lyrs <- glue("{var}|{terra::time(r)}")
debug: if (length(dims_other) > 0 && !all(length(dims[dims_other]) == 
    1)) stop(glue("Other dimensions not yet supported: {paste(dims_other, collapse = ',')}"))
debug: names(r) <- lyrs
debug: if (!is.null(rast_tif)) {
    if (fs::file_exists(rast_tif)) {
        r_tmp_tif <- tempfile(fileext = ".tif")
        r_tmp <- c(rast(rast_tif), r)
        r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
        terra::writeRaster(r_tmp, r_tmp_tif)
        fs::file_delete(rast_tif)
        fs::file_move(r_tmp_tif, rast_tif)
        rm(r)
        rm(r_tmp)
    }
    else {
        terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
    }
    r <- terra::rast(rast_tif)
}
debug: if (fs::file_exists(rast_tif)) {
    r_tmp_tif <- tempfile(fileext = ".tif")
    r_tmp <- c(rast(rast_tif), r)
    r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
    terra::writeRaster(r_tmp, r_tmp_tif)
    fs::file_delete(rast_tif)
    fs::file_move(r_tmp_tif, rast_tif)
    rm(r)
    rm(r_tmp)
} else {
    terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
}
debug: terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
debug: r <- terra::rast(rast_tif)
debug: d_r <- mutate(tidyr::pivot_longer(sf::st_drop_geometry(sf::st_as_sf(terra::zonal(x = r, 
    z = terra::vect(dplyr::select(sf_zones, dplyr::all_of(fld_zones))), 
    fun = zonal_fun, exact = T, na.rm = T, as.polygons = T))), 
    cols = -dplyr::any_of(fld_zones), names_to = "lyr", values_to = zonal_fun), 
    time = readr::parse_datetime(str_replace(lyr, glue("{var}\\|(.*)"), 
        "\\1")))
debug: if (!is.null(zonal_csv)) write_csv(d_r, zonal_csv)
debug: write_csv(d_r, zonal_csv)
debug: if (!keep_nc) unlink(dir_nc, recursive = T)
debug: unlink(dir_nc, recursive = T)
debug: return(d_r)
Downloading 1 requests, up to 1785 time slices each
Called from: extractr::ed_extract(ed, var = v, sf_zones = ply, bbox = bb, 
    mask_tif = F, rast_tif = glue("{dir_out}/{nms}/{yr}.tif"), 
    zonal_fun = "mean", zonal_csv = glue("{dir_out}/{nms}/{yr}.csv"), 
    dir_nc = glue("{dir_out}/{nms}/{yr}_nc"), keep_nc = F, n_max_vals_per_req = 1e+05, 
    time_min = time_min, time_max = time_max, verbose = T)
debug: while (i_req <= n_reqs) {
    i_t_beg <- (i_req - 1) * n_t_per_req + 1
    i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
    t_req <- times_todo[c(i_t_beg, i_t_end)]
    t_req_str <- format_ISO8601(t_req, usetz = "Z")
    if (verbose) 
        message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
    ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
        ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
        0), nc)
    unlink(ncs0)
    nc_retry <- T
    nc_n_try <- 1
    n_max_retries
    while (nc_retry) {
        res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
            url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
                bbox[["xmax"]]), latitude = c(bbox[["ymin"]], 
                bbox[["ymax"]]), time = t_req_str, fmt = "nc", 
            store = rerddap::disk(path = dir_nc)))
        if (inherits(res, "try-error")) {
            err <- attr(res, "condition")
            msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
            nc_n_try <- nc_n_try + 1
            if (nc_n_try > n_max_retries) {
                stop(msg)
            }
            else {
                message(msg, "\nRETRYing...")
                Sys.sleep(1)
            }
        }
        else {
            nc_retry <- F
        }
    }
    i_req <- i_req + 1
}
debug: i_t_beg <- (i_req - 1) * n_t_per_req + 1
debug: i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
debug: t_req <- times_todo[c(i_t_beg, i_t_end)]
debug: t_req_str <- format_ISO8601(t_req, usetz = "Z")
debug: if (verbose) message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
debug: message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
Fetching request 1 of 1 (2011-01-01 to 2011-12-01) ~ 19:42:33 UTC
debug: ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
    0), nc)
debug: unlink(ncs0)
debug: nc_retry <- T
debug: nc_n_try <- 1
debug: n_max_retries
debug: while (nc_retry) {
    res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
        url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
            bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
        time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
    if (inherits(res, "try-error")) {
        err <- attr(res, "condition")
        msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
        nc_n_try <- nc_n_try + 1
        if (nc_n_try > n_max_retries) {
            stop(msg)
        }
        else {
            message(msg, "\nRETRYing...")
            Sys.sleep(1)
        }
    }
    else {
        nc_retry <- F
    }
}
debug: res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
    url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
        bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
    time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
debug: if (inherits(res, "try-error")) {
    err <- attr(res, "condition")
    msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
    nc_n_try <- nc_n_try + 1
    if (nc_n_try > n_max_retries) {
        stop(msg)
    }
    else {
        message(msg, "\nRETRYing...")
        Sys.sleep(1)
    }
} else {
    nc_retry <- F
}
debug: nc_retry <- F
debug: (while) nc_retry
debug: i_req <- i_req + 1
debug: (while) i_req <= n_reqs
debug: ncs <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size > 
    0), nc)
debug: r <- terra::rast(ncs)
debug: stopifnot(all(class(terra::time(r)) %in% c("POSIXct", "POSIXt")))
debug: idx <- dplyr::pull(dplyr::filter(dplyr::arrange(dplyr::tibble(idx = 1:terra::nlyr(r), 
    time = terra::time(r)), time), !duplicated(time)), idx)
debug: r <- terra::subset(r, idx)
debug: stopifnot(terra::crs(r, proj = T) == wgs84)
debug: if (mask_tif) r <- terra::mask(r, sf_zones)
debug: lyrs <- glue("{var}|{terra::time(r)}")
debug: if (length(dims_other) > 0 && !all(length(dims[dims_other]) == 
    1)) stop(glue("Other dimensions not yet supported: {paste(dims_other, collapse = ',')}"))
debug: names(r) <- lyrs
debug: if (!is.null(rast_tif)) {
    if (fs::file_exists(rast_tif)) {
        r_tmp_tif <- tempfile(fileext = ".tif")
        r_tmp <- c(rast(rast_tif), r)
        r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
        terra::writeRaster(r_tmp, r_tmp_tif)
        fs::file_delete(rast_tif)
        fs::file_move(r_tmp_tif, rast_tif)
        rm(r)
        rm(r_tmp)
    }
    else {
        terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
    }
    r <- terra::rast(rast_tif)
}
debug: if (fs::file_exists(rast_tif)) {
    r_tmp_tif <- tempfile(fileext = ".tif")
    r_tmp <- c(rast(rast_tif), r)
    r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
    terra::writeRaster(r_tmp, r_tmp_tif)
    fs::file_delete(rast_tif)
    fs::file_move(r_tmp_tif, rast_tif)
    rm(r)
    rm(r_tmp)
} else {
    terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
}
debug: terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
debug: r <- terra::rast(rast_tif)
debug: d_r <- mutate(tidyr::pivot_longer(sf::st_drop_geometry(sf::st_as_sf(terra::zonal(x = r, 
    z = terra::vect(dplyr::select(sf_zones, dplyr::all_of(fld_zones))), 
    fun = zonal_fun, exact = T, na.rm = T, as.polygons = T))), 
    cols = -dplyr::any_of(fld_zones), names_to = "lyr", values_to = zonal_fun), 
    time = readr::parse_datetime(str_replace(lyr, glue("{var}\\|(.*)"), 
        "\\1")))
debug: if (!is.null(zonal_csv)) write_csv(d_r, zonal_csv)
debug: write_csv(d_r, zonal_csv)
debug: if (!keep_nc) unlink(dir_nc, recursive = T)
debug: unlink(dir_nc, recursive = T)
debug: return(d_r)
Downloading 1 requests, up to 1785 time slices each
Called from: extractr::ed_extract(ed, var = v, sf_zones = ply, bbox = bb, 
    mask_tif = F, rast_tif = glue("{dir_out}/{nms}/{yr}.tif"), 
    zonal_fun = "mean", zonal_csv = glue("{dir_out}/{nms}/{yr}.csv"), 
    dir_nc = glue("{dir_out}/{nms}/{yr}_nc"), keep_nc = F, n_max_vals_per_req = 1e+05, 
    time_min = time_min, time_max = time_max, verbose = T)
debug: while (i_req <= n_reqs) {
    i_t_beg <- (i_req - 1) * n_t_per_req + 1
    i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
    t_req <- times_todo[c(i_t_beg, i_t_end)]
    t_req_str <- format_ISO8601(t_req, usetz = "Z")
    if (verbose) 
        message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
    ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
        ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
        0), nc)
    unlink(ncs0)
    nc_retry <- T
    nc_n_try <- 1
    n_max_retries
    while (nc_retry) {
        res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
            url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
                bbox[["xmax"]]), latitude = c(bbox[["ymin"]], 
                bbox[["ymax"]]), time = t_req_str, fmt = "nc", 
            store = rerddap::disk(path = dir_nc)))
        if (inherits(res, "try-error")) {
            err <- attr(res, "condition")
            msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
            nc_n_try <- nc_n_try + 1
            if (nc_n_try > n_max_retries) {
                stop(msg)
            }
            else {
                message(msg, "\nRETRYing...")
                Sys.sleep(1)
            }
        }
        else {
            nc_retry <- F
        }
    }
    i_req <- i_req + 1
}
debug: i_t_beg <- (i_req - 1) * n_t_per_req + 1
debug: i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
debug: t_req <- times_todo[c(i_t_beg, i_t_end)]
debug: t_req_str <- format_ISO8601(t_req, usetz = "Z")
debug: if (verbose) message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
debug: message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
Fetching request 1 of 1 (2012-01-01 to 2012-12-01) ~ 19:42:34 UTC
debug: ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
    0), nc)
debug: unlink(ncs0)
debug: nc_retry <- T
debug: nc_n_try <- 1
debug: n_max_retries
debug: while (nc_retry) {
    res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
        url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
            bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
        time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
    if (inherits(res, "try-error")) {
        err <- attr(res, "condition")
        msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
        nc_n_try <- nc_n_try + 1
        if (nc_n_try > n_max_retries) {
            stop(msg)
        }
        else {
            message(msg, "\nRETRYing...")
            Sys.sleep(1)
        }
    }
    else {
        nc_retry <- F
    }
}
debug: res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
    url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
        bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
    time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
debug: if (inherits(res, "try-error")) {
    err <- attr(res, "condition")
    msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
    nc_n_try <- nc_n_try + 1
    if (nc_n_try > n_max_retries) {
        stop(msg)
    }
    else {
        message(msg, "\nRETRYing...")
        Sys.sleep(1)
    }
} else {
    nc_retry <- F
}
debug: nc_retry <- F
debug: (while) nc_retry
debug: i_req <- i_req + 1
debug: (while) i_req <= n_reqs
debug: ncs <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size > 
    0), nc)
debug: r <- terra::rast(ncs)
debug: stopifnot(all(class(terra::time(r)) %in% c("POSIXct", "POSIXt")))
debug: idx <- dplyr::pull(dplyr::filter(dplyr::arrange(dplyr::tibble(idx = 1:terra::nlyr(r), 
    time = terra::time(r)), time), !duplicated(time)), idx)
debug: r <- terra::subset(r, idx)
debug: stopifnot(terra::crs(r, proj = T) == wgs84)
debug: if (mask_tif) r <- terra::mask(r, sf_zones)
debug: lyrs <- glue("{var}|{terra::time(r)}")
debug: if (length(dims_other) > 0 && !all(length(dims[dims_other]) == 
    1)) stop(glue("Other dimensions not yet supported: {paste(dims_other, collapse = ',')}"))
debug: names(r) <- lyrs
debug: if (!is.null(rast_tif)) {
    if (fs::file_exists(rast_tif)) {
        r_tmp_tif <- tempfile(fileext = ".tif")
        r_tmp <- c(rast(rast_tif), r)
        r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
        terra::writeRaster(r_tmp, r_tmp_tif)
        fs::file_delete(rast_tif)
        fs::file_move(r_tmp_tif, rast_tif)
        rm(r)
        rm(r_tmp)
    }
    else {
        terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
    }
    r <- terra::rast(rast_tif)
}
debug: if (fs::file_exists(rast_tif)) {
    r_tmp_tif <- tempfile(fileext = ".tif")
    r_tmp <- c(rast(rast_tif), r)
    r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
    terra::writeRaster(r_tmp, r_tmp_tif)
    fs::file_delete(rast_tif)
    fs::file_move(r_tmp_tif, rast_tif)
    rm(r)
    rm(r_tmp)
} else {
    terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
}
debug: terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
debug: r <- terra::rast(rast_tif)
debug: d_r <- mutate(tidyr::pivot_longer(sf::st_drop_geometry(sf::st_as_sf(terra::zonal(x = r, 
    z = terra::vect(dplyr::select(sf_zones, dplyr::all_of(fld_zones))), 
    fun = zonal_fun, exact = T, na.rm = T, as.polygons = T))), 
    cols = -dplyr::any_of(fld_zones), names_to = "lyr", values_to = zonal_fun), 
    time = readr::parse_datetime(str_replace(lyr, glue("{var}\\|(.*)"), 
        "\\1")))
debug: if (!is.null(zonal_csv)) write_csv(d_r, zonal_csv)
debug: write_csv(d_r, zonal_csv)
debug: if (!keep_nc) unlink(dir_nc, recursive = T)
debug: unlink(dir_nc, recursive = T)
debug: return(d_r)
Downloading 1 requests, up to 1785 time slices each
Called from: extractr::ed_extract(ed, var = v, sf_zones = ply, bbox = bb, 
    mask_tif = F, rast_tif = glue("{dir_out}/{nms}/{yr}.tif"), 
    zonal_fun = "mean", zonal_csv = glue("{dir_out}/{nms}/{yr}.csv"), 
    dir_nc = glue("{dir_out}/{nms}/{yr}_nc"), keep_nc = F, n_max_vals_per_req = 1e+05, 
    time_min = time_min, time_max = time_max, verbose = T)
debug: while (i_req <= n_reqs) {
    i_t_beg <- (i_req - 1) * n_t_per_req + 1
    i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
    t_req <- times_todo[c(i_t_beg, i_t_end)]
    t_req_str <- format_ISO8601(t_req, usetz = "Z")
    if (verbose) 
        message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
    ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
        ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
        0), nc)
    unlink(ncs0)
    nc_retry <- T
    nc_n_try <- 1
    n_max_retries
    while (nc_retry) {
        res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
            url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
                bbox[["xmax"]]), latitude = c(bbox[["ymin"]], 
                bbox[["ymax"]]), time = t_req_str, fmt = "nc", 
            store = rerddap::disk(path = dir_nc)))
        if (inherits(res, "try-error")) {
            err <- attr(res, "condition")
            msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
            nc_n_try <- nc_n_try + 1
            if (nc_n_try > n_max_retries) {
                stop(msg)
            }
            else {
                message(msg, "\nRETRYing...")
                Sys.sleep(1)
            }
        }
        else {
            nc_retry <- F
        }
    }
    i_req <- i_req + 1
}
debug: i_t_beg <- (i_req - 1) * n_t_per_req + 1
debug: i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
debug: t_req <- times_todo[c(i_t_beg, i_t_end)]
debug: t_req_str <- format_ISO8601(t_req, usetz = "Z")
debug: if (verbose) message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
debug: message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
Fetching request 1 of 1 (2013-01-01 to 2013-12-01) ~ 19:42:36 UTC
debug: ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
    0), nc)
debug: unlink(ncs0)
debug: nc_retry <- T
debug: nc_n_try <- 1
debug: n_max_retries
debug: while (nc_retry) {
    res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
        url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
            bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
        time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
    if (inherits(res, "try-error")) {
        err <- attr(res, "condition")
        msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
        nc_n_try <- nc_n_try + 1
        if (nc_n_try > n_max_retries) {
            stop(msg)
        }
        else {
            message(msg, "\nRETRYing...")
            Sys.sleep(1)
        }
    }
    else {
        nc_retry <- F
    }
}
debug: res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
    url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
        bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
    time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
debug: if (inherits(res, "try-error")) {
    err <- attr(res, "condition")
    msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
    nc_n_try <- nc_n_try + 1
    if (nc_n_try > n_max_retries) {
        stop(msg)
    }
    else {
        message(msg, "\nRETRYing...")
        Sys.sleep(1)
    }
} else {
    nc_retry <- F
}
debug: nc_retry <- F
debug: (while) nc_retry
debug: i_req <- i_req + 1
debug: (while) i_req <= n_reqs
debug: ncs <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size > 
    0), nc)
debug: r <- terra::rast(ncs)
debug: stopifnot(all(class(terra::time(r)) %in% c("POSIXct", "POSIXt")))
debug: idx <- dplyr::pull(dplyr::filter(dplyr::arrange(dplyr::tibble(idx = 1:terra::nlyr(r), 
    time = terra::time(r)), time), !duplicated(time)), idx)
debug: r <- terra::subset(r, idx)
debug: stopifnot(terra::crs(r, proj = T) == wgs84)
debug: if (mask_tif) r <- terra::mask(r, sf_zones)
debug: lyrs <- glue("{var}|{terra::time(r)}")
debug: if (length(dims_other) > 0 && !all(length(dims[dims_other]) == 
    1)) stop(glue("Other dimensions not yet supported: {paste(dims_other, collapse = ',')}"))
debug: names(r) <- lyrs
debug: if (!is.null(rast_tif)) {
    if (fs::file_exists(rast_tif)) {
        r_tmp_tif <- tempfile(fileext = ".tif")
        r_tmp <- c(rast(rast_tif), r)
        r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
        terra::writeRaster(r_tmp, r_tmp_tif)
        fs::file_delete(rast_tif)
        fs::file_move(r_tmp_tif, rast_tif)
        rm(r)
        rm(r_tmp)
    }
    else {
        terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
    }
    r <- terra::rast(rast_tif)
}
debug: if (fs::file_exists(rast_tif)) {
    r_tmp_tif <- tempfile(fileext = ".tif")
    r_tmp <- c(rast(rast_tif), r)
    r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
    terra::writeRaster(r_tmp, r_tmp_tif)
    fs::file_delete(rast_tif)
    fs::file_move(r_tmp_tif, rast_tif)
    rm(r)
    rm(r_tmp)
} else {
    terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
}
debug: terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
debug: r <- terra::rast(rast_tif)
debug: d_r <- mutate(tidyr::pivot_longer(sf::st_drop_geometry(sf::st_as_sf(terra::zonal(x = r, 
    z = terra::vect(dplyr::select(sf_zones, dplyr::all_of(fld_zones))), 
    fun = zonal_fun, exact = T, na.rm = T, as.polygons = T))), 
    cols = -dplyr::any_of(fld_zones), names_to = "lyr", values_to = zonal_fun), 
    time = readr::parse_datetime(str_replace(lyr, glue("{var}\\|(.*)"), 
        "\\1")))
debug: if (!is.null(zonal_csv)) write_csv(d_r, zonal_csv)
debug: write_csv(d_r, zonal_csv)
debug: if (!keep_nc) unlink(dir_nc, recursive = T)
debug: unlink(dir_nc, recursive = T)
debug: return(d_r)
Downloading 1 requests, up to 1785 time slices each
Called from: extractr::ed_extract(ed, var = v, sf_zones = ply, bbox = bb, 
    mask_tif = F, rast_tif = glue("{dir_out}/{nms}/{yr}.tif"), 
    zonal_fun = "mean", zonal_csv = glue("{dir_out}/{nms}/{yr}.csv"), 
    dir_nc = glue("{dir_out}/{nms}/{yr}_nc"), keep_nc = F, n_max_vals_per_req = 1e+05, 
    time_min = time_min, time_max = time_max, verbose = T)
debug: while (i_req <= n_reqs) {
    i_t_beg <- (i_req - 1) * n_t_per_req + 1
    i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
    t_req <- times_todo[c(i_t_beg, i_t_end)]
    t_req_str <- format_ISO8601(t_req, usetz = "Z")
    if (verbose) 
        message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
    ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
        ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
        0), nc)
    unlink(ncs0)
    nc_retry <- T
    nc_n_try <- 1
    n_max_retries
    while (nc_retry) {
        res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
            url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
                bbox[["xmax"]]), latitude = c(bbox[["ymin"]], 
                bbox[["ymax"]]), time = t_req_str, fmt = "nc", 
            store = rerddap::disk(path = dir_nc)))
        if (inherits(res, "try-error")) {
            err <- attr(res, "condition")
            msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
            nc_n_try <- nc_n_try + 1
            if (nc_n_try > n_max_retries) {
                stop(msg)
            }
            else {
                message(msg, "\nRETRYing...")
                Sys.sleep(1)
            }
        }
        else {
            nc_retry <- F
        }
    }
    i_req <- i_req + 1
}
debug: i_t_beg <- (i_req - 1) * n_t_per_req + 1
debug: i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
debug: t_req <- times_todo[c(i_t_beg, i_t_end)]
debug: t_req_str <- format_ISO8601(t_req, usetz = "Z")
debug: if (verbose) message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
debug: message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
Fetching request 1 of 1 (2014-01-01 to 2014-12-01) ~ 19:42:38 UTC
debug: ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
    0), nc)
debug: unlink(ncs0)
debug: nc_retry <- T
debug: nc_n_try <- 1
debug: n_max_retries
debug: while (nc_retry) {
    res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
        url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
            bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
        time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
    if (inherits(res, "try-error")) {
        err <- attr(res, "condition")
        msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
        nc_n_try <- nc_n_try + 1
        if (nc_n_try > n_max_retries) {
            stop(msg)
        }
        else {
            message(msg, "\nRETRYing...")
            Sys.sleep(1)
        }
    }
    else {
        nc_retry <- F
    }
}
debug: res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
    url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
        bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
    time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
debug: if (inherits(res, "try-error")) {
    err <- attr(res, "condition")
    msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
    nc_n_try <- nc_n_try + 1
    if (nc_n_try > n_max_retries) {
        stop(msg)
    }
    else {
        message(msg, "\nRETRYing...")
        Sys.sleep(1)
    }
} else {
    nc_retry <- F
}
debug: nc_retry <- F
debug: (while) nc_retry
debug: i_req <- i_req + 1
debug: (while) i_req <= n_reqs
debug: ncs <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size > 
    0), nc)
debug: r <- terra::rast(ncs)
debug: stopifnot(all(class(terra::time(r)) %in% c("POSIXct", "POSIXt")))
debug: idx <- dplyr::pull(dplyr::filter(dplyr::arrange(dplyr::tibble(idx = 1:terra::nlyr(r), 
    time = terra::time(r)), time), !duplicated(time)), idx)
debug: r <- terra::subset(r, idx)
debug: stopifnot(terra::crs(r, proj = T) == wgs84)
debug: if (mask_tif) r <- terra::mask(r, sf_zones)
debug: lyrs <- glue("{var}|{terra::time(r)}")
debug: if (length(dims_other) > 0 && !all(length(dims[dims_other]) == 
    1)) stop(glue("Other dimensions not yet supported: {paste(dims_other, collapse = ',')}"))
debug: names(r) <- lyrs
debug: if (!is.null(rast_tif)) {
    if (fs::file_exists(rast_tif)) {
        r_tmp_tif <- tempfile(fileext = ".tif")
        r_tmp <- c(rast(rast_tif), r)
        r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
        terra::writeRaster(r_tmp, r_tmp_tif)
        fs::file_delete(rast_tif)
        fs::file_move(r_tmp_tif, rast_tif)
        rm(r)
        rm(r_tmp)
    }
    else {
        terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
    }
    r <- terra::rast(rast_tif)
}
debug: if (fs::file_exists(rast_tif)) {
    r_tmp_tif <- tempfile(fileext = ".tif")
    r_tmp <- c(rast(rast_tif), r)
    r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
    terra::writeRaster(r_tmp, r_tmp_tif)
    fs::file_delete(rast_tif)
    fs::file_move(r_tmp_tif, rast_tif)
    rm(r)
    rm(r_tmp)
} else {
    terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
}
debug: terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
debug: r <- terra::rast(rast_tif)
debug: d_r <- mutate(tidyr::pivot_longer(sf::st_drop_geometry(sf::st_as_sf(terra::zonal(x = r, 
    z = terra::vect(dplyr::select(sf_zones, dplyr::all_of(fld_zones))), 
    fun = zonal_fun, exact = T, na.rm = T, as.polygons = T))), 
    cols = -dplyr::any_of(fld_zones), names_to = "lyr", values_to = zonal_fun), 
    time = readr::parse_datetime(str_replace(lyr, glue("{var}\\|(.*)"), 
        "\\1")))
debug: if (!is.null(zonal_csv)) write_csv(d_r, zonal_csv)
debug: write_csv(d_r, zonal_csv)
debug: if (!keep_nc) unlink(dir_nc, recursive = T)
debug: unlink(dir_nc, recursive = T)
debug: return(d_r)
Downloading 1 requests, up to 1785 time slices each
Called from: extractr::ed_extract(ed, var = v, sf_zones = ply, bbox = bb, 
    mask_tif = F, rast_tif = glue("{dir_out}/{nms}/{yr}.tif"), 
    zonal_fun = "mean", zonal_csv = glue("{dir_out}/{nms}/{yr}.csv"), 
    dir_nc = glue("{dir_out}/{nms}/{yr}_nc"), keep_nc = F, n_max_vals_per_req = 1e+05, 
    time_min = time_min, time_max = time_max, verbose = T)
debug: while (i_req <= n_reqs) {
    i_t_beg <- (i_req - 1) * n_t_per_req + 1
    i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
    t_req <- times_todo[c(i_t_beg, i_t_end)]
    t_req_str <- format_ISO8601(t_req, usetz = "Z")
    if (verbose) 
        message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
    ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
        ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
        0), nc)
    unlink(ncs0)
    nc_retry <- T
    nc_n_try <- 1
    n_max_retries
    while (nc_retry) {
        res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
            url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
                bbox[["xmax"]]), latitude = c(bbox[["ymin"]], 
                bbox[["ymax"]]), time = t_req_str, fmt = "nc", 
            store = rerddap::disk(path = dir_nc)))
        if (inherits(res, "try-error")) {
            err <- attr(res, "condition")
            msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
            nc_n_try <- nc_n_try + 1
            if (nc_n_try > n_max_retries) {
                stop(msg)
            }
            else {
                message(msg, "\nRETRYing...")
                Sys.sleep(1)
            }
        }
        else {
            nc_retry <- F
        }
    }
    i_req <- i_req + 1
}
debug: i_t_beg <- (i_req - 1) * n_t_per_req + 1
debug: i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
debug: t_req <- times_todo[c(i_t_beg, i_t_end)]
debug: t_req_str <- format_ISO8601(t_req, usetz = "Z")
debug: if (verbose) message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
debug: message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
Fetching request 1 of 1 (2015-01-01 to 2015-12-01) ~ 19:42:39 UTC
debug: ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
    0), nc)
debug: unlink(ncs0)
debug: nc_retry <- T
debug: nc_n_try <- 1
debug: n_max_retries
debug: while (nc_retry) {
    res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
        url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
            bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
        time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
    if (inherits(res, "try-error")) {
        err <- attr(res, "condition")
        msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
        nc_n_try <- nc_n_try + 1
        if (nc_n_try > n_max_retries) {
            stop(msg)
        }
        else {
            message(msg, "\nRETRYing...")
            Sys.sleep(1)
        }
    }
    else {
        nc_retry <- F
    }
}
debug: res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
    url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
        bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
    time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
debug: if (inherits(res, "try-error")) {
    err <- attr(res, "condition")
    msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
    nc_n_try <- nc_n_try + 1
    if (nc_n_try > n_max_retries) {
        stop(msg)
    }
    else {
        message(msg, "\nRETRYing...")
        Sys.sleep(1)
    }
} else {
    nc_retry <- F
}
debug: nc_retry <- F
debug: (while) nc_retry
debug: i_req <- i_req + 1
debug: (while) i_req <= n_reqs
debug: ncs <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size > 
    0), nc)
debug: r <- terra::rast(ncs)
debug: stopifnot(all(class(terra::time(r)) %in% c("POSIXct", "POSIXt")))
debug: idx <- dplyr::pull(dplyr::filter(dplyr::arrange(dplyr::tibble(idx = 1:terra::nlyr(r), 
    time = terra::time(r)), time), !duplicated(time)), idx)
debug: r <- terra::subset(r, idx)
debug: stopifnot(terra::crs(r, proj = T) == wgs84)
debug: if (mask_tif) r <- terra::mask(r, sf_zones)
debug: lyrs <- glue("{var}|{terra::time(r)}")
debug: if (length(dims_other) > 0 && !all(length(dims[dims_other]) == 
    1)) stop(glue("Other dimensions not yet supported: {paste(dims_other, collapse = ',')}"))
debug: names(r) <- lyrs
debug: if (!is.null(rast_tif)) {
    if (fs::file_exists(rast_tif)) {
        r_tmp_tif <- tempfile(fileext = ".tif")
        r_tmp <- c(rast(rast_tif), r)
        r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
        terra::writeRaster(r_tmp, r_tmp_tif)
        fs::file_delete(rast_tif)
        fs::file_move(r_tmp_tif, rast_tif)
        rm(r)
        rm(r_tmp)
    }
    else {
        terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
    }
    r <- terra::rast(rast_tif)
}
debug: if (fs::file_exists(rast_tif)) {
    r_tmp_tif <- tempfile(fileext = ".tif")
    r_tmp <- c(rast(rast_tif), r)
    r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
    terra::writeRaster(r_tmp, r_tmp_tif)
    fs::file_delete(rast_tif)
    fs::file_move(r_tmp_tif, rast_tif)
    rm(r)
    rm(r_tmp)
} else {
    terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
}
debug: terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
debug: r <- terra::rast(rast_tif)
debug: d_r <- mutate(tidyr::pivot_longer(sf::st_drop_geometry(sf::st_as_sf(terra::zonal(x = r, 
    z = terra::vect(dplyr::select(sf_zones, dplyr::all_of(fld_zones))), 
    fun = zonal_fun, exact = T, na.rm = T, as.polygons = T))), 
    cols = -dplyr::any_of(fld_zones), names_to = "lyr", values_to = zonal_fun), 
    time = readr::parse_datetime(str_replace(lyr, glue("{var}\\|(.*)"), 
        "\\1")))
debug: if (!is.null(zonal_csv)) write_csv(d_r, zonal_csv)
debug: write_csv(d_r, zonal_csv)
debug: if (!keep_nc) unlink(dir_nc, recursive = T)
debug: unlink(dir_nc, recursive = T)
debug: return(d_r)
Downloading 1 requests, up to 1785 time slices each
Called from: extractr::ed_extract(ed, var = v, sf_zones = ply, bbox = bb, 
    mask_tif = F, rast_tif = glue("{dir_out}/{nms}/{yr}.tif"), 
    zonal_fun = "mean", zonal_csv = glue("{dir_out}/{nms}/{yr}.csv"), 
    dir_nc = glue("{dir_out}/{nms}/{yr}_nc"), keep_nc = F, n_max_vals_per_req = 1e+05, 
    time_min = time_min, time_max = time_max, verbose = T)
debug: while (i_req <= n_reqs) {
    i_t_beg <- (i_req - 1) * n_t_per_req + 1
    i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
    t_req <- times_todo[c(i_t_beg, i_t_end)]
    t_req_str <- format_ISO8601(t_req, usetz = "Z")
    if (verbose) 
        message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
    ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
        ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
        0), nc)
    unlink(ncs0)
    nc_retry <- T
    nc_n_try <- 1
    n_max_retries
    while (nc_retry) {
        res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
            url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
                bbox[["xmax"]]), latitude = c(bbox[["ymin"]], 
                bbox[["ymax"]]), time = t_req_str, fmt = "nc", 
            store = rerddap::disk(path = dir_nc)))
        if (inherits(res, "try-error")) {
            err <- attr(res, "condition")
            msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
            nc_n_try <- nc_n_try + 1
            if (nc_n_try > n_max_retries) {
                stop(msg)
            }
            else {
                message(msg, "\nRETRYing...")
                Sys.sleep(1)
            }
        }
        else {
            nc_retry <- F
        }
    }
    i_req <- i_req + 1
}
debug: i_t_beg <- (i_req - 1) * n_t_per_req + 1
debug: i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
debug: t_req <- times_todo[c(i_t_beg, i_t_end)]
debug: t_req_str <- format_ISO8601(t_req, usetz = "Z")
debug: if (verbose) message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
debug: message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
Fetching request 1 of 1 (2016-01-01 to 2016-12-01) ~ 19:42:41 UTC
debug: ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
    0), nc)
debug: unlink(ncs0)
debug: nc_retry <- T
debug: nc_n_try <- 1
debug: n_max_retries
debug: while (nc_retry) {
    res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
        url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
            bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
        time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
    if (inherits(res, "try-error")) {
        err <- attr(res, "condition")
        msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
        nc_n_try <- nc_n_try + 1
        if (nc_n_try > n_max_retries) {
            stop(msg)
        }
        else {
            message(msg, "\nRETRYing...")
            Sys.sleep(1)
        }
    }
    else {
        nc_retry <- F
    }
}
debug: res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
    url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
        bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
    time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
debug: if (inherits(res, "try-error")) {
    err <- attr(res, "condition")
    msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
    nc_n_try <- nc_n_try + 1
    if (nc_n_try > n_max_retries) {
        stop(msg)
    }
    else {
        message(msg, "\nRETRYing...")
        Sys.sleep(1)
    }
} else {
    nc_retry <- F
}
debug: nc_retry <- F
debug: (while) nc_retry
debug: i_req <- i_req + 1
debug: (while) i_req <= n_reqs
debug: ncs <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size > 
    0), nc)
debug: r <- terra::rast(ncs)
debug: stopifnot(all(class(terra::time(r)) %in% c("POSIXct", "POSIXt")))
debug: idx <- dplyr::pull(dplyr::filter(dplyr::arrange(dplyr::tibble(idx = 1:terra::nlyr(r), 
    time = terra::time(r)), time), !duplicated(time)), idx)
debug: r <- terra::subset(r, idx)
debug: stopifnot(terra::crs(r, proj = T) == wgs84)
debug: if (mask_tif) r <- terra::mask(r, sf_zones)
debug: lyrs <- glue("{var}|{terra::time(r)}")
debug: if (length(dims_other) > 0 && !all(length(dims[dims_other]) == 
    1)) stop(glue("Other dimensions not yet supported: {paste(dims_other, collapse = ',')}"))
debug: names(r) <- lyrs
debug: if (!is.null(rast_tif)) {
    if (fs::file_exists(rast_tif)) {
        r_tmp_tif <- tempfile(fileext = ".tif")
        r_tmp <- c(rast(rast_tif), r)
        r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
        terra::writeRaster(r_tmp, r_tmp_tif)
        fs::file_delete(rast_tif)
        fs::file_move(r_tmp_tif, rast_tif)
        rm(r)
        rm(r_tmp)
    }
    else {
        terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
    }
    r <- terra::rast(rast_tif)
}
debug: if (fs::file_exists(rast_tif)) {
    r_tmp_tif <- tempfile(fileext = ".tif")
    r_tmp <- c(rast(rast_tif), r)
    r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
    terra::writeRaster(r_tmp, r_tmp_tif)
    fs::file_delete(rast_tif)
    fs::file_move(r_tmp_tif, rast_tif)
    rm(r)
    rm(r_tmp)
} else {
    terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
}
debug: terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
debug: r <- terra::rast(rast_tif)
debug: d_r <- mutate(tidyr::pivot_longer(sf::st_drop_geometry(sf::st_as_sf(terra::zonal(x = r, 
    z = terra::vect(dplyr::select(sf_zones, dplyr::all_of(fld_zones))), 
    fun = zonal_fun, exact = T, na.rm = T, as.polygons = T))), 
    cols = -dplyr::any_of(fld_zones), names_to = "lyr", values_to = zonal_fun), 
    time = readr::parse_datetime(str_replace(lyr, glue("{var}\\|(.*)"), 
        "\\1")))
debug: if (!is.null(zonal_csv)) write_csv(d_r, zonal_csv)
debug: write_csv(d_r, zonal_csv)
debug: if (!keep_nc) unlink(dir_nc, recursive = T)
debug: unlink(dir_nc, recursive = T)
debug: return(d_r)
Downloading 1 requests, up to 1785 time slices each
Called from: extractr::ed_extract(ed, var = v, sf_zones = ply, bbox = bb, 
    mask_tif = F, rast_tif = glue("{dir_out}/{nms}/{yr}.tif"), 
    zonal_fun = "mean", zonal_csv = glue("{dir_out}/{nms}/{yr}.csv"), 
    dir_nc = glue("{dir_out}/{nms}/{yr}_nc"), keep_nc = F, n_max_vals_per_req = 1e+05, 
    time_min = time_min, time_max = time_max, verbose = T)
debug: while (i_req <= n_reqs) {
    i_t_beg <- (i_req - 1) * n_t_per_req + 1
    i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
    t_req <- times_todo[c(i_t_beg, i_t_end)]
    t_req_str <- format_ISO8601(t_req, usetz = "Z")
    if (verbose) 
        message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
    ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
        ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
        0), nc)
    unlink(ncs0)
    nc_retry <- T
    nc_n_try <- 1
    n_max_retries
    while (nc_retry) {
        res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
            url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
                bbox[["xmax"]]), latitude = c(bbox[["ymin"]], 
                bbox[["ymax"]]), time = t_req_str, fmt = "nc", 
            store = rerddap::disk(path = dir_nc)))
        if (inherits(res, "try-error")) {
            err <- attr(res, "condition")
            msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
            nc_n_try <- nc_n_try + 1
            if (nc_n_try > n_max_retries) {
                stop(msg)
            }
            else {
                message(msg, "\nRETRYing...")
                Sys.sleep(1)
            }
        }
        else {
            nc_retry <- F
        }
    }
    i_req <- i_req + 1
}
debug: i_t_beg <- (i_req - 1) * n_t_per_req + 1
debug: i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
debug: t_req <- times_todo[c(i_t_beg, i_t_end)]
debug: t_req_str <- format_ISO8601(t_req, usetz = "Z")
debug: if (verbose) message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
debug: message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
Fetching request 1 of 1 (2017-01-01 to 2017-12-01) ~ 19:42:42 UTC
debug: ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
    0), nc)
debug: unlink(ncs0)
debug: nc_retry <- T
debug: nc_n_try <- 1
debug: n_max_retries
debug: while (nc_retry) {
    res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
        url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
            bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
        time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
    if (inherits(res, "try-error")) {
        err <- attr(res, "condition")
        msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
        nc_n_try <- nc_n_try + 1
        if (nc_n_try > n_max_retries) {
            stop(msg)
        }
        else {
            message(msg, "\nRETRYing...")
            Sys.sleep(1)
        }
    }
    else {
        nc_retry <- F
    }
}
debug: res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
    url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
        bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
    time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
debug: if (inherits(res, "try-error")) {
    err <- attr(res, "condition")
    msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
    nc_n_try <- nc_n_try + 1
    if (nc_n_try > n_max_retries) {
        stop(msg)
    }
    else {
        message(msg, "\nRETRYing...")
        Sys.sleep(1)
    }
} else {
    nc_retry <- F
}
debug: nc_retry <- F
debug: (while) nc_retry
debug: i_req <- i_req + 1
debug: (while) i_req <= n_reqs
debug: ncs <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size > 
    0), nc)
debug: r <- terra::rast(ncs)
debug: stopifnot(all(class(terra::time(r)) %in% c("POSIXct", "POSIXt")))
debug: idx <- dplyr::pull(dplyr::filter(dplyr::arrange(dplyr::tibble(idx = 1:terra::nlyr(r), 
    time = terra::time(r)), time), !duplicated(time)), idx)
debug: r <- terra::subset(r, idx)
debug: stopifnot(terra::crs(r, proj = T) == wgs84)
debug: if (mask_tif) r <- terra::mask(r, sf_zones)
debug: lyrs <- glue("{var}|{terra::time(r)}")
debug: if (length(dims_other) > 0 && !all(length(dims[dims_other]) == 
    1)) stop(glue("Other dimensions not yet supported: {paste(dims_other, collapse = ',')}"))
debug: names(r) <- lyrs
debug: if (!is.null(rast_tif)) {
    if (fs::file_exists(rast_tif)) {
        r_tmp_tif <- tempfile(fileext = ".tif")
        r_tmp <- c(rast(rast_tif), r)
        r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
        terra::writeRaster(r_tmp, r_tmp_tif)
        fs::file_delete(rast_tif)
        fs::file_move(r_tmp_tif, rast_tif)
        rm(r)
        rm(r_tmp)
    }
    else {
        terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
    }
    r <- terra::rast(rast_tif)
}
debug: if (fs::file_exists(rast_tif)) {
    r_tmp_tif <- tempfile(fileext = ".tif")
    r_tmp <- c(rast(rast_tif), r)
    r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
    terra::writeRaster(r_tmp, r_tmp_tif)
    fs::file_delete(rast_tif)
    fs::file_move(r_tmp_tif, rast_tif)
    rm(r)
    rm(r_tmp)
} else {
    terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
}
debug: terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
debug: r <- terra::rast(rast_tif)
debug: d_r <- mutate(tidyr::pivot_longer(sf::st_drop_geometry(sf::st_as_sf(terra::zonal(x = r, 
    z = terra::vect(dplyr::select(sf_zones, dplyr::all_of(fld_zones))), 
    fun = zonal_fun, exact = T, na.rm = T, as.polygons = T))), 
    cols = -dplyr::any_of(fld_zones), names_to = "lyr", values_to = zonal_fun), 
    time = readr::parse_datetime(str_replace(lyr, glue("{var}\\|(.*)"), 
        "\\1")))
debug: if (!is.null(zonal_csv)) write_csv(d_r, zonal_csv)
debug: write_csv(d_r, zonal_csv)
debug: if (!keep_nc) unlink(dir_nc, recursive = T)
debug: unlink(dir_nc, recursive = T)
debug: return(d_r)
Downloading 1 requests, up to 1785 time slices each
Called from: extractr::ed_extract(ed, var = v, sf_zones = ply, bbox = bb, 
    mask_tif = F, rast_tif = glue("{dir_out}/{nms}/{yr}.tif"), 
    zonal_fun = "mean", zonal_csv = glue("{dir_out}/{nms}/{yr}.csv"), 
    dir_nc = glue("{dir_out}/{nms}/{yr}_nc"), keep_nc = F, n_max_vals_per_req = 1e+05, 
    time_min = time_min, time_max = time_max, verbose = T)
debug: while (i_req <= n_reqs) {
    i_t_beg <- (i_req - 1) * n_t_per_req + 1
    i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
    t_req <- times_todo[c(i_t_beg, i_t_end)]
    t_req_str <- format_ISO8601(t_req, usetz = "Z")
    if (verbose) 
        message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
    ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
        ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
        0), nc)
    unlink(ncs0)
    nc_retry <- T
    nc_n_try <- 1
    n_max_retries
    while (nc_retry) {
        res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
            url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
                bbox[["xmax"]]), latitude = c(bbox[["ymin"]], 
                bbox[["ymax"]]), time = t_req_str, fmt = "nc", 
            store = rerddap::disk(path = dir_nc)))
        if (inherits(res, "try-error")) {
            err <- attr(res, "condition")
            msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
            nc_n_try <- nc_n_try + 1
            if (nc_n_try > n_max_retries) {
                stop(msg)
            }
            else {
                message(msg, "\nRETRYing...")
                Sys.sleep(1)
            }
        }
        else {
            nc_retry <- F
        }
    }
    i_req <- i_req + 1
}
debug: i_t_beg <- (i_req - 1) * n_t_per_req + 1
debug: i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
debug: t_req <- times_todo[c(i_t_beg, i_t_end)]
debug: t_req_str <- format_ISO8601(t_req, usetz = "Z")
debug: if (verbose) message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
debug: message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
Fetching request 1 of 1 (2018-01-01 to 2018-12-01) ~ 19:42:44 UTC
debug: ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
    0), nc)
debug: unlink(ncs0)
debug: nc_retry <- T
debug: nc_n_try <- 1
debug: n_max_retries
debug: while (nc_retry) {
    res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
        url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
            bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
        time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
    if (inherits(res, "try-error")) {
        err <- attr(res, "condition")
        msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
        nc_n_try <- nc_n_try + 1
        if (nc_n_try > n_max_retries) {
            stop(msg)
        }
        else {
            message(msg, "\nRETRYing...")
            Sys.sleep(1)
        }
    }
    else {
        nc_retry <- F
    }
}
debug: res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
    url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
        bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
    time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
debug: if (inherits(res, "try-error")) {
    err <- attr(res, "condition")
    msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
    nc_n_try <- nc_n_try + 1
    if (nc_n_try > n_max_retries) {
        stop(msg)
    }
    else {
        message(msg, "\nRETRYing...")
        Sys.sleep(1)
    }
} else {
    nc_retry <- F
}
debug: nc_retry <- F
debug: (while) nc_retry
debug: i_req <- i_req + 1
debug: (while) i_req <= n_reqs
debug: ncs <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size > 
    0), nc)
debug: r <- terra::rast(ncs)
debug: stopifnot(all(class(terra::time(r)) %in% c("POSIXct", "POSIXt")))
debug: idx <- dplyr::pull(dplyr::filter(dplyr::arrange(dplyr::tibble(idx = 1:terra::nlyr(r), 
    time = terra::time(r)), time), !duplicated(time)), idx)
debug: r <- terra::subset(r, idx)
debug: stopifnot(terra::crs(r, proj = T) == wgs84)
debug: if (mask_tif) r <- terra::mask(r, sf_zones)
debug: lyrs <- glue("{var}|{terra::time(r)}")
debug: if (length(dims_other) > 0 && !all(length(dims[dims_other]) == 
    1)) stop(glue("Other dimensions not yet supported: {paste(dims_other, collapse = ',')}"))
debug: names(r) <- lyrs
debug: if (!is.null(rast_tif)) {
    if (fs::file_exists(rast_tif)) {
        r_tmp_tif <- tempfile(fileext = ".tif")
        r_tmp <- c(rast(rast_tif), r)
        r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
        terra::writeRaster(r_tmp, r_tmp_tif)
        fs::file_delete(rast_tif)
        fs::file_move(r_tmp_tif, rast_tif)
        rm(r)
        rm(r_tmp)
    }
    else {
        terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
    }
    r <- terra::rast(rast_tif)
}
debug: if (fs::file_exists(rast_tif)) {
    r_tmp_tif <- tempfile(fileext = ".tif")
    r_tmp <- c(rast(rast_tif), r)
    r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
    terra::writeRaster(r_tmp, r_tmp_tif)
    fs::file_delete(rast_tif)
    fs::file_move(r_tmp_tif, rast_tif)
    rm(r)
    rm(r_tmp)
} else {
    terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
}
debug: terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
debug: r <- terra::rast(rast_tif)
debug: d_r <- mutate(tidyr::pivot_longer(sf::st_drop_geometry(sf::st_as_sf(terra::zonal(x = r, 
    z = terra::vect(dplyr::select(sf_zones, dplyr::all_of(fld_zones))), 
    fun = zonal_fun, exact = T, na.rm = T, as.polygons = T))), 
    cols = -dplyr::any_of(fld_zones), names_to = "lyr", values_to = zonal_fun), 
    time = readr::parse_datetime(str_replace(lyr, glue("{var}\\|(.*)"), 
        "\\1")))
debug: if (!is.null(zonal_csv)) write_csv(d_r, zonal_csv)
debug: write_csv(d_r, zonal_csv)
debug: if (!keep_nc) unlink(dir_nc, recursive = T)
debug: unlink(dir_nc, recursive = T)
debug: return(d_r)
Downloading 1 requests, up to 1785 time slices each
Called from: extractr::ed_extract(ed, var = v, sf_zones = ply, bbox = bb, 
    mask_tif = F, rast_tif = glue("{dir_out}/{nms}/{yr}.tif"), 
    zonal_fun = "mean", zonal_csv = glue("{dir_out}/{nms}/{yr}.csv"), 
    dir_nc = glue("{dir_out}/{nms}/{yr}_nc"), keep_nc = F, n_max_vals_per_req = 1e+05, 
    time_min = time_min, time_max = time_max, verbose = T)
debug: while (i_req <= n_reqs) {
    i_t_beg <- (i_req - 1) * n_t_per_req + 1
    i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
    t_req <- times_todo[c(i_t_beg, i_t_end)]
    t_req_str <- format_ISO8601(t_req, usetz = "Z")
    if (verbose) 
        message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
    ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
        ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
        0), nc)
    unlink(ncs0)
    nc_retry <- T
    nc_n_try <- 1
    n_max_retries
    while (nc_retry) {
        res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
            url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
                bbox[["xmax"]]), latitude = c(bbox[["ymin"]], 
                bbox[["ymax"]]), time = t_req_str, fmt = "nc", 
            store = rerddap::disk(path = dir_nc)))
        if (inherits(res, "try-error")) {
            err <- attr(res, "condition")
            msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
            nc_n_try <- nc_n_try + 1
            if (nc_n_try > n_max_retries) {
                stop(msg)
            }
            else {
                message(msg, "\nRETRYing...")
                Sys.sleep(1)
            }
        }
        else {
            nc_retry <- F
        }
    }
    i_req <- i_req + 1
}
debug: i_t_beg <- (i_req - 1) * n_t_per_req + 1
debug: i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
debug: t_req <- times_todo[c(i_t_beg, i_t_end)]
debug: t_req_str <- format_ISO8601(t_req, usetz = "Z")
debug: if (verbose) message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
debug: message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
Fetching request 1 of 1 (2019-01-01 to 2019-12-01) ~ 19:42:46 UTC
debug: ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
    0), nc)
debug: unlink(ncs0)
debug: nc_retry <- T
debug: nc_n_try <- 1
debug: n_max_retries
debug: while (nc_retry) {
    res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
        url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
            bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
        time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
    if (inherits(res, "try-error")) {
        err <- attr(res, "condition")
        msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
        nc_n_try <- nc_n_try + 1
        if (nc_n_try > n_max_retries) {
            stop(msg)
        }
        else {
            message(msg, "\nRETRYing...")
            Sys.sleep(1)
        }
    }
    else {
        nc_retry <- F
    }
}
debug: res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
    url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
        bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
    time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
debug: if (inherits(res, "try-error")) {
    err <- attr(res, "condition")
    msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
    nc_n_try <- nc_n_try + 1
    if (nc_n_try > n_max_retries) {
        stop(msg)
    }
    else {
        message(msg, "\nRETRYing...")
        Sys.sleep(1)
    }
} else {
    nc_retry <- F
}
debug: nc_retry <- F
debug: (while) nc_retry
debug: i_req <- i_req + 1
debug: (while) i_req <= n_reqs
debug: ncs <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size > 
    0), nc)
debug: r <- terra::rast(ncs)
debug: stopifnot(all(class(terra::time(r)) %in% c("POSIXct", "POSIXt")))
debug: idx <- dplyr::pull(dplyr::filter(dplyr::arrange(dplyr::tibble(idx = 1:terra::nlyr(r), 
    time = terra::time(r)), time), !duplicated(time)), idx)
debug: r <- terra::subset(r, idx)
debug: stopifnot(terra::crs(r, proj = T) == wgs84)
debug: if (mask_tif) r <- terra::mask(r, sf_zones)
debug: lyrs <- glue("{var}|{terra::time(r)}")
debug: if (length(dims_other) > 0 && !all(length(dims[dims_other]) == 
    1)) stop(glue("Other dimensions not yet supported: {paste(dims_other, collapse = ',')}"))
debug: names(r) <- lyrs
debug: if (!is.null(rast_tif)) {
    if (fs::file_exists(rast_tif)) {
        r_tmp_tif <- tempfile(fileext = ".tif")
        r_tmp <- c(rast(rast_tif), r)
        r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
        terra::writeRaster(r_tmp, r_tmp_tif)
        fs::file_delete(rast_tif)
        fs::file_move(r_tmp_tif, rast_tif)
        rm(r)
        rm(r_tmp)
    }
    else {
        terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
    }
    r <- terra::rast(rast_tif)
}
debug: if (fs::file_exists(rast_tif)) {
    r_tmp_tif <- tempfile(fileext = ".tif")
    r_tmp <- c(rast(rast_tif), r)
    r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
    terra::writeRaster(r_tmp, r_tmp_tif)
    fs::file_delete(rast_tif)
    fs::file_move(r_tmp_tif, rast_tif)
    rm(r)
    rm(r_tmp)
} else {
    terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
}
debug: terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
debug: r <- terra::rast(rast_tif)
debug: d_r <- mutate(tidyr::pivot_longer(sf::st_drop_geometry(sf::st_as_sf(terra::zonal(x = r, 
    z = terra::vect(dplyr::select(sf_zones, dplyr::all_of(fld_zones))), 
    fun = zonal_fun, exact = T, na.rm = T, as.polygons = T))), 
    cols = -dplyr::any_of(fld_zones), names_to = "lyr", values_to = zonal_fun), 
    time = readr::parse_datetime(str_replace(lyr, glue("{var}\\|(.*)"), 
        "\\1")))
debug: if (!is.null(zonal_csv)) write_csv(d_r, zonal_csv)
debug: write_csv(d_r, zonal_csv)
debug: if (!keep_nc) unlink(dir_nc, recursive = T)
debug: unlink(dir_nc, recursive = T)
debug: return(d_r)
Downloading 1 requests, up to 1785 time slices each
Called from: extractr::ed_extract(ed, var = v, sf_zones = ply, bbox = bb, 
    mask_tif = F, rast_tif = glue("{dir_out}/{nms}/{yr}.tif"), 
    zonal_fun = "mean", zonal_csv = glue("{dir_out}/{nms}/{yr}.csv"), 
    dir_nc = glue("{dir_out}/{nms}/{yr}_nc"), keep_nc = F, n_max_vals_per_req = 1e+05, 
    time_min = time_min, time_max = time_max, verbose = T)
debug: while (i_req <= n_reqs) {
    i_t_beg <- (i_req - 1) * n_t_per_req + 1
    i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
    t_req <- times_todo[c(i_t_beg, i_t_end)]
    t_req_str <- format_ISO8601(t_req, usetz = "Z")
    if (verbose) 
        message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
    ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
        ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
        0), nc)
    unlink(ncs0)
    nc_retry <- T
    nc_n_try <- 1
    n_max_retries
    while (nc_retry) {
        res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
            url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
                bbox[["xmax"]]), latitude = c(bbox[["ymin"]], 
                bbox[["ymax"]]), time = t_req_str, fmt = "nc", 
            store = rerddap::disk(path = dir_nc)))
        if (inherits(res, "try-error")) {
            err <- attr(res, "condition")
            msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
            nc_n_try <- nc_n_try + 1
            if (nc_n_try > n_max_retries) {
                stop(msg)
            }
            else {
                message(msg, "\nRETRYing...")
                Sys.sleep(1)
            }
        }
        else {
            nc_retry <- F
        }
    }
    i_req <- i_req + 1
}
debug: i_t_beg <- (i_req - 1) * n_t_per_req + 1
debug: i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
debug: t_req <- times_todo[c(i_t_beg, i_t_end)]
debug: t_req_str <- format_ISO8601(t_req, usetz = "Z")
debug: if (verbose) message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
debug: message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
Fetching request 1 of 1 (2020-01-01 to 2020-12-01) ~ 19:42:47 UTC
debug: ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
    0), nc)
debug: unlink(ncs0)
debug: nc_retry <- T
debug: nc_n_try <- 1
debug: n_max_retries
debug: while (nc_retry) {
    res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
        url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
            bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
        time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
    if (inherits(res, "try-error")) {
        err <- attr(res, "condition")
        msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
        nc_n_try <- nc_n_try + 1
        if (nc_n_try > n_max_retries) {
            stop(msg)
        }
        else {
            message(msg, "\nRETRYing...")
            Sys.sleep(1)
        }
    }
    else {
        nc_retry <- F
    }
}
debug: res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
    url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
        bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
    time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
debug: if (inherits(res, "try-error")) {
    err <- attr(res, "condition")
    msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
    nc_n_try <- nc_n_try + 1
    if (nc_n_try > n_max_retries) {
        stop(msg)
    }
    else {
        message(msg, "\nRETRYing...")
        Sys.sleep(1)
    }
} else {
    nc_retry <- F
}
debug: nc_retry <- F
debug: (while) nc_retry
debug: i_req <- i_req + 1
debug: (while) i_req <= n_reqs
debug: ncs <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size > 
    0), nc)
debug: r <- terra::rast(ncs)
debug: stopifnot(all(class(terra::time(r)) %in% c("POSIXct", "POSIXt")))
debug: idx <- dplyr::pull(dplyr::filter(dplyr::arrange(dplyr::tibble(idx = 1:terra::nlyr(r), 
    time = terra::time(r)), time), !duplicated(time)), idx)
debug: r <- terra::subset(r, idx)
debug: stopifnot(terra::crs(r, proj = T) == wgs84)
debug: if (mask_tif) r <- terra::mask(r, sf_zones)
debug: lyrs <- glue("{var}|{terra::time(r)}")
debug: if (length(dims_other) > 0 && !all(length(dims[dims_other]) == 
    1)) stop(glue("Other dimensions not yet supported: {paste(dims_other, collapse = ',')}"))
debug: names(r) <- lyrs
debug: if (!is.null(rast_tif)) {
    if (fs::file_exists(rast_tif)) {
        r_tmp_tif <- tempfile(fileext = ".tif")
        r_tmp <- c(rast(rast_tif), r)
        r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
        terra::writeRaster(r_tmp, r_tmp_tif)
        fs::file_delete(rast_tif)
        fs::file_move(r_tmp_tif, rast_tif)
        rm(r)
        rm(r_tmp)
    }
    else {
        terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
    }
    r <- terra::rast(rast_tif)
}
debug: if (fs::file_exists(rast_tif)) {
    r_tmp_tif <- tempfile(fileext = ".tif")
    r_tmp <- c(rast(rast_tif), r)
    r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
    terra::writeRaster(r_tmp, r_tmp_tif)
    fs::file_delete(rast_tif)
    fs::file_move(r_tmp_tif, rast_tif)
    rm(r)
    rm(r_tmp)
} else {
    terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
}
debug: terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
debug: r <- terra::rast(rast_tif)
debug: d_r <- mutate(tidyr::pivot_longer(sf::st_drop_geometry(sf::st_as_sf(terra::zonal(x = r, 
    z = terra::vect(dplyr::select(sf_zones, dplyr::all_of(fld_zones))), 
    fun = zonal_fun, exact = T, na.rm = T, as.polygons = T))), 
    cols = -dplyr::any_of(fld_zones), names_to = "lyr", values_to = zonal_fun), 
    time = readr::parse_datetime(str_replace(lyr, glue("{var}\\|(.*)"), 
        "\\1")))
debug: if (!is.null(zonal_csv)) write_csv(d_r, zonal_csv)
debug: write_csv(d_r, zonal_csv)
debug: if (!keep_nc) unlink(dir_nc, recursive = T)
debug: unlink(dir_nc, recursive = T)
debug: return(d_r)
Downloading 1 requests, up to 1785 time slices each
Called from: extractr::ed_extract(ed, var = v, sf_zones = ply, bbox = bb, 
    mask_tif = F, rast_tif = glue("{dir_out}/{nms}/{yr}.tif"), 
    zonal_fun = "mean", zonal_csv = glue("{dir_out}/{nms}/{yr}.csv"), 
    dir_nc = glue("{dir_out}/{nms}/{yr}_nc"), keep_nc = F, n_max_vals_per_req = 1e+05, 
    time_min = time_min, time_max = time_max, verbose = T)
debug: while (i_req <= n_reqs) {
    i_t_beg <- (i_req - 1) * n_t_per_req + 1
    i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
    t_req <- times_todo[c(i_t_beg, i_t_end)]
    t_req_str <- format_ISO8601(t_req, usetz = "Z")
    if (verbose) 
        message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
    ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
        ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
        0), nc)
    unlink(ncs0)
    nc_retry <- T
    nc_n_try <- 1
    n_max_retries
    while (nc_retry) {
        res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
            url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
                bbox[["xmax"]]), latitude = c(bbox[["ymin"]], 
                bbox[["ymax"]]), time = t_req_str, fmt = "nc", 
            store = rerddap::disk(path = dir_nc)))
        if (inherits(res, "try-error")) {
            err <- attr(res, "condition")
            msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
            nc_n_try <- nc_n_try + 1
            if (nc_n_try > n_max_retries) {
                stop(msg)
            }
            else {
                message(msg, "\nRETRYing...")
                Sys.sleep(1)
            }
        }
        else {
            nc_retry <- F
        }
    }
    i_req <- i_req + 1
}
debug: i_t_beg <- (i_req - 1) * n_t_per_req + 1
debug: i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
debug: t_req <- times_todo[c(i_t_beg, i_t_end)]
debug: t_req_str <- format_ISO8601(t_req, usetz = "Z")
debug: if (verbose) message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
debug: message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
Fetching request 1 of 1 (2021-01-01 to 2021-12-01) ~ 19:42:50 UTC
debug: ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
    0), nc)
debug: unlink(ncs0)
debug: nc_retry <- T
debug: nc_n_try <- 1
debug: n_max_retries
debug: while (nc_retry) {
    res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
        url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
            bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
        time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
    if (inherits(res, "try-error")) {
        err <- attr(res, "condition")
        msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
        nc_n_try <- nc_n_try + 1
        if (nc_n_try > n_max_retries) {
            stop(msg)
        }
        else {
            message(msg, "\nRETRYing...")
            Sys.sleep(1)
        }
    }
    else {
        nc_retry <- F
    }
}
debug: res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
    url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
        bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
    time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
debug: if (inherits(res, "try-error")) {
    err <- attr(res, "condition")
    msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
    nc_n_try <- nc_n_try + 1
    if (nc_n_try > n_max_retries) {
        stop(msg)
    }
    else {
        message(msg, "\nRETRYing...")
        Sys.sleep(1)
    }
} else {
    nc_retry <- F
}
debug: nc_retry <- F
debug: (while) nc_retry
debug: i_req <- i_req + 1
debug: (while) i_req <= n_reqs
debug: ncs <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size > 
    0), nc)
debug: r <- terra::rast(ncs)
debug: stopifnot(all(class(terra::time(r)) %in% c("POSIXct", "POSIXt")))
debug: idx <- dplyr::pull(dplyr::filter(dplyr::arrange(dplyr::tibble(idx = 1:terra::nlyr(r), 
    time = terra::time(r)), time), !duplicated(time)), idx)
debug: r <- terra::subset(r, idx)
debug: stopifnot(terra::crs(r, proj = T) == wgs84)
debug: if (mask_tif) r <- terra::mask(r, sf_zones)
debug: lyrs <- glue("{var}|{terra::time(r)}")
debug: if (length(dims_other) > 0 && !all(length(dims[dims_other]) == 
    1)) stop(glue("Other dimensions not yet supported: {paste(dims_other, collapse = ',')}"))
debug: names(r) <- lyrs
debug: if (!is.null(rast_tif)) {
    if (fs::file_exists(rast_tif)) {
        r_tmp_tif <- tempfile(fileext = ".tif")
        r_tmp <- c(rast(rast_tif), r)
        r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
        terra::writeRaster(r_tmp, r_tmp_tif)
        fs::file_delete(rast_tif)
        fs::file_move(r_tmp_tif, rast_tif)
        rm(r)
        rm(r_tmp)
    }
    else {
        terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
    }
    r <- terra::rast(rast_tif)
}
debug: if (fs::file_exists(rast_tif)) {
    r_tmp_tif <- tempfile(fileext = ".tif")
    r_tmp <- c(rast(rast_tif), r)
    r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
    terra::writeRaster(r_tmp, r_tmp_tif)
    fs::file_delete(rast_tif)
    fs::file_move(r_tmp_tif, rast_tif)
    rm(r)
    rm(r_tmp)
} else {
    terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
}
debug: terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
debug: r <- terra::rast(rast_tif)
debug: d_r <- mutate(tidyr::pivot_longer(sf::st_drop_geometry(sf::st_as_sf(terra::zonal(x = r, 
    z = terra::vect(dplyr::select(sf_zones, dplyr::all_of(fld_zones))), 
    fun = zonal_fun, exact = T, na.rm = T, as.polygons = T))), 
    cols = -dplyr::any_of(fld_zones), names_to = "lyr", values_to = zonal_fun), 
    time = readr::parse_datetime(str_replace(lyr, glue("{var}\\|(.*)"), 
        "\\1")))
debug: if (!is.null(zonal_csv)) write_csv(d_r, zonal_csv)
debug: write_csv(d_r, zonal_csv)
debug: if (!keep_nc) unlink(dir_nc, recursive = T)
debug: unlink(dir_nc, recursive = T)
debug: return(d_r)
Downloading 1 requests, up to 1785 time slices each
Called from: extractr::ed_extract(ed, var = v, sf_zones = ply, bbox = bb, 
    mask_tif = F, rast_tif = glue("{dir_out}/{nms}/{yr}.tif"), 
    zonal_fun = "mean", zonal_csv = glue("{dir_out}/{nms}/{yr}.csv"), 
    dir_nc = glue("{dir_out}/{nms}/{yr}_nc"), keep_nc = F, n_max_vals_per_req = 1e+05, 
    time_min = time_min, time_max = time_max, verbose = T)
debug: while (i_req <= n_reqs) {
    i_t_beg <- (i_req - 1) * n_t_per_req + 1
    i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
    t_req <- times_todo[c(i_t_beg, i_t_end)]
    t_req_str <- format_ISO8601(t_req, usetz = "Z")
    if (verbose) 
        message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
    ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
        ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
        0), nc)
    unlink(ncs0)
    nc_retry <- T
    nc_n_try <- 1
    n_max_retries
    while (nc_retry) {
        res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
            url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
                bbox[["xmax"]]), latitude = c(bbox[["ymin"]], 
                bbox[["ymax"]]), time = t_req_str, fmt = "nc", 
            store = rerddap::disk(path = dir_nc)))
        if (inherits(res, "try-error")) {
            err <- attr(res, "condition")
            msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
            nc_n_try <- nc_n_try + 1
            if (nc_n_try > n_max_retries) {
                stop(msg)
            }
            else {
                message(msg, "\nRETRYing...")
                Sys.sleep(1)
            }
        }
        else {
            nc_retry <- F
        }
    }
    i_req <- i_req + 1
}
debug: i_t_beg <- (i_req - 1) * n_t_per_req + 1
debug: i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
debug: t_req <- times_todo[c(i_t_beg, i_t_end)]
debug: t_req_str <- format_ISO8601(t_req, usetz = "Z")
debug: if (verbose) message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
debug: message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
Fetching request 1 of 1 (2022-01-01 to 2022-12-01) ~ 19:42:51 UTC
debug: ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
    0), nc)
debug: unlink(ncs0)
debug: nc_retry <- T
debug: nc_n_try <- 1
debug: n_max_retries
debug: while (nc_retry) {
    res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
        url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
            bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
        time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
    if (inherits(res, "try-error")) {
        err <- attr(res, "condition")
        msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
        nc_n_try <- nc_n_try + 1
        if (nc_n_try > n_max_retries) {
            stop(msg)
        }
        else {
            message(msg, "\nRETRYing...")
            Sys.sleep(1)
        }
    }
    else {
        nc_retry <- F
    }
}
debug: res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
    url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
        bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
    time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
debug: if (inherits(res, "try-error")) {
    err <- attr(res, "condition")
    msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
    nc_n_try <- nc_n_try + 1
    if (nc_n_try > n_max_retries) {
        stop(msg)
    }
    else {
        message(msg, "\nRETRYing...")
        Sys.sleep(1)
    }
} else {
    nc_retry <- F
}
debug: nc_retry <- F
debug: (while) nc_retry
debug: i_req <- i_req + 1
debug: (while) i_req <= n_reqs
debug: ncs <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size > 
    0), nc)
debug: r <- terra::rast(ncs)
debug: stopifnot(all(class(terra::time(r)) %in% c("POSIXct", "POSIXt")))
debug: idx <- dplyr::pull(dplyr::filter(dplyr::arrange(dplyr::tibble(idx = 1:terra::nlyr(r), 
    time = terra::time(r)), time), !duplicated(time)), idx)
debug: r <- terra::subset(r, idx)
debug: stopifnot(terra::crs(r, proj = T) == wgs84)
debug: if (mask_tif) r <- terra::mask(r, sf_zones)
debug: lyrs <- glue("{var}|{terra::time(r)}")
debug: if (length(dims_other) > 0 && !all(length(dims[dims_other]) == 
    1)) stop(glue("Other dimensions not yet supported: {paste(dims_other, collapse = ',')}"))
debug: names(r) <- lyrs
debug: if (!is.null(rast_tif)) {
    if (fs::file_exists(rast_tif)) {
        r_tmp_tif <- tempfile(fileext = ".tif")
        r_tmp <- c(rast(rast_tif), r)
        r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
        terra::writeRaster(r_tmp, r_tmp_tif)
        fs::file_delete(rast_tif)
        fs::file_move(r_tmp_tif, rast_tif)
        rm(r)
        rm(r_tmp)
    }
    else {
        terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
    }
    r <- terra::rast(rast_tif)
}
debug: if (fs::file_exists(rast_tif)) {
    r_tmp_tif <- tempfile(fileext = ".tif")
    r_tmp <- c(rast(rast_tif), r)
    r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
    terra::writeRaster(r_tmp, r_tmp_tif)
    fs::file_delete(rast_tif)
    fs::file_move(r_tmp_tif, rast_tif)
    rm(r)
    rm(r_tmp)
} else {
    terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
}
debug: terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
debug: r <- terra::rast(rast_tif)
debug: d_r <- mutate(tidyr::pivot_longer(sf::st_drop_geometry(sf::st_as_sf(terra::zonal(x = r, 
    z = terra::vect(dplyr::select(sf_zones, dplyr::all_of(fld_zones))), 
    fun = zonal_fun, exact = T, na.rm = T, as.polygons = T))), 
    cols = -dplyr::any_of(fld_zones), names_to = "lyr", values_to = zonal_fun), 
    time = readr::parse_datetime(str_replace(lyr, glue("{var}\\|(.*)"), 
        "\\1")))
debug: if (!is.null(zonal_csv)) write_csv(d_r, zonal_csv)
debug: write_csv(d_r, zonal_csv)
debug: if (!keep_nc) unlink(dir_nc, recursive = T)
debug: unlink(dir_nc, recursive = T)
debug: return(d_r)
Downloading 1 requests, up to 1785 time slices each
Called from: extractr::ed_extract(ed, var = v, sf_zones = ply, bbox = bb, 
    mask_tif = F, rast_tif = glue("{dir_out}/{nms}/{yr}.tif"), 
    zonal_fun = "mean", zonal_csv = glue("{dir_out}/{nms}/{yr}.csv"), 
    dir_nc = glue("{dir_out}/{nms}/{yr}_nc"), keep_nc = F, n_max_vals_per_req = 1e+05, 
    time_min = time_min, time_max = time_max, verbose = T)
debug: while (i_req <= n_reqs) {
    i_t_beg <- (i_req - 1) * n_t_per_req + 1
    i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
    t_req <- times_todo[c(i_t_beg, i_t_end)]
    t_req_str <- format_ISO8601(t_req, usetz = "Z")
    if (verbose) 
        message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
    ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
        ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
        0), nc)
    unlink(ncs0)
    nc_retry <- T
    nc_n_try <- 1
    n_max_retries
    while (nc_retry) {
        res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
            url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
                bbox[["xmax"]]), latitude = c(bbox[["ymin"]], 
                bbox[["ymax"]]), time = t_req_str, fmt = "nc", 
            store = rerddap::disk(path = dir_nc)))
        if (inherits(res, "try-error")) {
            err <- attr(res, "condition")
            msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
            nc_n_try <- nc_n_try + 1
            if (nc_n_try > n_max_retries) {
                stop(msg)
            }
            else {
                message(msg, "\nRETRYing...")
                Sys.sleep(1)
            }
        }
        else {
            nc_retry <- F
        }
    }
    i_req <- i_req + 1
}
debug: i_t_beg <- (i_req - 1) * n_t_per_req + 1
debug: i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
debug: t_req <- times_todo[c(i_t_beg, i_t_end)]
debug: t_req_str <- format_ISO8601(t_req, usetz = "Z")
debug: if (verbose) message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
debug: message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
Fetching request 1 of 1 (2023-01-01 to 2023-12-01) ~ 19:42:53 UTC
debug: ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
    0), nc)
debug: unlink(ncs0)
debug: nc_retry <- T
debug: nc_n_try <- 1
debug: n_max_retries
debug: while (nc_retry) {
    res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
        url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
            bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
        time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
    if (inherits(res, "try-error")) {
        err <- attr(res, "condition")
        msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
        nc_n_try <- nc_n_try + 1
        if (nc_n_try > n_max_retries) {
            stop(msg)
        }
        else {
            message(msg, "\nRETRYing...")
            Sys.sleep(1)
        }
    }
    else {
        nc_retry <- F
    }
}
debug: res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
    url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
        bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
    time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
debug: if (inherits(res, "try-error")) {
    err <- attr(res, "condition")
    msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
    nc_n_try <- nc_n_try + 1
    if (nc_n_try > n_max_retries) {
        stop(msg)
    }
    else {
        message(msg, "\nRETRYing...")
        Sys.sleep(1)
    }
} else {
    nc_retry <- F
}
debug: nc_retry <- F
debug: (while) nc_retry
debug: i_req <- i_req + 1
debug: (while) i_req <= n_reqs
debug: ncs <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size > 
    0), nc)
debug: r <- terra::rast(ncs)
debug: stopifnot(all(class(terra::time(r)) %in% c("POSIXct", "POSIXt")))
debug: idx <- dplyr::pull(dplyr::filter(dplyr::arrange(dplyr::tibble(idx = 1:terra::nlyr(r), 
    time = terra::time(r)), time), !duplicated(time)), idx)
debug: r <- terra::subset(r, idx)
debug: stopifnot(terra::crs(r, proj = T) == wgs84)
debug: if (mask_tif) r <- terra::mask(r, sf_zones)
debug: lyrs <- glue("{var}|{terra::time(r)}")
debug: if (length(dims_other) > 0 && !all(length(dims[dims_other]) == 
    1)) stop(glue("Other dimensions not yet supported: {paste(dims_other, collapse = ',')}"))
debug: names(r) <- lyrs
debug: if (!is.null(rast_tif)) {
    if (fs::file_exists(rast_tif)) {
        r_tmp_tif <- tempfile(fileext = ".tif")
        r_tmp <- c(rast(rast_tif), r)
        r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
        terra::writeRaster(r_tmp, r_tmp_tif)
        fs::file_delete(rast_tif)
        fs::file_move(r_tmp_tif, rast_tif)
        rm(r)
        rm(r_tmp)
    }
    else {
        terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
    }
    r <- terra::rast(rast_tif)
}
debug: if (fs::file_exists(rast_tif)) {
    r_tmp_tif <- tempfile(fileext = ".tif")
    r_tmp <- c(rast(rast_tif), r)
    r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
    terra::writeRaster(r_tmp, r_tmp_tif)
    fs::file_delete(rast_tif)
    fs::file_move(r_tmp_tif, rast_tif)
    rm(r)
    rm(r_tmp)
} else {
    terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
}
debug: terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
debug: r <- terra::rast(rast_tif)
debug: d_r <- mutate(tidyr::pivot_longer(sf::st_drop_geometry(sf::st_as_sf(terra::zonal(x = r, 
    z = terra::vect(dplyr::select(sf_zones, dplyr::all_of(fld_zones))), 
    fun = zonal_fun, exact = T, na.rm = T, as.polygons = T))), 
    cols = -dplyr::any_of(fld_zones), names_to = "lyr", values_to = zonal_fun), 
    time = readr::parse_datetime(str_replace(lyr, glue("{var}\\|(.*)"), 
        "\\1")))
debug: if (!is.null(zonal_csv)) write_csv(d_r, zonal_csv)
debug: write_csv(d_r, zonal_csv)
debug: if (!keep_nc) unlink(dir_nc, recursive = T)
debug: unlink(dir_nc, recursive = T)
debug: return(d_r)
Downloading 1 requests, up to 1785 time slices each
Called from: extractr::ed_extract(ed, var = v, sf_zones = ply, bbox = bb, 
    mask_tif = F, rast_tif = glue("{dir_out}/{nms}/{yr}.tif"), 
    zonal_fun = "mean", zonal_csv = glue("{dir_out}/{nms}/{yr}.csv"), 
    dir_nc = glue("{dir_out}/{nms}/{yr}_nc"), keep_nc = F, n_max_vals_per_req = 1e+05, 
    time_min = time_min, time_max = time_max, verbose = T)
debug: while (i_req <= n_reqs) {
    i_t_beg <- (i_req - 1) * n_t_per_req + 1
    i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
    t_req <- times_todo[c(i_t_beg, i_t_end)]
    t_req_str <- format_ISO8601(t_req, usetz = "Z")
    if (verbose) 
        message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
    ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
        ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
        0), nc)
    unlink(ncs0)
    nc_retry <- T
    nc_n_try <- 1
    n_max_retries
    while (nc_retry) {
        res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
            url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
                bbox[["xmax"]]), latitude = c(bbox[["ymin"]], 
                bbox[["ymax"]]), time = t_req_str, fmt = "nc", 
            store = rerddap::disk(path = dir_nc)))
        if (inherits(res, "try-error")) {
            err <- attr(res, "condition")
            msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
            nc_n_try <- nc_n_try + 1
            if (nc_n_try > n_max_retries) {
                stop(msg)
            }
            else {
                message(msg, "\nRETRYing...")
                Sys.sleep(1)
            }
        }
        else {
            nc_retry <- F
        }
    }
    i_req <- i_req + 1
}
debug: i_t_beg <- (i_req - 1) * n_t_per_req + 1
debug: i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
debug: t_req <- times_todo[c(i_t_beg, i_t_end)]
debug: t_req_str <- format_ISO8601(t_req, usetz = "Z")
debug: if (verbose) message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
debug: message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
Fetching request 1 of 1 (2024-01-01 to 2024-12-01) ~ 19:42:55 UTC
debug: ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
    0), nc)
debug: unlink(ncs0)
debug: nc_retry <- T
debug: nc_n_try <- 1
debug: n_max_retries
debug: while (nc_retry) {
    res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
        url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
            bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
        time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
    if (inherits(res, "try-error")) {
        err <- attr(res, "condition")
        msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
        nc_n_try <- nc_n_try + 1
        if (nc_n_try > n_max_retries) {
            stop(msg)
        }
        else {
            message(msg, "\nRETRYing...")
            Sys.sleep(1)
        }
    }
    else {
        nc_retry <- F
    }
}
debug: res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
    url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
        bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
    time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
debug: if (inherits(res, "try-error")) {
    err <- attr(res, "condition")
    msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
    nc_n_try <- nc_n_try + 1
    if (nc_n_try > n_max_retries) {
        stop(msg)
    }
    else {
        message(msg, "\nRETRYing...")
        Sys.sleep(1)
    }
} else {
    nc_retry <- F
}
debug: nc_retry <- F
debug: (while) nc_retry
debug: i_req <- i_req + 1
debug: (while) i_req <= n_reqs
debug: ncs <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size > 
    0), nc)
debug: r <- terra::rast(ncs)
debug: stopifnot(all(class(terra::time(r)) %in% c("POSIXct", "POSIXt")))
debug: idx <- dplyr::pull(dplyr::filter(dplyr::arrange(dplyr::tibble(idx = 1:terra::nlyr(r), 
    time = terra::time(r)), time), !duplicated(time)), idx)
debug: r <- terra::subset(r, idx)
debug: stopifnot(terra::crs(r, proj = T) == wgs84)
debug: if (mask_tif) r <- terra::mask(r, sf_zones)
debug: lyrs <- glue("{var}|{terra::time(r)}")
debug: if (length(dims_other) > 0 && !all(length(dims[dims_other]) == 
    1)) stop(glue("Other dimensions not yet supported: {paste(dims_other, collapse = ',')}"))
debug: names(r) <- lyrs
debug: if (!is.null(rast_tif)) {
    if (fs::file_exists(rast_tif)) {
        r_tmp_tif <- tempfile(fileext = ".tif")
        r_tmp <- c(rast(rast_tif), r)
        r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
        terra::writeRaster(r_tmp, r_tmp_tif)
        fs::file_delete(rast_tif)
        fs::file_move(r_tmp_tif, rast_tif)
        rm(r)
        rm(r_tmp)
    }
    else {
        terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
    }
    r <- terra::rast(rast_tif)
}
debug: if (fs::file_exists(rast_tif)) {
    r_tmp_tif <- tempfile(fileext = ".tif")
    r_tmp <- c(rast(rast_tif), r)
    r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
    terra::writeRaster(r_tmp, r_tmp_tif)
    fs::file_delete(rast_tif)
    fs::file_move(r_tmp_tif, rast_tif)
    rm(r)
    rm(r_tmp)
} else {
    terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
}
debug: terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
debug: r <- terra::rast(rast_tif)
debug: d_r <- mutate(tidyr::pivot_longer(sf::st_drop_geometry(sf::st_as_sf(terra::zonal(x = r, 
    z = terra::vect(dplyr::select(sf_zones, dplyr::all_of(fld_zones))), 
    fun = zonal_fun, exact = T, na.rm = T, as.polygons = T))), 
    cols = -dplyr::any_of(fld_zones), names_to = "lyr", values_to = zonal_fun), 
    time = readr::parse_datetime(str_replace(lyr, glue("{var}\\|(.*)"), 
        "\\1")))
debug: if (!is.null(zonal_csv)) write_csv(d_r, zonal_csv)
debug: write_csv(d_r, zonal_csv)
debug: if (!keep_nc) unlink(dir_nc, recursive = T)
debug: unlink(dir_nc, recursive = T)
debug: return(d_r)
Downloading 1 requests, up to 1785 time slices each
Called from: extractr::ed_extract(ed, var = v, sf_zones = ply, bbox = bb, 
    mask_tif = F, rast_tif = glue("{dir_out}/{nms}/{yr}.tif"), 
    zonal_fun = "mean", zonal_csv = glue("{dir_out}/{nms}/{yr}.csv"), 
    dir_nc = glue("{dir_out}/{nms}/{yr}_nc"), keep_nc = F, n_max_vals_per_req = 1e+05, 
    time_min = time_min, time_max = time_max, verbose = T)
debug: while (i_req <= n_reqs) {
    i_t_beg <- (i_req - 1) * n_t_per_req + 1
    i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
    t_req <- times_todo[c(i_t_beg, i_t_end)]
    t_req_str <- format_ISO8601(t_req, usetz = "Z")
    if (verbose) 
        message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
    ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
        ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
        0), nc)
    unlink(ncs0)
    nc_retry <- T
    nc_n_try <- 1
    n_max_retries
    while (nc_retry) {
        res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
            url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
                bbox[["xmax"]]), latitude = c(bbox[["ymin"]], 
                bbox[["ymax"]]), time = t_req_str, fmt = "nc", 
            store = rerddap::disk(path = dir_nc)))
        if (inherits(res, "try-error")) {
            err <- attr(res, "condition")
            msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
            nc_n_try <- nc_n_try + 1
            if (nc_n_try > n_max_retries) {
                stop(msg)
            }
            else {
                message(msg, "\nRETRYing...")
                Sys.sleep(1)
            }
        }
        else {
            nc_retry <- F
        }
    }
    i_req <- i_req + 1
}
debug: i_t_beg <- (i_req - 1) * n_t_per_req + 1
debug: i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
debug: t_req <- times_todo[c(i_t_beg, i_t_end)]
debug: t_req_str <- format_ISO8601(t_req, usetz = "Z")
debug: if (verbose) message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
debug: message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
Fetching request 1 of 1 (2025-01-01 to 2025-07-01) ~ 19:42:56 UTC
debug: ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
    0), nc)
debug: unlink(ncs0)
debug: nc_retry <- T
debug: nc_n_try <- 1
debug: n_max_retries
debug: while (nc_retry) {
    res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
        url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
            bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
        time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
    if (inherits(res, "try-error")) {
        err <- attr(res, "condition")
        msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
        nc_n_try <- nc_n_try + 1
        if (nc_n_try > n_max_retries) {
            stop(msg)
        }
        else {
            message(msg, "\nRETRYing...")
            Sys.sleep(1)
        }
    }
    else {
        nc_retry <- F
    }
}
debug: res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
    url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
        bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
    time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
debug: if (inherits(res, "try-error")) {
    err <- attr(res, "condition")
    msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
    nc_n_try <- nc_n_try + 1
    if (nc_n_try > n_max_retries) {
        stop(msg)
    }
    else {
        message(msg, "\nRETRYing...")
        Sys.sleep(1)
    }
} else {
    nc_retry <- F
}
debug: nc_retry <- F
debug: (while) nc_retry
debug: i_req <- i_req + 1
debug: (while) i_req <= n_reqs
debug: ncs <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size > 
    0), nc)
debug: r <- terra::rast(ncs)
debug: stopifnot(all(class(terra::time(r)) %in% c("POSIXct", "POSIXt")))
debug: idx <- dplyr::pull(dplyr::filter(dplyr::arrange(dplyr::tibble(idx = 1:terra::nlyr(r), 
    time = terra::time(r)), time), !duplicated(time)), idx)
debug: r <- terra::subset(r, idx)
debug: stopifnot(terra::crs(r, proj = T) == wgs84)
debug: if (mask_tif) r <- terra::mask(r, sf_zones)
debug: lyrs <- glue("{var}|{terra::time(r)}")
debug: if (length(dims_other) > 0 && !all(length(dims[dims_other]) == 
    1)) stop(glue("Other dimensions not yet supported: {paste(dims_other, collapse = ',')}"))
debug: names(r) <- lyrs
debug: if (!is.null(rast_tif)) {
    if (fs::file_exists(rast_tif)) {
        r_tmp_tif <- tempfile(fileext = ".tif")
        r_tmp <- c(rast(rast_tif), r)
        r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
        terra::writeRaster(r_tmp, r_tmp_tif)
        fs::file_delete(rast_tif)
        fs::file_move(r_tmp_tif, rast_tif)
        rm(r)
        rm(r_tmp)
    }
    else {
        terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
    }
    r <- terra::rast(rast_tif)
}
debug: if (fs::file_exists(rast_tif)) {
    r_tmp_tif <- tempfile(fileext = ".tif")
    r_tmp <- c(rast(rast_tif), r)
    r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
    terra::writeRaster(r_tmp, r_tmp_tif)
    fs::file_delete(rast_tif)
    fs::file_move(r_tmp_tif, rast_tif)
    rm(r)
    rm(r_tmp)
} else {
    terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
}
debug: terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
debug: r <- terra::rast(rast_tif)
debug: d_r <- mutate(tidyr::pivot_longer(sf::st_drop_geometry(sf::st_as_sf(terra::zonal(x = r, 
    z = terra::vect(dplyr::select(sf_zones, dplyr::all_of(fld_zones))), 
    fun = zonal_fun, exact = T, na.rm = T, as.polygons = T))), 
    cols = -dplyr::any_of(fld_zones), names_to = "lyr", values_to = zonal_fun), 
    time = readr::parse_datetime(str_replace(lyr, glue("{var}\\|(.*)"), 
        "\\1")))
debug: if (!is.null(zonal_csv)) write_csv(d_r, zonal_csv)
debug: write_csv(d_r, zonal_csv)
debug: if (!keep_nc) unlink(dir_nc, recursive = T)
debug: unlink(dir_nc, recursive = T)
debug: return(d_r)
Downloading 1 requests, up to 42 time slices each
Called from: extractr::ed_extract(ed, var = v, sf_zones = ply, bbox = bb, 
    mask_tif = F, rast_tif = glue("{dir_out}/{nms}/{yr}.tif"), 
    zonal_fun = "mean", zonal_csv = glue("{dir_out}/{nms}/{yr}.csv"), 
    dir_nc = glue("{dir_out}/{nms}/{yr}_nc"), keep_nc = F, n_max_vals_per_req = 1e+05, 
    time_min = time_min, time_max = time_max, verbose = T)
debug: while (i_req <= n_reqs) {
    i_t_beg <- (i_req - 1) * n_t_per_req + 1
    i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
    t_req <- times_todo[c(i_t_beg, i_t_end)]
    t_req_str <- format_ISO8601(t_req, usetz = "Z")
    if (verbose) 
        message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
    ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
        ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
        0), nc)
    unlink(ncs0)
    nc_retry <- T
    nc_n_try <- 1
    n_max_retries
    while (nc_retry) {
        res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
            url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
                bbox[["xmax"]]), latitude = c(bbox[["ymin"]], 
                bbox[["ymax"]]), time = t_req_str, fmt = "nc", 
            store = rerddap::disk(path = dir_nc)))
        if (inherits(res, "try-error")) {
            err <- attr(res, "condition")
            msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
            nc_n_try <- nc_n_try + 1
            if (nc_n_try > n_max_retries) {
                stop(msg)
            }
            else {
                message(msg, "\nRETRYing...")
                Sys.sleep(1)
            }
        }
        else {
            nc_retry <- F
        }
    }
    i_req <- i_req + 1
}
debug: i_t_beg <- (i_req - 1) * n_t_per_req + 1
debug: i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
debug: t_req <- times_todo[c(i_t_beg, i_t_end)]
debug: t_req_str <- format_ISO8601(t_req, usetz = "Z")
debug: if (verbose) message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
debug: message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
Fetching request 1 of 1 (1998-01-01 to 1998-12-01) ~ 19:42:58 UTC
debug: ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
    0), nc)
debug: unlink(ncs0)
debug: nc_retry <- T
debug: nc_n_try <- 1
debug: n_max_retries
debug: while (nc_retry) {
    res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
        url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
            bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
        time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
    if (inherits(res, "try-error")) {
        err <- attr(res, "condition")
        msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
        nc_n_try <- nc_n_try + 1
        if (nc_n_try > n_max_retries) {
            stop(msg)
        }
        else {
            message(msg, "\nRETRYing...")
            Sys.sleep(1)
        }
    }
    else {
        nc_retry <- F
    }
}
debug: res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
    url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
        bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
    time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
debug: if (inherits(res, "try-error")) {
    err <- attr(res, "condition")
    msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
    nc_n_try <- nc_n_try + 1
    if (nc_n_try > n_max_retries) {
        stop(msg)
    }
    else {
        message(msg, "\nRETRYing...")
        Sys.sleep(1)
    }
} else {
    nc_retry <- F
}
debug: nc_retry <- F
debug: (while) nc_retry
debug: i_req <- i_req + 1
debug: (while) i_req <= n_reqs
debug: ncs <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size > 
    0), nc)
debug: r <- terra::rast(ncs)
debug: stopifnot(all(class(terra::time(r)) %in% c("POSIXct", "POSIXt")))
debug: idx <- dplyr::pull(dplyr::filter(dplyr::arrange(dplyr::tibble(idx = 1:terra::nlyr(r), 
    time = terra::time(r)), time), !duplicated(time)), idx)
debug: r <- terra::subset(r, idx)
debug: stopifnot(terra::crs(r, proj = T) == wgs84)
debug: if (mask_tif) r <- terra::mask(r, sf_zones)
debug: lyrs <- glue("{var}|{terra::time(r)}")
debug: if (length(dims_other) > 0 && !all(length(dims[dims_other]) == 
    1)) stop(glue("Other dimensions not yet supported: {paste(dims_other, collapse = ',')}"))
debug: names(r) <- lyrs
debug: if (!is.null(rast_tif)) {
    if (fs::file_exists(rast_tif)) {
        r_tmp_tif <- tempfile(fileext = ".tif")
        r_tmp <- c(rast(rast_tif), r)
        r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
        terra::writeRaster(r_tmp, r_tmp_tif)
        fs::file_delete(rast_tif)
        fs::file_move(r_tmp_tif, rast_tif)
        rm(r)
        rm(r_tmp)
    }
    else {
        terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
    }
    r <- terra::rast(rast_tif)
}
debug: if (fs::file_exists(rast_tif)) {
    r_tmp_tif <- tempfile(fileext = ".tif")
    r_tmp <- c(rast(rast_tif), r)
    r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
    terra::writeRaster(r_tmp, r_tmp_tif)
    fs::file_delete(rast_tif)
    fs::file_move(r_tmp_tif, rast_tif)
    rm(r)
    rm(r_tmp)
} else {
    terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
}
debug: terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
debug: r <- terra::rast(rast_tif)
debug: d_r <- mutate(tidyr::pivot_longer(sf::st_drop_geometry(sf::st_as_sf(terra::zonal(x = r, 
    z = terra::vect(dplyr::select(sf_zones, dplyr::all_of(fld_zones))), 
    fun = zonal_fun, exact = T, na.rm = T, as.polygons = T))), 
    cols = -dplyr::any_of(fld_zones), names_to = "lyr", values_to = zonal_fun), 
    time = readr::parse_datetime(str_replace(lyr, glue("{var}\\|(.*)"), 
        "\\1")))
debug: if (!is.null(zonal_csv)) write_csv(d_r, zonal_csv)
debug: write_csv(d_r, zonal_csv)
debug: if (!keep_nc) unlink(dir_nc, recursive = T)
debug: unlink(dir_nc, recursive = T)
debug: return(d_r)
Downloading 1 requests, up to 42 time slices each
Called from: extractr::ed_extract(ed, var = v, sf_zones = ply, bbox = bb, 
    mask_tif = F, rast_tif = glue("{dir_out}/{nms}/{yr}.tif"), 
    zonal_fun = "mean", zonal_csv = glue("{dir_out}/{nms}/{yr}.csv"), 
    dir_nc = glue("{dir_out}/{nms}/{yr}_nc"), keep_nc = F, n_max_vals_per_req = 1e+05, 
    time_min = time_min, time_max = time_max, verbose = T)
debug: while (i_req <= n_reqs) {
    i_t_beg <- (i_req - 1) * n_t_per_req + 1
    i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
    t_req <- times_todo[c(i_t_beg, i_t_end)]
    t_req_str <- format_ISO8601(t_req, usetz = "Z")
    if (verbose) 
        message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
    ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
        ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
        0), nc)
    unlink(ncs0)
    nc_retry <- T
    nc_n_try <- 1
    n_max_retries
    while (nc_retry) {
        res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
            url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
                bbox[["xmax"]]), latitude = c(bbox[["ymin"]], 
                bbox[["ymax"]]), time = t_req_str, fmt = "nc", 
            store = rerddap::disk(path = dir_nc)))
        if (inherits(res, "try-error")) {
            err <- attr(res, "condition")
            msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
            nc_n_try <- nc_n_try + 1
            if (nc_n_try > n_max_retries) {
                stop(msg)
            }
            else {
                message(msg, "\nRETRYing...")
                Sys.sleep(1)
            }
        }
        else {
            nc_retry <- F
        }
    }
    i_req <- i_req + 1
}
debug: i_t_beg <- (i_req - 1) * n_t_per_req + 1
debug: i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
debug: t_req <- times_todo[c(i_t_beg, i_t_end)]
debug: t_req_str <- format_ISO8601(t_req, usetz = "Z")
debug: if (verbose) message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
debug: message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
Fetching request 1 of 1 (1999-01-01 to 1999-12-01) ~ 19:43:00 UTC
debug: ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
    0), nc)
debug: unlink(ncs0)
debug: nc_retry <- T
debug: nc_n_try <- 1
debug: n_max_retries
debug: while (nc_retry) {
    res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
        url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
            bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
        time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
    if (inherits(res, "try-error")) {
        err <- attr(res, "condition")
        msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
        nc_n_try <- nc_n_try + 1
        if (nc_n_try > n_max_retries) {
            stop(msg)
        }
        else {
            message(msg, "\nRETRYing...")
            Sys.sleep(1)
        }
    }
    else {
        nc_retry <- F
    }
}
debug: res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
    url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
        bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
    time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
debug: if (inherits(res, "try-error")) {
    err <- attr(res, "condition")
    msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
    nc_n_try <- nc_n_try + 1
    if (nc_n_try > n_max_retries) {
        stop(msg)
    }
    else {
        message(msg, "\nRETRYing...")
        Sys.sleep(1)
    }
} else {
    nc_retry <- F
}
debug: nc_retry <- F
debug: (while) nc_retry
debug: i_req <- i_req + 1
debug: (while) i_req <= n_reqs
debug: ncs <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size > 
    0), nc)
debug: r <- terra::rast(ncs)
debug: stopifnot(all(class(terra::time(r)) %in% c("POSIXct", "POSIXt")))
debug: idx <- dplyr::pull(dplyr::filter(dplyr::arrange(dplyr::tibble(idx = 1:terra::nlyr(r), 
    time = terra::time(r)), time), !duplicated(time)), idx)
debug: r <- terra::subset(r, idx)
debug: stopifnot(terra::crs(r, proj = T) == wgs84)
debug: if (mask_tif) r <- terra::mask(r, sf_zones)
debug: lyrs <- glue("{var}|{terra::time(r)}")
debug: if (length(dims_other) > 0 && !all(length(dims[dims_other]) == 
    1)) stop(glue("Other dimensions not yet supported: {paste(dims_other, collapse = ',')}"))
debug: names(r) <- lyrs
debug: if (!is.null(rast_tif)) {
    if (fs::file_exists(rast_tif)) {
        r_tmp_tif <- tempfile(fileext = ".tif")
        r_tmp <- c(rast(rast_tif), r)
        r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
        terra::writeRaster(r_tmp, r_tmp_tif)
        fs::file_delete(rast_tif)
        fs::file_move(r_tmp_tif, rast_tif)
        rm(r)
        rm(r_tmp)
    }
    else {
        terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
    }
    r <- terra::rast(rast_tif)
}
debug: if (fs::file_exists(rast_tif)) {
    r_tmp_tif <- tempfile(fileext = ".tif")
    r_tmp <- c(rast(rast_tif), r)
    r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
    terra::writeRaster(r_tmp, r_tmp_tif)
    fs::file_delete(rast_tif)
    fs::file_move(r_tmp_tif, rast_tif)
    rm(r)
    rm(r_tmp)
} else {
    terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
}
debug: terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
debug: r <- terra::rast(rast_tif)
debug: d_r <- mutate(tidyr::pivot_longer(sf::st_drop_geometry(sf::st_as_sf(terra::zonal(x = r, 
    z = terra::vect(dplyr::select(sf_zones, dplyr::all_of(fld_zones))), 
    fun = zonal_fun, exact = T, na.rm = T, as.polygons = T))), 
    cols = -dplyr::any_of(fld_zones), names_to = "lyr", values_to = zonal_fun), 
    time = readr::parse_datetime(str_replace(lyr, glue("{var}\\|(.*)"), 
        "\\1")))
debug: if (!is.null(zonal_csv)) write_csv(d_r, zonal_csv)
debug: write_csv(d_r, zonal_csv)
debug: if (!keep_nc) unlink(dir_nc, recursive = T)
debug: unlink(dir_nc, recursive = T)
debug: return(d_r)
Downloading 1 requests, up to 42 time slices each
Called from: extractr::ed_extract(ed, var = v, sf_zones = ply, bbox = bb, 
    mask_tif = F, rast_tif = glue("{dir_out}/{nms}/{yr}.tif"), 
    zonal_fun = "mean", zonal_csv = glue("{dir_out}/{nms}/{yr}.csv"), 
    dir_nc = glue("{dir_out}/{nms}/{yr}_nc"), keep_nc = F, n_max_vals_per_req = 1e+05, 
    time_min = time_min, time_max = time_max, verbose = T)
debug: while (i_req <= n_reqs) {
    i_t_beg <- (i_req - 1) * n_t_per_req + 1
    i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
    t_req <- times_todo[c(i_t_beg, i_t_end)]
    t_req_str <- format_ISO8601(t_req, usetz = "Z")
    if (verbose) 
        message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
    ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
        ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
        0), nc)
    unlink(ncs0)
    nc_retry <- T
    nc_n_try <- 1
    n_max_retries
    while (nc_retry) {
        res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
            url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
                bbox[["xmax"]]), latitude = c(bbox[["ymin"]], 
                bbox[["ymax"]]), time = t_req_str, fmt = "nc", 
            store = rerddap::disk(path = dir_nc)))
        if (inherits(res, "try-error")) {
            err <- attr(res, "condition")
            msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
            nc_n_try <- nc_n_try + 1
            if (nc_n_try > n_max_retries) {
                stop(msg)
            }
            else {
                message(msg, "\nRETRYing...")
                Sys.sleep(1)
            }
        }
        else {
            nc_retry <- F
        }
    }
    i_req <- i_req + 1
}
debug: i_t_beg <- (i_req - 1) * n_t_per_req + 1
debug: i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
debug: t_req <- times_todo[c(i_t_beg, i_t_end)]
debug: t_req_str <- format_ISO8601(t_req, usetz = "Z")
debug: if (verbose) message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
debug: message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
Fetching request 1 of 1 (2000-01-01 to 2000-12-01) ~ 19:43:03 UTC
debug: ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
    0), nc)
debug: unlink(ncs0)
debug: nc_retry <- T
debug: nc_n_try <- 1
debug: n_max_retries
debug: while (nc_retry) {
    res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
        url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
            bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
        time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
    if (inherits(res, "try-error")) {
        err <- attr(res, "condition")
        msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
        nc_n_try <- nc_n_try + 1
        if (nc_n_try > n_max_retries) {
            stop(msg)
        }
        else {
            message(msg, "\nRETRYing...")
            Sys.sleep(1)
        }
    }
    else {
        nc_retry <- F
    }
}
debug: res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
    url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
        bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
    time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
debug: if (inherits(res, "try-error")) {
    err <- attr(res, "condition")
    msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
    nc_n_try <- nc_n_try + 1
    if (nc_n_try > n_max_retries) {
        stop(msg)
    }
    else {
        message(msg, "\nRETRYing...")
        Sys.sleep(1)
    }
} else {
    nc_retry <- F
}
debug: nc_retry <- F
debug: (while) nc_retry
debug: i_req <- i_req + 1
debug: (while) i_req <= n_reqs
debug: ncs <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size > 
    0), nc)
debug: r <- terra::rast(ncs)
debug: stopifnot(all(class(terra::time(r)) %in% c("POSIXct", "POSIXt")))
debug: idx <- dplyr::pull(dplyr::filter(dplyr::arrange(dplyr::tibble(idx = 1:terra::nlyr(r), 
    time = terra::time(r)), time), !duplicated(time)), idx)
debug: r <- terra::subset(r, idx)
debug: stopifnot(terra::crs(r, proj = T) == wgs84)
debug: if (mask_tif) r <- terra::mask(r, sf_zones)
debug: lyrs <- glue("{var}|{terra::time(r)}")
debug: if (length(dims_other) > 0 && !all(length(dims[dims_other]) == 
    1)) stop(glue("Other dimensions not yet supported: {paste(dims_other, collapse = ',')}"))
debug: names(r) <- lyrs
debug: if (!is.null(rast_tif)) {
    if (fs::file_exists(rast_tif)) {
        r_tmp_tif <- tempfile(fileext = ".tif")
        r_tmp <- c(rast(rast_tif), r)
        r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
        terra::writeRaster(r_tmp, r_tmp_tif)
        fs::file_delete(rast_tif)
        fs::file_move(r_tmp_tif, rast_tif)
        rm(r)
        rm(r_tmp)
    }
    else {
        terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
    }
    r <- terra::rast(rast_tif)
}
debug: if (fs::file_exists(rast_tif)) {
    r_tmp_tif <- tempfile(fileext = ".tif")
    r_tmp <- c(rast(rast_tif), r)
    r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
    terra::writeRaster(r_tmp, r_tmp_tif)
    fs::file_delete(rast_tif)
    fs::file_move(r_tmp_tif, rast_tif)
    rm(r)
    rm(r_tmp)
} else {
    terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
}
debug: terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
debug: r <- terra::rast(rast_tif)
debug: d_r <- mutate(tidyr::pivot_longer(sf::st_drop_geometry(sf::st_as_sf(terra::zonal(x = r, 
    z = terra::vect(dplyr::select(sf_zones, dplyr::all_of(fld_zones))), 
    fun = zonal_fun, exact = T, na.rm = T, as.polygons = T))), 
    cols = -dplyr::any_of(fld_zones), names_to = "lyr", values_to = zonal_fun), 
    time = readr::parse_datetime(str_replace(lyr, glue("{var}\\|(.*)"), 
        "\\1")))
debug: if (!is.null(zonal_csv)) write_csv(d_r, zonal_csv)
debug: write_csv(d_r, zonal_csv)
debug: if (!keep_nc) unlink(dir_nc, recursive = T)
debug: unlink(dir_nc, recursive = T)
debug: return(d_r)
Downloading 1 requests, up to 42 time slices each
Called from: extractr::ed_extract(ed, var = v, sf_zones = ply, bbox = bb, 
    mask_tif = F, rast_tif = glue("{dir_out}/{nms}/{yr}.tif"), 
    zonal_fun = "mean", zonal_csv = glue("{dir_out}/{nms}/{yr}.csv"), 
    dir_nc = glue("{dir_out}/{nms}/{yr}_nc"), keep_nc = F, n_max_vals_per_req = 1e+05, 
    time_min = time_min, time_max = time_max, verbose = T)
debug: while (i_req <= n_reqs) {
    i_t_beg <- (i_req - 1) * n_t_per_req + 1
    i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
    t_req <- times_todo[c(i_t_beg, i_t_end)]
    t_req_str <- format_ISO8601(t_req, usetz = "Z")
    if (verbose) 
        message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
    ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
        ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
        0), nc)
    unlink(ncs0)
    nc_retry <- T
    nc_n_try <- 1
    n_max_retries
    while (nc_retry) {
        res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
            url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
                bbox[["xmax"]]), latitude = c(bbox[["ymin"]], 
                bbox[["ymax"]]), time = t_req_str, fmt = "nc", 
            store = rerddap::disk(path = dir_nc)))
        if (inherits(res, "try-error")) {
            err <- attr(res, "condition")
            msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
            nc_n_try <- nc_n_try + 1
            if (nc_n_try > n_max_retries) {
                stop(msg)
            }
            else {
                message(msg, "\nRETRYing...")
                Sys.sleep(1)
            }
        }
        else {
            nc_retry <- F
        }
    }
    i_req <- i_req + 1
}
debug: i_t_beg <- (i_req - 1) * n_t_per_req + 1
debug: i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
debug: t_req <- times_todo[c(i_t_beg, i_t_end)]
debug: t_req_str <- format_ISO8601(t_req, usetz = "Z")
debug: if (verbose) message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
debug: message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
Fetching request 1 of 1 (2001-01-01 to 2001-12-01) ~ 19:43:05 UTC
debug: ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
    0), nc)
debug: unlink(ncs0)
debug: nc_retry <- T
debug: nc_n_try <- 1
debug: n_max_retries
debug: while (nc_retry) {
    res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
        url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
            bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
        time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
    if (inherits(res, "try-error")) {
        err <- attr(res, "condition")
        msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
        nc_n_try <- nc_n_try + 1
        if (nc_n_try > n_max_retries) {
            stop(msg)
        }
        else {
            message(msg, "\nRETRYing...")
            Sys.sleep(1)
        }
    }
    else {
        nc_retry <- F
    }
}
debug: res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
    url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
        bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
    time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
debug: if (inherits(res, "try-error")) {
    err <- attr(res, "condition")
    msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
    nc_n_try <- nc_n_try + 1
    if (nc_n_try > n_max_retries) {
        stop(msg)
    }
    else {
        message(msg, "\nRETRYing...")
        Sys.sleep(1)
    }
} else {
    nc_retry <- F
}
debug: nc_retry <- F
debug: (while) nc_retry
debug: i_req <- i_req + 1
debug: (while) i_req <= n_reqs
debug: ncs <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size > 
    0), nc)
debug: r <- terra::rast(ncs)
debug: stopifnot(all(class(terra::time(r)) %in% c("POSIXct", "POSIXt")))
debug: idx <- dplyr::pull(dplyr::filter(dplyr::arrange(dplyr::tibble(idx = 1:terra::nlyr(r), 
    time = terra::time(r)), time), !duplicated(time)), idx)
debug: r <- terra::subset(r, idx)
debug: stopifnot(terra::crs(r, proj = T) == wgs84)
debug: if (mask_tif) r <- terra::mask(r, sf_zones)
debug: lyrs <- glue("{var}|{terra::time(r)}")
debug: if (length(dims_other) > 0 && !all(length(dims[dims_other]) == 
    1)) stop(glue("Other dimensions not yet supported: {paste(dims_other, collapse = ',')}"))
debug: names(r) <- lyrs
debug: if (!is.null(rast_tif)) {
    if (fs::file_exists(rast_tif)) {
        r_tmp_tif <- tempfile(fileext = ".tif")
        r_tmp <- c(rast(rast_tif), r)
        r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
        terra::writeRaster(r_tmp, r_tmp_tif)
        fs::file_delete(rast_tif)
        fs::file_move(r_tmp_tif, rast_tif)
        rm(r)
        rm(r_tmp)
    }
    else {
        terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
    }
    r <- terra::rast(rast_tif)
}
debug: if (fs::file_exists(rast_tif)) {
    r_tmp_tif <- tempfile(fileext = ".tif")
    r_tmp <- c(rast(rast_tif), r)
    r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
    terra::writeRaster(r_tmp, r_tmp_tif)
    fs::file_delete(rast_tif)
    fs::file_move(r_tmp_tif, rast_tif)
    rm(r)
    rm(r_tmp)
} else {
    terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
}
debug: terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
debug: r <- terra::rast(rast_tif)
debug: d_r <- mutate(tidyr::pivot_longer(sf::st_drop_geometry(sf::st_as_sf(terra::zonal(x = r, 
    z = terra::vect(dplyr::select(sf_zones, dplyr::all_of(fld_zones))), 
    fun = zonal_fun, exact = T, na.rm = T, as.polygons = T))), 
    cols = -dplyr::any_of(fld_zones), names_to = "lyr", values_to = zonal_fun), 
    time = readr::parse_datetime(str_replace(lyr, glue("{var}\\|(.*)"), 
        "\\1")))
debug: if (!is.null(zonal_csv)) write_csv(d_r, zonal_csv)
debug: write_csv(d_r, zonal_csv)
debug: if (!keep_nc) unlink(dir_nc, recursive = T)
debug: unlink(dir_nc, recursive = T)
debug: return(d_r)
Downloading 1 requests, up to 42 time slices each
Called from: extractr::ed_extract(ed, var = v, sf_zones = ply, bbox = bb, 
    mask_tif = F, rast_tif = glue("{dir_out}/{nms}/{yr}.tif"), 
    zonal_fun = "mean", zonal_csv = glue("{dir_out}/{nms}/{yr}.csv"), 
    dir_nc = glue("{dir_out}/{nms}/{yr}_nc"), keep_nc = F, n_max_vals_per_req = 1e+05, 
    time_min = time_min, time_max = time_max, verbose = T)
debug: while (i_req <= n_reqs) {
    i_t_beg <- (i_req - 1) * n_t_per_req + 1
    i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
    t_req <- times_todo[c(i_t_beg, i_t_end)]
    t_req_str <- format_ISO8601(t_req, usetz = "Z")
    if (verbose) 
        message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
    ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
        ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
        0), nc)
    unlink(ncs0)
    nc_retry <- T
    nc_n_try <- 1
    n_max_retries
    while (nc_retry) {
        res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
            url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
                bbox[["xmax"]]), latitude = c(bbox[["ymin"]], 
                bbox[["ymax"]]), time = t_req_str, fmt = "nc", 
            store = rerddap::disk(path = dir_nc)))
        if (inherits(res, "try-error")) {
            err <- attr(res, "condition")
            msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
            nc_n_try <- nc_n_try + 1
            if (nc_n_try > n_max_retries) {
                stop(msg)
            }
            else {
                message(msg, "\nRETRYing...")
                Sys.sleep(1)
            }
        }
        else {
            nc_retry <- F
        }
    }
    i_req <- i_req + 1
}
debug: i_t_beg <- (i_req - 1) * n_t_per_req + 1
debug: i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
debug: t_req <- times_todo[c(i_t_beg, i_t_end)]
debug: t_req_str <- format_ISO8601(t_req, usetz = "Z")
debug: if (verbose) message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
debug: message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
Fetching request 1 of 1 (2002-01-01 to 2002-12-01) ~ 19:43:07 UTC
debug: ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
    0), nc)
debug: unlink(ncs0)
debug: nc_retry <- T
debug: nc_n_try <- 1
debug: n_max_retries
debug: while (nc_retry) {
    res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
        url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
            bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
        time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
    if (inherits(res, "try-error")) {
        err <- attr(res, "condition")
        msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
        nc_n_try <- nc_n_try + 1
        if (nc_n_try > n_max_retries) {
            stop(msg)
        }
        else {
            message(msg, "\nRETRYing...")
            Sys.sleep(1)
        }
    }
    else {
        nc_retry <- F
    }
}
debug: res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
    url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
        bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
    time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
debug: if (inherits(res, "try-error")) {
    err <- attr(res, "condition")
    msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
    nc_n_try <- nc_n_try + 1
    if (nc_n_try > n_max_retries) {
        stop(msg)
    }
    else {
        message(msg, "\nRETRYing...")
        Sys.sleep(1)
    }
} else {
    nc_retry <- F
}
debug: nc_retry <- F
debug: (while) nc_retry
debug: i_req <- i_req + 1
debug: (while) i_req <= n_reqs
debug: ncs <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size > 
    0), nc)
debug: r <- terra::rast(ncs)
debug: stopifnot(all(class(terra::time(r)) %in% c("POSIXct", "POSIXt")))
debug: idx <- dplyr::pull(dplyr::filter(dplyr::arrange(dplyr::tibble(idx = 1:terra::nlyr(r), 
    time = terra::time(r)), time), !duplicated(time)), idx)
debug: r <- terra::subset(r, idx)
debug: stopifnot(terra::crs(r, proj = T) == wgs84)
debug: if (mask_tif) r <- terra::mask(r, sf_zones)
debug: lyrs <- glue("{var}|{terra::time(r)}")
debug: if (length(dims_other) > 0 && !all(length(dims[dims_other]) == 
    1)) stop(glue("Other dimensions not yet supported: {paste(dims_other, collapse = ',')}"))
debug: names(r) <- lyrs
debug: if (!is.null(rast_tif)) {
    if (fs::file_exists(rast_tif)) {
        r_tmp_tif <- tempfile(fileext = ".tif")
        r_tmp <- c(rast(rast_tif), r)
        r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
        terra::writeRaster(r_tmp, r_tmp_tif)
        fs::file_delete(rast_tif)
        fs::file_move(r_tmp_tif, rast_tif)
        rm(r)
        rm(r_tmp)
    }
    else {
        terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
    }
    r <- terra::rast(rast_tif)
}
debug: if (fs::file_exists(rast_tif)) {
    r_tmp_tif <- tempfile(fileext = ".tif")
    r_tmp <- c(rast(rast_tif), r)
    r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
    terra::writeRaster(r_tmp, r_tmp_tif)
    fs::file_delete(rast_tif)
    fs::file_move(r_tmp_tif, rast_tif)
    rm(r)
    rm(r_tmp)
} else {
    terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
}
debug: terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
debug: r <- terra::rast(rast_tif)
debug: d_r <- mutate(tidyr::pivot_longer(sf::st_drop_geometry(sf::st_as_sf(terra::zonal(x = r, 
    z = terra::vect(dplyr::select(sf_zones, dplyr::all_of(fld_zones))), 
    fun = zonal_fun, exact = T, na.rm = T, as.polygons = T))), 
    cols = -dplyr::any_of(fld_zones), names_to = "lyr", values_to = zonal_fun), 
    time = readr::parse_datetime(str_replace(lyr, glue("{var}\\|(.*)"), 
        "\\1")))
debug: if (!is.null(zonal_csv)) write_csv(d_r, zonal_csv)
debug: write_csv(d_r, zonal_csv)
debug: if (!keep_nc) unlink(dir_nc, recursive = T)
debug: unlink(dir_nc, recursive = T)
debug: return(d_r)
Downloading 1 requests, up to 42 time slices each
Called from: extractr::ed_extract(ed, var = v, sf_zones = ply, bbox = bb, 
    mask_tif = F, rast_tif = glue("{dir_out}/{nms}/{yr}.tif"), 
    zonal_fun = "mean", zonal_csv = glue("{dir_out}/{nms}/{yr}.csv"), 
    dir_nc = glue("{dir_out}/{nms}/{yr}_nc"), keep_nc = F, n_max_vals_per_req = 1e+05, 
    time_min = time_min, time_max = time_max, verbose = T)
debug: while (i_req <= n_reqs) {
    i_t_beg <- (i_req - 1) * n_t_per_req + 1
    i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
    t_req <- times_todo[c(i_t_beg, i_t_end)]
    t_req_str <- format_ISO8601(t_req, usetz = "Z")
    if (verbose) 
        message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
    ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
        ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
        0), nc)
    unlink(ncs0)
    nc_retry <- T
    nc_n_try <- 1
    n_max_retries
    while (nc_retry) {
        res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
            url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
                bbox[["xmax"]]), latitude = c(bbox[["ymin"]], 
                bbox[["ymax"]]), time = t_req_str, fmt = "nc", 
            store = rerddap::disk(path = dir_nc)))
        if (inherits(res, "try-error")) {
            err <- attr(res, "condition")
            msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
            nc_n_try <- nc_n_try + 1
            if (nc_n_try > n_max_retries) {
                stop(msg)
            }
            else {
                message(msg, "\nRETRYing...")
                Sys.sleep(1)
            }
        }
        else {
            nc_retry <- F
        }
    }
    i_req <- i_req + 1
}
debug: i_t_beg <- (i_req - 1) * n_t_per_req + 1
debug: i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
debug: t_req <- times_todo[c(i_t_beg, i_t_end)]
debug: t_req_str <- format_ISO8601(t_req, usetz = "Z")
debug: if (verbose) message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
debug: message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
Fetching request 1 of 1 (2003-01-01 to 2003-12-01) ~ 19:43:09 UTC
debug: ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
    0), nc)
debug: unlink(ncs0)
debug: nc_retry <- T
debug: nc_n_try <- 1
debug: n_max_retries
debug: while (nc_retry) {
    res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
        url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
            bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
        time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
    if (inherits(res, "try-error")) {
        err <- attr(res, "condition")
        msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
        nc_n_try <- nc_n_try + 1
        if (nc_n_try > n_max_retries) {
            stop(msg)
        }
        else {
            message(msg, "\nRETRYing...")
            Sys.sleep(1)
        }
    }
    else {
        nc_retry <- F
    }
}
debug: res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
    url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
        bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
    time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
debug: if (inherits(res, "try-error")) {
    err <- attr(res, "condition")
    msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
    nc_n_try <- nc_n_try + 1
    if (nc_n_try > n_max_retries) {
        stop(msg)
    }
    else {
        message(msg, "\nRETRYing...")
        Sys.sleep(1)
    }
} else {
    nc_retry <- F
}
debug: nc_retry <- F
debug: (while) nc_retry
debug: i_req <- i_req + 1
debug: (while) i_req <= n_reqs
debug: ncs <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size > 
    0), nc)
debug: r <- terra::rast(ncs)
debug: stopifnot(all(class(terra::time(r)) %in% c("POSIXct", "POSIXt")))
debug: idx <- dplyr::pull(dplyr::filter(dplyr::arrange(dplyr::tibble(idx = 1:terra::nlyr(r), 
    time = terra::time(r)), time), !duplicated(time)), idx)
debug: r <- terra::subset(r, idx)
debug: stopifnot(terra::crs(r, proj = T) == wgs84)
debug: if (mask_tif) r <- terra::mask(r, sf_zones)
debug: lyrs <- glue("{var}|{terra::time(r)}")
debug: if (length(dims_other) > 0 && !all(length(dims[dims_other]) == 
    1)) stop(glue("Other dimensions not yet supported: {paste(dims_other, collapse = ',')}"))
debug: names(r) <- lyrs
debug: if (!is.null(rast_tif)) {
    if (fs::file_exists(rast_tif)) {
        r_tmp_tif <- tempfile(fileext = ".tif")
        r_tmp <- c(rast(rast_tif), r)
        r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
        terra::writeRaster(r_tmp, r_tmp_tif)
        fs::file_delete(rast_tif)
        fs::file_move(r_tmp_tif, rast_tif)
        rm(r)
        rm(r_tmp)
    }
    else {
        terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
    }
    r <- terra::rast(rast_tif)
}
debug: if (fs::file_exists(rast_tif)) {
    r_tmp_tif <- tempfile(fileext = ".tif")
    r_tmp <- c(rast(rast_tif), r)
    r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
    terra::writeRaster(r_tmp, r_tmp_tif)
    fs::file_delete(rast_tif)
    fs::file_move(r_tmp_tif, rast_tif)
    rm(r)
    rm(r_tmp)
} else {
    terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
}
debug: terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
debug: r <- terra::rast(rast_tif)
debug: d_r <- mutate(tidyr::pivot_longer(sf::st_drop_geometry(sf::st_as_sf(terra::zonal(x = r, 
    z = terra::vect(dplyr::select(sf_zones, dplyr::all_of(fld_zones))), 
    fun = zonal_fun, exact = T, na.rm = T, as.polygons = T))), 
    cols = -dplyr::any_of(fld_zones), names_to = "lyr", values_to = zonal_fun), 
    time = readr::parse_datetime(str_replace(lyr, glue("{var}\\|(.*)"), 
        "\\1")))
debug: if (!is.null(zonal_csv)) write_csv(d_r, zonal_csv)
debug: write_csv(d_r, zonal_csv)
debug: if (!keep_nc) unlink(dir_nc, recursive = T)
debug: unlink(dir_nc, recursive = T)
debug: return(d_r)
Downloading 1 requests, up to 42 time slices each
Called from: extractr::ed_extract(ed, var = v, sf_zones = ply, bbox = bb, 
    mask_tif = F, rast_tif = glue("{dir_out}/{nms}/{yr}.tif"), 
    zonal_fun = "mean", zonal_csv = glue("{dir_out}/{nms}/{yr}.csv"), 
    dir_nc = glue("{dir_out}/{nms}/{yr}_nc"), keep_nc = F, n_max_vals_per_req = 1e+05, 
    time_min = time_min, time_max = time_max, verbose = T)
debug: while (i_req <= n_reqs) {
    i_t_beg <- (i_req - 1) * n_t_per_req + 1
    i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
    t_req <- times_todo[c(i_t_beg, i_t_end)]
    t_req_str <- format_ISO8601(t_req, usetz = "Z")
    if (verbose) 
        message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
    ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
        ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
        0), nc)
    unlink(ncs0)
    nc_retry <- T
    nc_n_try <- 1
    n_max_retries
    while (nc_retry) {
        res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
            url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
                bbox[["xmax"]]), latitude = c(bbox[["ymin"]], 
                bbox[["ymax"]]), time = t_req_str, fmt = "nc", 
            store = rerddap::disk(path = dir_nc)))
        if (inherits(res, "try-error")) {
            err <- attr(res, "condition")
            msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
            nc_n_try <- nc_n_try + 1
            if (nc_n_try > n_max_retries) {
                stop(msg)
            }
            else {
                message(msg, "\nRETRYing...")
                Sys.sleep(1)
            }
        }
        else {
            nc_retry <- F
        }
    }
    i_req <- i_req + 1
}
debug: i_t_beg <- (i_req - 1) * n_t_per_req + 1
debug: i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
debug: t_req <- times_todo[c(i_t_beg, i_t_end)]
debug: t_req_str <- format_ISO8601(t_req, usetz = "Z")
debug: if (verbose) message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
debug: message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
Fetching request 1 of 1 (2004-01-01 to 2004-12-01) ~ 19:43:11 UTC
debug: ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
    0), nc)
debug: unlink(ncs0)
debug: nc_retry <- T
debug: nc_n_try <- 1
debug: n_max_retries
debug: while (nc_retry) {
    res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
        url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
            bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
        time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
    if (inherits(res, "try-error")) {
        err <- attr(res, "condition")
        msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
        nc_n_try <- nc_n_try + 1
        if (nc_n_try > n_max_retries) {
            stop(msg)
        }
        else {
            message(msg, "\nRETRYing...")
            Sys.sleep(1)
        }
    }
    else {
        nc_retry <- F
    }
}
debug: res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
    url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
        bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
    time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
debug: if (inherits(res, "try-error")) {
    err <- attr(res, "condition")
    msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
    nc_n_try <- nc_n_try + 1
    if (nc_n_try > n_max_retries) {
        stop(msg)
    }
    else {
        message(msg, "\nRETRYing...")
        Sys.sleep(1)
    }
} else {
    nc_retry <- F
}
debug: nc_retry <- F
debug: (while) nc_retry
debug: i_req <- i_req + 1
debug: (while) i_req <= n_reqs
debug: ncs <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size > 
    0), nc)
debug: r <- terra::rast(ncs)
debug: stopifnot(all(class(terra::time(r)) %in% c("POSIXct", "POSIXt")))
debug: idx <- dplyr::pull(dplyr::filter(dplyr::arrange(dplyr::tibble(idx = 1:terra::nlyr(r), 
    time = terra::time(r)), time), !duplicated(time)), idx)
debug: r <- terra::subset(r, idx)
debug: stopifnot(terra::crs(r, proj = T) == wgs84)
debug: if (mask_tif) r <- terra::mask(r, sf_zones)
debug: lyrs <- glue("{var}|{terra::time(r)}")
debug: if (length(dims_other) > 0 && !all(length(dims[dims_other]) == 
    1)) stop(glue("Other dimensions not yet supported: {paste(dims_other, collapse = ',')}"))
debug: names(r) <- lyrs
debug: if (!is.null(rast_tif)) {
    if (fs::file_exists(rast_tif)) {
        r_tmp_tif <- tempfile(fileext = ".tif")
        r_tmp <- c(rast(rast_tif), r)
        r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
        terra::writeRaster(r_tmp, r_tmp_tif)
        fs::file_delete(rast_tif)
        fs::file_move(r_tmp_tif, rast_tif)
        rm(r)
        rm(r_tmp)
    }
    else {
        terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
    }
    r <- terra::rast(rast_tif)
}
debug: if (fs::file_exists(rast_tif)) {
    r_tmp_tif <- tempfile(fileext = ".tif")
    r_tmp <- c(rast(rast_tif), r)
    r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
    terra::writeRaster(r_tmp, r_tmp_tif)
    fs::file_delete(rast_tif)
    fs::file_move(r_tmp_tif, rast_tif)
    rm(r)
    rm(r_tmp)
} else {
    terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
}
debug: terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
debug: r <- terra::rast(rast_tif)
debug: d_r <- mutate(tidyr::pivot_longer(sf::st_drop_geometry(sf::st_as_sf(terra::zonal(x = r, 
    z = terra::vect(dplyr::select(sf_zones, dplyr::all_of(fld_zones))), 
    fun = zonal_fun, exact = T, na.rm = T, as.polygons = T))), 
    cols = -dplyr::any_of(fld_zones), names_to = "lyr", values_to = zonal_fun), 
    time = readr::parse_datetime(str_replace(lyr, glue("{var}\\|(.*)"), 
        "\\1")))
debug: if (!is.null(zonal_csv)) write_csv(d_r, zonal_csv)
debug: write_csv(d_r, zonal_csv)
debug: if (!keep_nc) unlink(dir_nc, recursive = T)
debug: unlink(dir_nc, recursive = T)
debug: return(d_r)
Downloading 1 requests, up to 42 time slices each
Called from: extractr::ed_extract(ed, var = v, sf_zones = ply, bbox = bb, 
    mask_tif = F, rast_tif = glue("{dir_out}/{nms}/{yr}.tif"), 
    zonal_fun = "mean", zonal_csv = glue("{dir_out}/{nms}/{yr}.csv"), 
    dir_nc = glue("{dir_out}/{nms}/{yr}_nc"), keep_nc = F, n_max_vals_per_req = 1e+05, 
    time_min = time_min, time_max = time_max, verbose = T)
debug: while (i_req <= n_reqs) {
    i_t_beg <- (i_req - 1) * n_t_per_req + 1
    i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
    t_req <- times_todo[c(i_t_beg, i_t_end)]
    t_req_str <- format_ISO8601(t_req, usetz = "Z")
    if (verbose) 
        message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
    ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
        ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
        0), nc)
    unlink(ncs0)
    nc_retry <- T
    nc_n_try <- 1
    n_max_retries
    while (nc_retry) {
        res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
            url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
                bbox[["xmax"]]), latitude = c(bbox[["ymin"]], 
                bbox[["ymax"]]), time = t_req_str, fmt = "nc", 
            store = rerddap::disk(path = dir_nc)))
        if (inherits(res, "try-error")) {
            err <- attr(res, "condition")
            msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
            nc_n_try <- nc_n_try + 1
            if (nc_n_try > n_max_retries) {
                stop(msg)
            }
            else {
                message(msg, "\nRETRYing...")
                Sys.sleep(1)
            }
        }
        else {
            nc_retry <- F
        }
    }
    i_req <- i_req + 1
}
debug: i_t_beg <- (i_req - 1) * n_t_per_req + 1
debug: i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
debug: t_req <- times_todo[c(i_t_beg, i_t_end)]
debug: t_req_str <- format_ISO8601(t_req, usetz = "Z")
debug: if (verbose) message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
debug: message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
Fetching request 1 of 1 (2005-01-01 to 2005-12-01) ~ 19:43:13 UTC
debug: ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
    0), nc)
debug: unlink(ncs0)
debug: nc_retry <- T
debug: nc_n_try <- 1
debug: n_max_retries
debug: while (nc_retry) {
    res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
        url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
            bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
        time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
    if (inherits(res, "try-error")) {
        err <- attr(res, "condition")
        msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
        nc_n_try <- nc_n_try + 1
        if (nc_n_try > n_max_retries) {
            stop(msg)
        }
        else {
            message(msg, "\nRETRYing...")
            Sys.sleep(1)
        }
    }
    else {
        nc_retry <- F
    }
}
debug: res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
    url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
        bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
    time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
debug: if (inherits(res, "try-error")) {
    err <- attr(res, "condition")
    msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
    nc_n_try <- nc_n_try + 1
    if (nc_n_try > n_max_retries) {
        stop(msg)
    }
    else {
        message(msg, "\nRETRYing...")
        Sys.sleep(1)
    }
} else {
    nc_retry <- F
}
debug: nc_retry <- F
debug: (while) nc_retry
debug: i_req <- i_req + 1
debug: (while) i_req <= n_reqs
debug: ncs <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size > 
    0), nc)
debug: r <- terra::rast(ncs)
debug: stopifnot(all(class(terra::time(r)) %in% c("POSIXct", "POSIXt")))
debug: idx <- dplyr::pull(dplyr::filter(dplyr::arrange(dplyr::tibble(idx = 1:terra::nlyr(r), 
    time = terra::time(r)), time), !duplicated(time)), idx)
debug: r <- terra::subset(r, idx)
debug: stopifnot(terra::crs(r, proj = T) == wgs84)
debug: if (mask_tif) r <- terra::mask(r, sf_zones)
debug: lyrs <- glue("{var}|{terra::time(r)}")
debug: if (length(dims_other) > 0 && !all(length(dims[dims_other]) == 
    1)) stop(glue("Other dimensions not yet supported: {paste(dims_other, collapse = ',')}"))
debug: names(r) <- lyrs
debug: if (!is.null(rast_tif)) {
    if (fs::file_exists(rast_tif)) {
        r_tmp_tif <- tempfile(fileext = ".tif")
        r_tmp <- c(rast(rast_tif), r)
        r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
        terra::writeRaster(r_tmp, r_tmp_tif)
        fs::file_delete(rast_tif)
        fs::file_move(r_tmp_tif, rast_tif)
        rm(r)
        rm(r_tmp)
    }
    else {
        terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
    }
    r <- terra::rast(rast_tif)
}
debug: if (fs::file_exists(rast_tif)) {
    r_tmp_tif <- tempfile(fileext = ".tif")
    r_tmp <- c(rast(rast_tif), r)
    r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
    terra::writeRaster(r_tmp, r_tmp_tif)
    fs::file_delete(rast_tif)
    fs::file_move(r_tmp_tif, rast_tif)
    rm(r)
    rm(r_tmp)
} else {
    terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
}
debug: terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
debug: r <- terra::rast(rast_tif)
debug: d_r <- mutate(tidyr::pivot_longer(sf::st_drop_geometry(sf::st_as_sf(terra::zonal(x = r, 
    z = terra::vect(dplyr::select(sf_zones, dplyr::all_of(fld_zones))), 
    fun = zonal_fun, exact = T, na.rm = T, as.polygons = T))), 
    cols = -dplyr::any_of(fld_zones), names_to = "lyr", values_to = zonal_fun), 
    time = readr::parse_datetime(str_replace(lyr, glue("{var}\\|(.*)"), 
        "\\1")))
debug: if (!is.null(zonal_csv)) write_csv(d_r, zonal_csv)
debug: write_csv(d_r, zonal_csv)
debug: if (!keep_nc) unlink(dir_nc, recursive = T)
debug: unlink(dir_nc, recursive = T)
debug: return(d_r)
Downloading 1 requests, up to 42 time slices each
Called from: extractr::ed_extract(ed, var = v, sf_zones = ply, bbox = bb, 
    mask_tif = F, rast_tif = glue("{dir_out}/{nms}/{yr}.tif"), 
    zonal_fun = "mean", zonal_csv = glue("{dir_out}/{nms}/{yr}.csv"), 
    dir_nc = glue("{dir_out}/{nms}/{yr}_nc"), keep_nc = F, n_max_vals_per_req = 1e+05, 
    time_min = time_min, time_max = time_max, verbose = T)
debug: while (i_req <= n_reqs) {
    i_t_beg <- (i_req - 1) * n_t_per_req + 1
    i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
    t_req <- times_todo[c(i_t_beg, i_t_end)]
    t_req_str <- format_ISO8601(t_req, usetz = "Z")
    if (verbose) 
        message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
    ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
        ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
        0), nc)
    unlink(ncs0)
    nc_retry <- T
    nc_n_try <- 1
    n_max_retries
    while (nc_retry) {
        res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
            url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
                bbox[["xmax"]]), latitude = c(bbox[["ymin"]], 
                bbox[["ymax"]]), time = t_req_str, fmt = "nc", 
            store = rerddap::disk(path = dir_nc)))
        if (inherits(res, "try-error")) {
            err <- attr(res, "condition")
            msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
            nc_n_try <- nc_n_try + 1
            if (nc_n_try > n_max_retries) {
                stop(msg)
            }
            else {
                message(msg, "\nRETRYing...")
                Sys.sleep(1)
            }
        }
        else {
            nc_retry <- F
        }
    }
    i_req <- i_req + 1
}
debug: i_t_beg <- (i_req - 1) * n_t_per_req + 1
debug: i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
debug: t_req <- times_todo[c(i_t_beg, i_t_end)]
debug: t_req_str <- format_ISO8601(t_req, usetz = "Z")
debug: if (verbose) message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
debug: message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
Fetching request 1 of 1 (2006-01-01 to 2006-12-01) ~ 19:43:15 UTC
debug: ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
    0), nc)
debug: unlink(ncs0)
debug: nc_retry <- T
debug: nc_n_try <- 1
debug: n_max_retries
debug: while (nc_retry) {
    res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
        url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
            bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
        time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
    if (inherits(res, "try-error")) {
        err <- attr(res, "condition")
        msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
        nc_n_try <- nc_n_try + 1
        if (nc_n_try > n_max_retries) {
            stop(msg)
        }
        else {
            message(msg, "\nRETRYing...")
            Sys.sleep(1)
        }
    }
    else {
        nc_retry <- F
    }
}
debug: res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
    url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
        bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
    time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
debug: if (inherits(res, "try-error")) {
    err <- attr(res, "condition")
    msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
    nc_n_try <- nc_n_try + 1
    if (nc_n_try > n_max_retries) {
        stop(msg)
    }
    else {
        message(msg, "\nRETRYing...")
        Sys.sleep(1)
    }
} else {
    nc_retry <- F
}
debug: nc_retry <- F
debug: (while) nc_retry
debug: i_req <- i_req + 1
debug: (while) i_req <= n_reqs
debug: ncs <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size > 
    0), nc)
debug: r <- terra::rast(ncs)
debug: stopifnot(all(class(terra::time(r)) %in% c("POSIXct", "POSIXt")))
debug: idx <- dplyr::pull(dplyr::filter(dplyr::arrange(dplyr::tibble(idx = 1:terra::nlyr(r), 
    time = terra::time(r)), time), !duplicated(time)), idx)
debug: r <- terra::subset(r, idx)
debug: stopifnot(terra::crs(r, proj = T) == wgs84)
debug: if (mask_tif) r <- terra::mask(r, sf_zones)
debug: lyrs <- glue("{var}|{terra::time(r)}")
debug: if (length(dims_other) > 0 && !all(length(dims[dims_other]) == 
    1)) stop(glue("Other dimensions not yet supported: {paste(dims_other, collapse = ',')}"))
debug: names(r) <- lyrs
debug: if (!is.null(rast_tif)) {
    if (fs::file_exists(rast_tif)) {
        r_tmp_tif <- tempfile(fileext = ".tif")
        r_tmp <- c(rast(rast_tif), r)
        r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
        terra::writeRaster(r_tmp, r_tmp_tif)
        fs::file_delete(rast_tif)
        fs::file_move(r_tmp_tif, rast_tif)
        rm(r)
        rm(r_tmp)
    }
    else {
        terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
    }
    r <- terra::rast(rast_tif)
}
debug: if (fs::file_exists(rast_tif)) {
    r_tmp_tif <- tempfile(fileext = ".tif")
    r_tmp <- c(rast(rast_tif), r)
    r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
    terra::writeRaster(r_tmp, r_tmp_tif)
    fs::file_delete(rast_tif)
    fs::file_move(r_tmp_tif, rast_tif)
    rm(r)
    rm(r_tmp)
} else {
    terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
}
debug: terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
debug: r <- terra::rast(rast_tif)
debug: d_r <- mutate(tidyr::pivot_longer(sf::st_drop_geometry(sf::st_as_sf(terra::zonal(x = r, 
    z = terra::vect(dplyr::select(sf_zones, dplyr::all_of(fld_zones))), 
    fun = zonal_fun, exact = T, na.rm = T, as.polygons = T))), 
    cols = -dplyr::any_of(fld_zones), names_to = "lyr", values_to = zonal_fun), 
    time = readr::parse_datetime(str_replace(lyr, glue("{var}\\|(.*)"), 
        "\\1")))
debug: if (!is.null(zonal_csv)) write_csv(d_r, zonal_csv)
debug: write_csv(d_r, zonal_csv)
debug: if (!keep_nc) unlink(dir_nc, recursive = T)
debug: unlink(dir_nc, recursive = T)
debug: return(d_r)
Downloading 1 requests, up to 42 time slices each
Called from: extractr::ed_extract(ed, var = v, sf_zones = ply, bbox = bb, 
    mask_tif = F, rast_tif = glue("{dir_out}/{nms}/{yr}.tif"), 
    zonal_fun = "mean", zonal_csv = glue("{dir_out}/{nms}/{yr}.csv"), 
    dir_nc = glue("{dir_out}/{nms}/{yr}_nc"), keep_nc = F, n_max_vals_per_req = 1e+05, 
    time_min = time_min, time_max = time_max, verbose = T)
debug: while (i_req <= n_reqs) {
    i_t_beg <- (i_req - 1) * n_t_per_req + 1
    i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
    t_req <- times_todo[c(i_t_beg, i_t_end)]
    t_req_str <- format_ISO8601(t_req, usetz = "Z")
    if (verbose) 
        message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
    ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
        ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
        0), nc)
    unlink(ncs0)
    nc_retry <- T
    nc_n_try <- 1
    n_max_retries
    while (nc_retry) {
        res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
            url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
                bbox[["xmax"]]), latitude = c(bbox[["ymin"]], 
                bbox[["ymax"]]), time = t_req_str, fmt = "nc", 
            store = rerddap::disk(path = dir_nc)))
        if (inherits(res, "try-error")) {
            err <- attr(res, "condition")
            msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
            nc_n_try <- nc_n_try + 1
            if (nc_n_try > n_max_retries) {
                stop(msg)
            }
            else {
                message(msg, "\nRETRYing...")
                Sys.sleep(1)
            }
        }
        else {
            nc_retry <- F
        }
    }
    i_req <- i_req + 1
}
debug: i_t_beg <- (i_req - 1) * n_t_per_req + 1
debug: i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
debug: t_req <- times_todo[c(i_t_beg, i_t_end)]
debug: t_req_str <- format_ISO8601(t_req, usetz = "Z")
debug: if (verbose) message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
debug: message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
Fetching request 1 of 1 (2007-01-01 to 2007-12-01) ~ 19:43:17 UTC
debug: ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
    0), nc)
debug: unlink(ncs0)
debug: nc_retry <- T
debug: nc_n_try <- 1
debug: n_max_retries
debug: while (nc_retry) {
    res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
        url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
            bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
        time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
    if (inherits(res, "try-error")) {
        err <- attr(res, "condition")
        msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
        nc_n_try <- nc_n_try + 1
        if (nc_n_try > n_max_retries) {
            stop(msg)
        }
        else {
            message(msg, "\nRETRYing...")
            Sys.sleep(1)
        }
    }
    else {
        nc_retry <- F
    }
}
debug: res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
    url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
        bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
    time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
debug: if (inherits(res, "try-error")) {
    err <- attr(res, "condition")
    msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
    nc_n_try <- nc_n_try + 1
    if (nc_n_try > n_max_retries) {
        stop(msg)
    }
    else {
        message(msg, "\nRETRYing...")
        Sys.sleep(1)
    }
} else {
    nc_retry <- F
}
debug: nc_retry <- F
debug: (while) nc_retry
debug: i_req <- i_req + 1
debug: (while) i_req <= n_reqs
debug: ncs <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size > 
    0), nc)
debug: r <- terra::rast(ncs)
debug: stopifnot(all(class(terra::time(r)) %in% c("POSIXct", "POSIXt")))
debug: idx <- dplyr::pull(dplyr::filter(dplyr::arrange(dplyr::tibble(idx = 1:terra::nlyr(r), 
    time = terra::time(r)), time), !duplicated(time)), idx)
debug: r <- terra::subset(r, idx)
debug: stopifnot(terra::crs(r, proj = T) == wgs84)
debug: if (mask_tif) r <- terra::mask(r, sf_zones)
debug: lyrs <- glue("{var}|{terra::time(r)}")
debug: if (length(dims_other) > 0 && !all(length(dims[dims_other]) == 
    1)) stop(glue("Other dimensions not yet supported: {paste(dims_other, collapse = ',')}"))
debug: names(r) <- lyrs
debug: if (!is.null(rast_tif)) {
    if (fs::file_exists(rast_tif)) {
        r_tmp_tif <- tempfile(fileext = ".tif")
        r_tmp <- c(rast(rast_tif), r)
        r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
        terra::writeRaster(r_tmp, r_tmp_tif)
        fs::file_delete(rast_tif)
        fs::file_move(r_tmp_tif, rast_tif)
        rm(r)
        rm(r_tmp)
    }
    else {
        terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
    }
    r <- terra::rast(rast_tif)
}
debug: if (fs::file_exists(rast_tif)) {
    r_tmp_tif <- tempfile(fileext = ".tif")
    r_tmp <- c(rast(rast_tif), r)
    r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
    terra::writeRaster(r_tmp, r_tmp_tif)
    fs::file_delete(rast_tif)
    fs::file_move(r_tmp_tif, rast_tif)
    rm(r)
    rm(r_tmp)
} else {
    terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
}
debug: terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
debug: r <- terra::rast(rast_tif)
debug: d_r <- mutate(tidyr::pivot_longer(sf::st_drop_geometry(sf::st_as_sf(terra::zonal(x = r, 
    z = terra::vect(dplyr::select(sf_zones, dplyr::all_of(fld_zones))), 
    fun = zonal_fun, exact = T, na.rm = T, as.polygons = T))), 
    cols = -dplyr::any_of(fld_zones), names_to = "lyr", values_to = zonal_fun), 
    time = readr::parse_datetime(str_replace(lyr, glue("{var}\\|(.*)"), 
        "\\1")))
debug: if (!is.null(zonal_csv)) write_csv(d_r, zonal_csv)
debug: write_csv(d_r, zonal_csv)
debug: if (!keep_nc) unlink(dir_nc, recursive = T)
debug: unlink(dir_nc, recursive = T)
debug: return(d_r)
Downloading 1 requests, up to 42 time slices each
Called from: extractr::ed_extract(ed, var = v, sf_zones = ply, bbox = bb, 
    mask_tif = F, rast_tif = glue("{dir_out}/{nms}/{yr}.tif"), 
    zonal_fun = "mean", zonal_csv = glue("{dir_out}/{nms}/{yr}.csv"), 
    dir_nc = glue("{dir_out}/{nms}/{yr}_nc"), keep_nc = F, n_max_vals_per_req = 1e+05, 
    time_min = time_min, time_max = time_max, verbose = T)
debug: while (i_req <= n_reqs) {
    i_t_beg <- (i_req - 1) * n_t_per_req + 1
    i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
    t_req <- times_todo[c(i_t_beg, i_t_end)]
    t_req_str <- format_ISO8601(t_req, usetz = "Z")
    if (verbose) 
        message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
    ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
        ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
        0), nc)
    unlink(ncs0)
    nc_retry <- T
    nc_n_try <- 1
    n_max_retries
    while (nc_retry) {
        res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
            url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
                bbox[["xmax"]]), latitude = c(bbox[["ymin"]], 
                bbox[["ymax"]]), time = t_req_str, fmt = "nc", 
            store = rerddap::disk(path = dir_nc)))
        if (inherits(res, "try-error")) {
            err <- attr(res, "condition")
            msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
            nc_n_try <- nc_n_try + 1
            if (nc_n_try > n_max_retries) {
                stop(msg)
            }
            else {
                message(msg, "\nRETRYing...")
                Sys.sleep(1)
            }
        }
        else {
            nc_retry <- F
        }
    }
    i_req <- i_req + 1
}
debug: i_t_beg <- (i_req - 1) * n_t_per_req + 1
debug: i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
debug: t_req <- times_todo[c(i_t_beg, i_t_end)]
debug: t_req_str <- format_ISO8601(t_req, usetz = "Z")
debug: if (verbose) message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
debug: message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
Fetching request 1 of 1 (2008-01-01 to 2008-12-01) ~ 19:43:19 UTC
debug: ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
    0), nc)
debug: unlink(ncs0)
debug: nc_retry <- T
debug: nc_n_try <- 1
debug: n_max_retries
debug: while (nc_retry) {
    res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
        url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
            bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
        time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
    if (inherits(res, "try-error")) {
        err <- attr(res, "condition")
        msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
        nc_n_try <- nc_n_try + 1
        if (nc_n_try > n_max_retries) {
            stop(msg)
        }
        else {
            message(msg, "\nRETRYing...")
            Sys.sleep(1)
        }
    }
    else {
        nc_retry <- F
    }
}
debug: res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
    url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
        bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
    time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
debug: if (inherits(res, "try-error")) {
    err <- attr(res, "condition")
    msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
    nc_n_try <- nc_n_try + 1
    if (nc_n_try > n_max_retries) {
        stop(msg)
    }
    else {
        message(msg, "\nRETRYing...")
        Sys.sleep(1)
    }
} else {
    nc_retry <- F
}
debug: nc_retry <- F
debug: (while) nc_retry
debug: i_req <- i_req + 1
debug: (while) i_req <= n_reqs
debug: ncs <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size > 
    0), nc)
debug: r <- terra::rast(ncs)
debug: stopifnot(all(class(terra::time(r)) %in% c("POSIXct", "POSIXt")))
debug: idx <- dplyr::pull(dplyr::filter(dplyr::arrange(dplyr::tibble(idx = 1:terra::nlyr(r), 
    time = terra::time(r)), time), !duplicated(time)), idx)
debug: r <- terra::subset(r, idx)
debug: stopifnot(terra::crs(r, proj = T) == wgs84)
debug: if (mask_tif) r <- terra::mask(r, sf_zones)
debug: lyrs <- glue("{var}|{terra::time(r)}")
debug: if (length(dims_other) > 0 && !all(length(dims[dims_other]) == 
    1)) stop(glue("Other dimensions not yet supported: {paste(dims_other, collapse = ',')}"))
debug: names(r) <- lyrs
debug: if (!is.null(rast_tif)) {
    if (fs::file_exists(rast_tif)) {
        r_tmp_tif <- tempfile(fileext = ".tif")
        r_tmp <- c(rast(rast_tif), r)
        r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
        terra::writeRaster(r_tmp, r_tmp_tif)
        fs::file_delete(rast_tif)
        fs::file_move(r_tmp_tif, rast_tif)
        rm(r)
        rm(r_tmp)
    }
    else {
        terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
    }
    r <- terra::rast(rast_tif)
}
debug: if (fs::file_exists(rast_tif)) {
    r_tmp_tif <- tempfile(fileext = ".tif")
    r_tmp <- c(rast(rast_tif), r)
    r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
    terra::writeRaster(r_tmp, r_tmp_tif)
    fs::file_delete(rast_tif)
    fs::file_move(r_tmp_tif, rast_tif)
    rm(r)
    rm(r_tmp)
} else {
    terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
}
debug: terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
debug: r <- terra::rast(rast_tif)
debug: d_r <- mutate(tidyr::pivot_longer(sf::st_drop_geometry(sf::st_as_sf(terra::zonal(x = r, 
    z = terra::vect(dplyr::select(sf_zones, dplyr::all_of(fld_zones))), 
    fun = zonal_fun, exact = T, na.rm = T, as.polygons = T))), 
    cols = -dplyr::any_of(fld_zones), names_to = "lyr", values_to = zonal_fun), 
    time = readr::parse_datetime(str_replace(lyr, glue("{var}\\|(.*)"), 
        "\\1")))
debug: if (!is.null(zonal_csv)) write_csv(d_r, zonal_csv)
debug: write_csv(d_r, zonal_csv)
debug: if (!keep_nc) unlink(dir_nc, recursive = T)
debug: unlink(dir_nc, recursive = T)
debug: return(d_r)
Downloading 1 requests, up to 42 time slices each
Called from: extractr::ed_extract(ed, var = v, sf_zones = ply, bbox = bb, 
    mask_tif = F, rast_tif = glue("{dir_out}/{nms}/{yr}.tif"), 
    zonal_fun = "mean", zonal_csv = glue("{dir_out}/{nms}/{yr}.csv"), 
    dir_nc = glue("{dir_out}/{nms}/{yr}_nc"), keep_nc = F, n_max_vals_per_req = 1e+05, 
    time_min = time_min, time_max = time_max, verbose = T)
debug: while (i_req <= n_reqs) {
    i_t_beg <- (i_req - 1) * n_t_per_req + 1
    i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
    t_req <- times_todo[c(i_t_beg, i_t_end)]
    t_req_str <- format_ISO8601(t_req, usetz = "Z")
    if (verbose) 
        message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
    ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
        ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
        0), nc)
    unlink(ncs0)
    nc_retry <- T
    nc_n_try <- 1
    n_max_retries
    while (nc_retry) {
        res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
            url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
                bbox[["xmax"]]), latitude = c(bbox[["ymin"]], 
                bbox[["ymax"]]), time = t_req_str, fmt = "nc", 
            store = rerddap::disk(path = dir_nc)))
        if (inherits(res, "try-error")) {
            err <- attr(res, "condition")
            msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
            nc_n_try <- nc_n_try + 1
            if (nc_n_try > n_max_retries) {
                stop(msg)
            }
            else {
                message(msg, "\nRETRYing...")
                Sys.sleep(1)
            }
        }
        else {
            nc_retry <- F
        }
    }
    i_req <- i_req + 1
}
debug: i_t_beg <- (i_req - 1) * n_t_per_req + 1
debug: i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
debug: t_req <- times_todo[c(i_t_beg, i_t_end)]
debug: t_req_str <- format_ISO8601(t_req, usetz = "Z")
debug: if (verbose) message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
debug: message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
Fetching request 1 of 1 (2009-01-01 to 2009-12-01) ~ 19:43:21 UTC
debug: ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
    0), nc)
debug: unlink(ncs0)
debug: nc_retry <- T
debug: nc_n_try <- 1
debug: n_max_retries
debug: while (nc_retry) {
    res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
        url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
            bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
        time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
    if (inherits(res, "try-error")) {
        err <- attr(res, "condition")
        msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
        nc_n_try <- nc_n_try + 1
        if (nc_n_try > n_max_retries) {
            stop(msg)
        }
        else {
            message(msg, "\nRETRYing...")
            Sys.sleep(1)
        }
    }
    else {
        nc_retry <- F
    }
}
debug: res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
    url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
        bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
    time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
debug: if (inherits(res, "try-error")) {
    err <- attr(res, "condition")
    msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
    nc_n_try <- nc_n_try + 1
    if (nc_n_try > n_max_retries) {
        stop(msg)
    }
    else {
        message(msg, "\nRETRYing...")
        Sys.sleep(1)
    }
} else {
    nc_retry <- F
}
debug: nc_retry <- F
debug: (while) nc_retry
debug: i_req <- i_req + 1
debug: (while) i_req <= n_reqs
debug: ncs <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size > 
    0), nc)
debug: r <- terra::rast(ncs)
debug: stopifnot(all(class(terra::time(r)) %in% c("POSIXct", "POSIXt")))
debug: idx <- dplyr::pull(dplyr::filter(dplyr::arrange(dplyr::tibble(idx = 1:terra::nlyr(r), 
    time = terra::time(r)), time), !duplicated(time)), idx)
debug: r <- terra::subset(r, idx)
debug: stopifnot(terra::crs(r, proj = T) == wgs84)
debug: if (mask_tif) r <- terra::mask(r, sf_zones)
debug: lyrs <- glue("{var}|{terra::time(r)}")
debug: if (length(dims_other) > 0 && !all(length(dims[dims_other]) == 
    1)) stop(glue("Other dimensions not yet supported: {paste(dims_other, collapse = ',')}"))
debug: names(r) <- lyrs
debug: if (!is.null(rast_tif)) {
    if (fs::file_exists(rast_tif)) {
        r_tmp_tif <- tempfile(fileext = ".tif")
        r_tmp <- c(rast(rast_tif), r)
        r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
        terra::writeRaster(r_tmp, r_tmp_tif)
        fs::file_delete(rast_tif)
        fs::file_move(r_tmp_tif, rast_tif)
        rm(r)
        rm(r_tmp)
    }
    else {
        terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
    }
    r <- terra::rast(rast_tif)
}
debug: if (fs::file_exists(rast_tif)) {
    r_tmp_tif <- tempfile(fileext = ".tif")
    r_tmp <- c(rast(rast_tif), r)
    r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
    terra::writeRaster(r_tmp, r_tmp_tif)
    fs::file_delete(rast_tif)
    fs::file_move(r_tmp_tif, rast_tif)
    rm(r)
    rm(r_tmp)
} else {
    terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
}
debug: terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
debug: r <- terra::rast(rast_tif)
debug: d_r <- mutate(tidyr::pivot_longer(sf::st_drop_geometry(sf::st_as_sf(terra::zonal(x = r, 
    z = terra::vect(dplyr::select(sf_zones, dplyr::all_of(fld_zones))), 
    fun = zonal_fun, exact = T, na.rm = T, as.polygons = T))), 
    cols = -dplyr::any_of(fld_zones), names_to = "lyr", values_to = zonal_fun), 
    time = readr::parse_datetime(str_replace(lyr, glue("{var}\\|(.*)"), 
        "\\1")))
debug: if (!is.null(zonal_csv)) write_csv(d_r, zonal_csv)
debug: write_csv(d_r, zonal_csv)
debug: if (!keep_nc) unlink(dir_nc, recursive = T)
debug: unlink(dir_nc, recursive = T)
debug: return(d_r)
Downloading 1 requests, up to 42 time slices each
Called from: extractr::ed_extract(ed, var = v, sf_zones = ply, bbox = bb, 
    mask_tif = F, rast_tif = glue("{dir_out}/{nms}/{yr}.tif"), 
    zonal_fun = "mean", zonal_csv = glue("{dir_out}/{nms}/{yr}.csv"), 
    dir_nc = glue("{dir_out}/{nms}/{yr}_nc"), keep_nc = F, n_max_vals_per_req = 1e+05, 
    time_min = time_min, time_max = time_max, verbose = T)
debug: while (i_req <= n_reqs) {
    i_t_beg <- (i_req - 1) * n_t_per_req + 1
    i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
    t_req <- times_todo[c(i_t_beg, i_t_end)]
    t_req_str <- format_ISO8601(t_req, usetz = "Z")
    if (verbose) 
        message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
    ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
        ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
        0), nc)
    unlink(ncs0)
    nc_retry <- T
    nc_n_try <- 1
    n_max_retries
    while (nc_retry) {
        res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
            url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
                bbox[["xmax"]]), latitude = c(bbox[["ymin"]], 
                bbox[["ymax"]]), time = t_req_str, fmt = "nc", 
            store = rerddap::disk(path = dir_nc)))
        if (inherits(res, "try-error")) {
            err <- attr(res, "condition")
            msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
            nc_n_try <- nc_n_try + 1
            if (nc_n_try > n_max_retries) {
                stop(msg)
            }
            else {
                message(msg, "\nRETRYing...")
                Sys.sleep(1)
            }
        }
        else {
            nc_retry <- F
        }
    }
    i_req <- i_req + 1
}
debug: i_t_beg <- (i_req - 1) * n_t_per_req + 1
debug: i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
debug: t_req <- times_todo[c(i_t_beg, i_t_end)]
debug: t_req_str <- format_ISO8601(t_req, usetz = "Z")
debug: if (verbose) message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
debug: message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
Fetching request 1 of 1 (2010-01-01 to 2010-12-01) ~ 19:43:23 UTC
debug: ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
    0), nc)
debug: unlink(ncs0)
debug: nc_retry <- T
debug: nc_n_try <- 1
debug: n_max_retries
debug: while (nc_retry) {
    res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
        url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
            bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
        time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
    if (inherits(res, "try-error")) {
        err <- attr(res, "condition")
        msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
        nc_n_try <- nc_n_try + 1
        if (nc_n_try > n_max_retries) {
            stop(msg)
        }
        else {
            message(msg, "\nRETRYing...")
            Sys.sleep(1)
        }
    }
    else {
        nc_retry <- F
    }
}
debug: res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
    url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
        bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
    time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
debug: if (inherits(res, "try-error")) {
    err <- attr(res, "condition")
    msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
    nc_n_try <- nc_n_try + 1
    if (nc_n_try > n_max_retries) {
        stop(msg)
    }
    else {
        message(msg, "\nRETRYing...")
        Sys.sleep(1)
    }
} else {
    nc_retry <- F
}
debug: nc_retry <- F
debug: (while) nc_retry
debug: i_req <- i_req + 1
debug: (while) i_req <= n_reqs
debug: ncs <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size > 
    0), nc)
debug: r <- terra::rast(ncs)
debug: stopifnot(all(class(terra::time(r)) %in% c("POSIXct", "POSIXt")))
debug: idx <- dplyr::pull(dplyr::filter(dplyr::arrange(dplyr::tibble(idx = 1:terra::nlyr(r), 
    time = terra::time(r)), time), !duplicated(time)), idx)
debug: r <- terra::subset(r, idx)
debug: stopifnot(terra::crs(r, proj = T) == wgs84)
debug: if (mask_tif) r <- terra::mask(r, sf_zones)
debug: lyrs <- glue("{var}|{terra::time(r)}")
debug: if (length(dims_other) > 0 && !all(length(dims[dims_other]) == 
    1)) stop(glue("Other dimensions not yet supported: {paste(dims_other, collapse = ',')}"))
debug: names(r) <- lyrs
debug: if (!is.null(rast_tif)) {
    if (fs::file_exists(rast_tif)) {
        r_tmp_tif <- tempfile(fileext = ".tif")
        r_tmp <- c(rast(rast_tif), r)
        r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
        terra::writeRaster(r_tmp, r_tmp_tif)
        fs::file_delete(rast_tif)
        fs::file_move(r_tmp_tif, rast_tif)
        rm(r)
        rm(r_tmp)
    }
    else {
        terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
    }
    r <- terra::rast(rast_tif)
}
debug: if (fs::file_exists(rast_tif)) {
    r_tmp_tif <- tempfile(fileext = ".tif")
    r_tmp <- c(rast(rast_tif), r)
    r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
    terra::writeRaster(r_tmp, r_tmp_tif)
    fs::file_delete(rast_tif)
    fs::file_move(r_tmp_tif, rast_tif)
    rm(r)
    rm(r_tmp)
} else {
    terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
}
debug: terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
debug: r <- terra::rast(rast_tif)
debug: d_r <- mutate(tidyr::pivot_longer(sf::st_drop_geometry(sf::st_as_sf(terra::zonal(x = r, 
    z = terra::vect(dplyr::select(sf_zones, dplyr::all_of(fld_zones))), 
    fun = zonal_fun, exact = T, na.rm = T, as.polygons = T))), 
    cols = -dplyr::any_of(fld_zones), names_to = "lyr", values_to = zonal_fun), 
    time = readr::parse_datetime(str_replace(lyr, glue("{var}\\|(.*)"), 
        "\\1")))
debug: if (!is.null(zonal_csv)) write_csv(d_r, zonal_csv)
debug: write_csv(d_r, zonal_csv)
debug: if (!keep_nc) unlink(dir_nc, recursive = T)
debug: unlink(dir_nc, recursive = T)
debug: return(d_r)
Downloading 1 requests, up to 42 time slices each
Called from: extractr::ed_extract(ed, var = v, sf_zones = ply, bbox = bb, 
    mask_tif = F, rast_tif = glue("{dir_out}/{nms}/{yr}.tif"), 
    zonal_fun = "mean", zonal_csv = glue("{dir_out}/{nms}/{yr}.csv"), 
    dir_nc = glue("{dir_out}/{nms}/{yr}_nc"), keep_nc = F, n_max_vals_per_req = 1e+05, 
    time_min = time_min, time_max = time_max, verbose = T)
debug: while (i_req <= n_reqs) {
    i_t_beg <- (i_req - 1) * n_t_per_req + 1
    i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
    t_req <- times_todo[c(i_t_beg, i_t_end)]
    t_req_str <- format_ISO8601(t_req, usetz = "Z")
    if (verbose) 
        message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
    ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
        ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
        0), nc)
    unlink(ncs0)
    nc_retry <- T
    nc_n_try <- 1
    n_max_retries
    while (nc_retry) {
        res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
            url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
                bbox[["xmax"]]), latitude = c(bbox[["ymin"]], 
                bbox[["ymax"]]), time = t_req_str, fmt = "nc", 
            store = rerddap::disk(path = dir_nc)))
        if (inherits(res, "try-error")) {
            err <- attr(res, "condition")
            msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
            nc_n_try <- nc_n_try + 1
            if (nc_n_try > n_max_retries) {
                stop(msg)
            }
            else {
                message(msg, "\nRETRYing...")
                Sys.sleep(1)
            }
        }
        else {
            nc_retry <- F
        }
    }
    i_req <- i_req + 1
}
debug: i_t_beg <- (i_req - 1) * n_t_per_req + 1
debug: i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
debug: t_req <- times_todo[c(i_t_beg, i_t_end)]
debug: t_req_str <- format_ISO8601(t_req, usetz = "Z")
debug: if (verbose) message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
debug: message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
Fetching request 1 of 1 (2011-01-01 to 2011-12-01) ~ 19:43:26 UTC
debug: ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
    0), nc)
debug: unlink(ncs0)
debug: nc_retry <- T
debug: nc_n_try <- 1
debug: n_max_retries
debug: while (nc_retry) {
    res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
        url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
            bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
        time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
    if (inherits(res, "try-error")) {
        err <- attr(res, "condition")
        msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
        nc_n_try <- nc_n_try + 1
        if (nc_n_try > n_max_retries) {
            stop(msg)
        }
        else {
            message(msg, "\nRETRYing...")
            Sys.sleep(1)
        }
    }
    else {
        nc_retry <- F
    }
}
debug: res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
    url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
        bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
    time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
debug: if (inherits(res, "try-error")) {
    err <- attr(res, "condition")
    msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
    nc_n_try <- nc_n_try + 1
    if (nc_n_try > n_max_retries) {
        stop(msg)
    }
    else {
        message(msg, "\nRETRYing...")
        Sys.sleep(1)
    }
} else {
    nc_retry <- F
}
debug: nc_retry <- F
debug: (while) nc_retry
debug: i_req <- i_req + 1
debug: (while) i_req <= n_reqs
debug: ncs <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size > 
    0), nc)
debug: r <- terra::rast(ncs)
debug: stopifnot(all(class(terra::time(r)) %in% c("POSIXct", "POSIXt")))
debug: idx <- dplyr::pull(dplyr::filter(dplyr::arrange(dplyr::tibble(idx = 1:terra::nlyr(r), 
    time = terra::time(r)), time), !duplicated(time)), idx)
debug: r <- terra::subset(r, idx)
debug: stopifnot(terra::crs(r, proj = T) == wgs84)
debug: if (mask_tif) r <- terra::mask(r, sf_zones)
debug: lyrs <- glue("{var}|{terra::time(r)}")
debug: if (length(dims_other) > 0 && !all(length(dims[dims_other]) == 
    1)) stop(glue("Other dimensions not yet supported: {paste(dims_other, collapse = ',')}"))
debug: names(r) <- lyrs
debug: if (!is.null(rast_tif)) {
    if (fs::file_exists(rast_tif)) {
        r_tmp_tif <- tempfile(fileext = ".tif")
        r_tmp <- c(rast(rast_tif), r)
        r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
        terra::writeRaster(r_tmp, r_tmp_tif)
        fs::file_delete(rast_tif)
        fs::file_move(r_tmp_tif, rast_tif)
        rm(r)
        rm(r_tmp)
    }
    else {
        terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
    }
    r <- terra::rast(rast_tif)
}
debug: if (fs::file_exists(rast_tif)) {
    r_tmp_tif <- tempfile(fileext = ".tif")
    r_tmp <- c(rast(rast_tif), r)
    r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
    terra::writeRaster(r_tmp, r_tmp_tif)
    fs::file_delete(rast_tif)
    fs::file_move(r_tmp_tif, rast_tif)
    rm(r)
    rm(r_tmp)
} else {
    terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
}
debug: terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
debug: r <- terra::rast(rast_tif)
debug: d_r <- mutate(tidyr::pivot_longer(sf::st_drop_geometry(sf::st_as_sf(terra::zonal(x = r, 
    z = terra::vect(dplyr::select(sf_zones, dplyr::all_of(fld_zones))), 
    fun = zonal_fun, exact = T, na.rm = T, as.polygons = T))), 
    cols = -dplyr::any_of(fld_zones), names_to = "lyr", values_to = zonal_fun), 
    time = readr::parse_datetime(str_replace(lyr, glue("{var}\\|(.*)"), 
        "\\1")))
debug: if (!is.null(zonal_csv)) write_csv(d_r, zonal_csv)
debug: write_csv(d_r, zonal_csv)
debug: if (!keep_nc) unlink(dir_nc, recursive = T)
debug: unlink(dir_nc, recursive = T)
debug: return(d_r)
Downloading 1 requests, up to 42 time slices each
Called from: extractr::ed_extract(ed, var = v, sf_zones = ply, bbox = bb, 
    mask_tif = F, rast_tif = glue("{dir_out}/{nms}/{yr}.tif"), 
    zonal_fun = "mean", zonal_csv = glue("{dir_out}/{nms}/{yr}.csv"), 
    dir_nc = glue("{dir_out}/{nms}/{yr}_nc"), keep_nc = F, n_max_vals_per_req = 1e+05, 
    time_min = time_min, time_max = time_max, verbose = T)
debug: while (i_req <= n_reqs) {
    i_t_beg <- (i_req - 1) * n_t_per_req + 1
    i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
    t_req <- times_todo[c(i_t_beg, i_t_end)]
    t_req_str <- format_ISO8601(t_req, usetz = "Z")
    if (verbose) 
        message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
    ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
        ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
        0), nc)
    unlink(ncs0)
    nc_retry <- T
    nc_n_try <- 1
    n_max_retries
    while (nc_retry) {
        res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
            url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
                bbox[["xmax"]]), latitude = c(bbox[["ymin"]], 
                bbox[["ymax"]]), time = t_req_str, fmt = "nc", 
            store = rerddap::disk(path = dir_nc)))
        if (inherits(res, "try-error")) {
            err <- attr(res, "condition")
            msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
            nc_n_try <- nc_n_try + 1
            if (nc_n_try > n_max_retries) {
                stop(msg)
            }
            else {
                message(msg, "\nRETRYing...")
                Sys.sleep(1)
            }
        }
        else {
            nc_retry <- F
        }
    }
    i_req <- i_req + 1
}
debug: i_t_beg <- (i_req - 1) * n_t_per_req + 1
debug: i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
debug: t_req <- times_todo[c(i_t_beg, i_t_end)]
debug: t_req_str <- format_ISO8601(t_req, usetz = "Z")
debug: if (verbose) message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
debug: message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
Fetching request 1 of 1 (2012-01-01 to 2012-12-01) ~ 19:43:28 UTC
debug: ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
    0), nc)
debug: unlink(ncs0)
debug: nc_retry <- T
debug: nc_n_try <- 1
debug: n_max_retries
debug: while (nc_retry) {
    res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
        url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
            bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
        time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
    if (inherits(res, "try-error")) {
        err <- attr(res, "condition")
        msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
        nc_n_try <- nc_n_try + 1
        if (nc_n_try > n_max_retries) {
            stop(msg)
        }
        else {
            message(msg, "\nRETRYing...")
            Sys.sleep(1)
        }
    }
    else {
        nc_retry <- F
    }
}
debug: res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
    url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
        bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
    time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
debug: if (inherits(res, "try-error")) {
    err <- attr(res, "condition")
    msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
    nc_n_try <- nc_n_try + 1
    if (nc_n_try > n_max_retries) {
        stop(msg)
    }
    else {
        message(msg, "\nRETRYing...")
        Sys.sleep(1)
    }
} else {
    nc_retry <- F
}
debug: nc_retry <- F
debug: (while) nc_retry
debug: i_req <- i_req + 1
debug: (while) i_req <= n_reqs
debug: ncs <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size > 
    0), nc)
debug: r <- terra::rast(ncs)
debug: stopifnot(all(class(terra::time(r)) %in% c("POSIXct", "POSIXt")))
debug: idx <- dplyr::pull(dplyr::filter(dplyr::arrange(dplyr::tibble(idx = 1:terra::nlyr(r), 
    time = terra::time(r)), time), !duplicated(time)), idx)
debug: r <- terra::subset(r, idx)
debug: stopifnot(terra::crs(r, proj = T) == wgs84)
debug: if (mask_tif) r <- terra::mask(r, sf_zones)
debug: lyrs <- glue("{var}|{terra::time(r)}")
debug: if (length(dims_other) > 0 && !all(length(dims[dims_other]) == 
    1)) stop(glue("Other dimensions not yet supported: {paste(dims_other, collapse = ',')}"))
debug: names(r) <- lyrs
debug: if (!is.null(rast_tif)) {
    if (fs::file_exists(rast_tif)) {
        r_tmp_tif <- tempfile(fileext = ".tif")
        r_tmp <- c(rast(rast_tif), r)
        r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
        terra::writeRaster(r_tmp, r_tmp_tif)
        fs::file_delete(rast_tif)
        fs::file_move(r_tmp_tif, rast_tif)
        rm(r)
        rm(r_tmp)
    }
    else {
        terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
    }
    r <- terra::rast(rast_tif)
}
debug: if (fs::file_exists(rast_tif)) {
    r_tmp_tif <- tempfile(fileext = ".tif")
    r_tmp <- c(rast(rast_tif), r)
    r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
    terra::writeRaster(r_tmp, r_tmp_tif)
    fs::file_delete(rast_tif)
    fs::file_move(r_tmp_tif, rast_tif)
    rm(r)
    rm(r_tmp)
} else {
    terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
}
debug: terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
debug: r <- terra::rast(rast_tif)
debug: d_r <- mutate(tidyr::pivot_longer(sf::st_drop_geometry(sf::st_as_sf(terra::zonal(x = r, 
    z = terra::vect(dplyr::select(sf_zones, dplyr::all_of(fld_zones))), 
    fun = zonal_fun, exact = T, na.rm = T, as.polygons = T))), 
    cols = -dplyr::any_of(fld_zones), names_to = "lyr", values_to = zonal_fun), 
    time = readr::parse_datetime(str_replace(lyr, glue("{var}\\|(.*)"), 
        "\\1")))
debug: if (!is.null(zonal_csv)) write_csv(d_r, zonal_csv)
debug: write_csv(d_r, zonal_csv)
debug: if (!keep_nc) unlink(dir_nc, recursive = T)
debug: unlink(dir_nc, recursive = T)
debug: return(d_r)
Downloading 1 requests, up to 42 time slices each
Called from: extractr::ed_extract(ed, var = v, sf_zones = ply, bbox = bb, 
    mask_tif = F, rast_tif = glue("{dir_out}/{nms}/{yr}.tif"), 
    zonal_fun = "mean", zonal_csv = glue("{dir_out}/{nms}/{yr}.csv"), 
    dir_nc = glue("{dir_out}/{nms}/{yr}_nc"), keep_nc = F, n_max_vals_per_req = 1e+05, 
    time_min = time_min, time_max = time_max, verbose = T)
debug: while (i_req <= n_reqs) {
    i_t_beg <- (i_req - 1) * n_t_per_req + 1
    i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
    t_req <- times_todo[c(i_t_beg, i_t_end)]
    t_req_str <- format_ISO8601(t_req, usetz = "Z")
    if (verbose) 
        message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
    ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
        ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
        0), nc)
    unlink(ncs0)
    nc_retry <- T
    nc_n_try <- 1
    n_max_retries
    while (nc_retry) {
        res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
            url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
                bbox[["xmax"]]), latitude = c(bbox[["ymin"]], 
                bbox[["ymax"]]), time = t_req_str, fmt = "nc", 
            store = rerddap::disk(path = dir_nc)))
        if (inherits(res, "try-error")) {
            err <- attr(res, "condition")
            msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
            nc_n_try <- nc_n_try + 1
            if (nc_n_try > n_max_retries) {
                stop(msg)
            }
            else {
                message(msg, "\nRETRYing...")
                Sys.sleep(1)
            }
        }
        else {
            nc_retry <- F
        }
    }
    i_req <- i_req + 1
}
debug: i_t_beg <- (i_req - 1) * n_t_per_req + 1
debug: i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
debug: t_req <- times_todo[c(i_t_beg, i_t_end)]
debug: t_req_str <- format_ISO8601(t_req, usetz = "Z")
debug: if (verbose) message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
debug: message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
Fetching request 1 of 1 (2013-01-01 to 2013-12-01) ~ 19:43:30 UTC
debug: ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
    0), nc)
debug: unlink(ncs0)
debug: nc_retry <- T
debug: nc_n_try <- 1
debug: n_max_retries
debug: while (nc_retry) {
    res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
        url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
            bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
        time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
    if (inherits(res, "try-error")) {
        err <- attr(res, "condition")
        msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
        nc_n_try <- nc_n_try + 1
        if (nc_n_try > n_max_retries) {
            stop(msg)
        }
        else {
            message(msg, "\nRETRYing...")
            Sys.sleep(1)
        }
    }
    else {
        nc_retry <- F
    }
}
debug: res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
    url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
        bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
    time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
debug: if (inherits(res, "try-error")) {
    err <- attr(res, "condition")
    msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
    nc_n_try <- nc_n_try + 1
    if (nc_n_try > n_max_retries) {
        stop(msg)
    }
    else {
        message(msg, "\nRETRYing...")
        Sys.sleep(1)
    }
} else {
    nc_retry <- F
}
debug: nc_retry <- F
debug: (while) nc_retry
debug: i_req <- i_req + 1
debug: (while) i_req <= n_reqs
debug: ncs <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size > 
    0), nc)
debug: r <- terra::rast(ncs)
debug: stopifnot(all(class(terra::time(r)) %in% c("POSIXct", "POSIXt")))
debug: idx <- dplyr::pull(dplyr::filter(dplyr::arrange(dplyr::tibble(idx = 1:terra::nlyr(r), 
    time = terra::time(r)), time), !duplicated(time)), idx)
debug: r <- terra::subset(r, idx)
debug: stopifnot(terra::crs(r, proj = T) == wgs84)
debug: if (mask_tif) r <- terra::mask(r, sf_zones)
debug: lyrs <- glue("{var}|{terra::time(r)}")
debug: if (length(dims_other) > 0 && !all(length(dims[dims_other]) == 
    1)) stop(glue("Other dimensions not yet supported: {paste(dims_other, collapse = ',')}"))
debug: names(r) <- lyrs
debug: if (!is.null(rast_tif)) {
    if (fs::file_exists(rast_tif)) {
        r_tmp_tif <- tempfile(fileext = ".tif")
        r_tmp <- c(rast(rast_tif), r)
        r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
        terra::writeRaster(r_tmp, r_tmp_tif)
        fs::file_delete(rast_tif)
        fs::file_move(r_tmp_tif, rast_tif)
        rm(r)
        rm(r_tmp)
    }
    else {
        terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
    }
    r <- terra::rast(rast_tif)
}
debug: if (fs::file_exists(rast_tif)) {
    r_tmp_tif <- tempfile(fileext = ".tif")
    r_tmp <- c(rast(rast_tif), r)
    r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
    terra::writeRaster(r_tmp, r_tmp_tif)
    fs::file_delete(rast_tif)
    fs::file_move(r_tmp_tif, rast_tif)
    rm(r)
    rm(r_tmp)
} else {
    terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
}
debug: terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
debug: r <- terra::rast(rast_tif)
debug: d_r <- mutate(tidyr::pivot_longer(sf::st_drop_geometry(sf::st_as_sf(terra::zonal(x = r, 
    z = terra::vect(dplyr::select(sf_zones, dplyr::all_of(fld_zones))), 
    fun = zonal_fun, exact = T, na.rm = T, as.polygons = T))), 
    cols = -dplyr::any_of(fld_zones), names_to = "lyr", values_to = zonal_fun), 
    time = readr::parse_datetime(str_replace(lyr, glue("{var}\\|(.*)"), 
        "\\1")))
debug: if (!is.null(zonal_csv)) write_csv(d_r, zonal_csv)
debug: write_csv(d_r, zonal_csv)
debug: if (!keep_nc) unlink(dir_nc, recursive = T)
debug: unlink(dir_nc, recursive = T)
debug: return(d_r)
Downloading 1 requests, up to 42 time slices each
Called from: extractr::ed_extract(ed, var = v, sf_zones = ply, bbox = bb, 
    mask_tif = F, rast_tif = glue("{dir_out}/{nms}/{yr}.tif"), 
    zonal_fun = "mean", zonal_csv = glue("{dir_out}/{nms}/{yr}.csv"), 
    dir_nc = glue("{dir_out}/{nms}/{yr}_nc"), keep_nc = F, n_max_vals_per_req = 1e+05, 
    time_min = time_min, time_max = time_max, verbose = T)
debug: while (i_req <= n_reqs) {
    i_t_beg <- (i_req - 1) * n_t_per_req + 1
    i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
    t_req <- times_todo[c(i_t_beg, i_t_end)]
    t_req_str <- format_ISO8601(t_req, usetz = "Z")
    if (verbose) 
        message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
    ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
        ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
        0), nc)
    unlink(ncs0)
    nc_retry <- T
    nc_n_try <- 1
    n_max_retries
    while (nc_retry) {
        res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
            url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
                bbox[["xmax"]]), latitude = c(bbox[["ymin"]], 
                bbox[["ymax"]]), time = t_req_str, fmt = "nc", 
            store = rerddap::disk(path = dir_nc)))
        if (inherits(res, "try-error")) {
            err <- attr(res, "condition")
            msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
            nc_n_try <- nc_n_try + 1
            if (nc_n_try > n_max_retries) {
                stop(msg)
            }
            else {
                message(msg, "\nRETRYing...")
                Sys.sleep(1)
            }
        }
        else {
            nc_retry <- F
        }
    }
    i_req <- i_req + 1
}
debug: i_t_beg <- (i_req - 1) * n_t_per_req + 1
debug: i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
debug: t_req <- times_todo[c(i_t_beg, i_t_end)]
debug: t_req_str <- format_ISO8601(t_req, usetz = "Z")
debug: if (verbose) message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
debug: message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
Fetching request 1 of 1 (2014-01-01 to 2014-12-01) ~ 19:43:32 UTC
debug: ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
    0), nc)
debug: unlink(ncs0)
debug: nc_retry <- T
debug: nc_n_try <- 1
debug: n_max_retries
debug: while (nc_retry) {
    res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
        url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
            bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
        time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
    if (inherits(res, "try-error")) {
        err <- attr(res, "condition")
        msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
        nc_n_try <- nc_n_try + 1
        if (nc_n_try > n_max_retries) {
            stop(msg)
        }
        else {
            message(msg, "\nRETRYing...")
            Sys.sleep(1)
        }
    }
    else {
        nc_retry <- F
    }
}
debug: res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
    url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
        bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
    time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
debug: if (inherits(res, "try-error")) {
    err <- attr(res, "condition")
    msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
    nc_n_try <- nc_n_try + 1
    if (nc_n_try > n_max_retries) {
        stop(msg)
    }
    else {
        message(msg, "\nRETRYing...")
        Sys.sleep(1)
    }
} else {
    nc_retry <- F
}
debug: nc_retry <- F
debug: (while) nc_retry
debug: i_req <- i_req + 1
debug: (while) i_req <= n_reqs
debug: ncs <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size > 
    0), nc)
debug: r <- terra::rast(ncs)
debug: stopifnot(all(class(terra::time(r)) %in% c("POSIXct", "POSIXt")))
debug: idx <- dplyr::pull(dplyr::filter(dplyr::arrange(dplyr::tibble(idx = 1:terra::nlyr(r), 
    time = terra::time(r)), time), !duplicated(time)), idx)
debug: r <- terra::subset(r, idx)
debug: stopifnot(terra::crs(r, proj = T) == wgs84)
debug: if (mask_tif) r <- terra::mask(r, sf_zones)
debug: lyrs <- glue("{var}|{terra::time(r)}")
debug: if (length(dims_other) > 0 && !all(length(dims[dims_other]) == 
    1)) stop(glue("Other dimensions not yet supported: {paste(dims_other, collapse = ',')}"))
debug: names(r) <- lyrs
debug: if (!is.null(rast_tif)) {
    if (fs::file_exists(rast_tif)) {
        r_tmp_tif <- tempfile(fileext = ".tif")
        r_tmp <- c(rast(rast_tif), r)
        r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
        terra::writeRaster(r_tmp, r_tmp_tif)
        fs::file_delete(rast_tif)
        fs::file_move(r_tmp_tif, rast_tif)
        rm(r)
        rm(r_tmp)
    }
    else {
        terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
    }
    r <- terra::rast(rast_tif)
}
debug: if (fs::file_exists(rast_tif)) {
    r_tmp_tif <- tempfile(fileext = ".tif")
    r_tmp <- c(rast(rast_tif), r)
    r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
    terra::writeRaster(r_tmp, r_tmp_tif)
    fs::file_delete(rast_tif)
    fs::file_move(r_tmp_tif, rast_tif)
    rm(r)
    rm(r_tmp)
} else {
    terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
}
debug: terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
debug: r <- terra::rast(rast_tif)
debug: d_r <- mutate(tidyr::pivot_longer(sf::st_drop_geometry(sf::st_as_sf(terra::zonal(x = r, 
    z = terra::vect(dplyr::select(sf_zones, dplyr::all_of(fld_zones))), 
    fun = zonal_fun, exact = T, na.rm = T, as.polygons = T))), 
    cols = -dplyr::any_of(fld_zones), names_to = "lyr", values_to = zonal_fun), 
    time = readr::parse_datetime(str_replace(lyr, glue("{var}\\|(.*)"), 
        "\\1")))
debug: if (!is.null(zonal_csv)) write_csv(d_r, zonal_csv)
debug: write_csv(d_r, zonal_csv)
debug: if (!keep_nc) unlink(dir_nc, recursive = T)
debug: unlink(dir_nc, recursive = T)
debug: return(d_r)
Downloading 1 requests, up to 42 time slices each
Called from: extractr::ed_extract(ed, var = v, sf_zones = ply, bbox = bb, 
    mask_tif = F, rast_tif = glue("{dir_out}/{nms}/{yr}.tif"), 
    zonal_fun = "mean", zonal_csv = glue("{dir_out}/{nms}/{yr}.csv"), 
    dir_nc = glue("{dir_out}/{nms}/{yr}_nc"), keep_nc = F, n_max_vals_per_req = 1e+05, 
    time_min = time_min, time_max = time_max, verbose = T)
debug: while (i_req <= n_reqs) {
    i_t_beg <- (i_req - 1) * n_t_per_req + 1
    i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
    t_req <- times_todo[c(i_t_beg, i_t_end)]
    t_req_str <- format_ISO8601(t_req, usetz = "Z")
    if (verbose) 
        message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
    ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
        ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
        0), nc)
    unlink(ncs0)
    nc_retry <- T
    nc_n_try <- 1
    n_max_retries
    while (nc_retry) {
        res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
            url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
                bbox[["xmax"]]), latitude = c(bbox[["ymin"]], 
                bbox[["ymax"]]), time = t_req_str, fmt = "nc", 
            store = rerddap::disk(path = dir_nc)))
        if (inherits(res, "try-error")) {
            err <- attr(res, "condition")
            msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
            nc_n_try <- nc_n_try + 1
            if (nc_n_try > n_max_retries) {
                stop(msg)
            }
            else {
                message(msg, "\nRETRYing...")
                Sys.sleep(1)
            }
        }
        else {
            nc_retry <- F
        }
    }
    i_req <- i_req + 1
}
debug: i_t_beg <- (i_req - 1) * n_t_per_req + 1
debug: i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
debug: t_req <- times_todo[c(i_t_beg, i_t_end)]
debug: t_req_str <- format_ISO8601(t_req, usetz = "Z")
debug: if (verbose) message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
debug: message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
Fetching request 1 of 1 (2015-01-01 to 2015-12-01) ~ 19:43:34 UTC
debug: ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
    0), nc)
debug: unlink(ncs0)
debug: nc_retry <- T
debug: nc_n_try <- 1
debug: n_max_retries
debug: while (nc_retry) {
    res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
        url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
            bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
        time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
    if (inherits(res, "try-error")) {
        err <- attr(res, "condition")
        msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
        nc_n_try <- nc_n_try + 1
        if (nc_n_try > n_max_retries) {
            stop(msg)
        }
        else {
            message(msg, "\nRETRYing...")
            Sys.sleep(1)
        }
    }
    else {
        nc_retry <- F
    }
}
debug: res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
    url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
        bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
    time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
debug: if (inherits(res, "try-error")) {
    err <- attr(res, "condition")
    msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
    nc_n_try <- nc_n_try + 1
    if (nc_n_try > n_max_retries) {
        stop(msg)
    }
    else {
        message(msg, "\nRETRYing...")
        Sys.sleep(1)
    }
} else {
    nc_retry <- F
}
debug: nc_retry <- F
debug: (while) nc_retry
debug: i_req <- i_req + 1
debug: (while) i_req <= n_reqs
debug: ncs <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size > 
    0), nc)
debug: r <- terra::rast(ncs)
debug: stopifnot(all(class(terra::time(r)) %in% c("POSIXct", "POSIXt")))
debug: idx <- dplyr::pull(dplyr::filter(dplyr::arrange(dplyr::tibble(idx = 1:terra::nlyr(r), 
    time = terra::time(r)), time), !duplicated(time)), idx)
debug: r <- terra::subset(r, idx)
debug: stopifnot(terra::crs(r, proj = T) == wgs84)
debug: if (mask_tif) r <- terra::mask(r, sf_zones)
debug: lyrs <- glue("{var}|{terra::time(r)}")
debug: if (length(dims_other) > 0 && !all(length(dims[dims_other]) == 
    1)) stop(glue("Other dimensions not yet supported: {paste(dims_other, collapse = ',')}"))
debug: names(r) <- lyrs
debug: if (!is.null(rast_tif)) {
    if (fs::file_exists(rast_tif)) {
        r_tmp_tif <- tempfile(fileext = ".tif")
        r_tmp <- c(rast(rast_tif), r)
        r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
        terra::writeRaster(r_tmp, r_tmp_tif)
        fs::file_delete(rast_tif)
        fs::file_move(r_tmp_tif, rast_tif)
        rm(r)
        rm(r_tmp)
    }
    else {
        terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
    }
    r <- terra::rast(rast_tif)
}
debug: if (fs::file_exists(rast_tif)) {
    r_tmp_tif <- tempfile(fileext = ".tif")
    r_tmp <- c(rast(rast_tif), r)
    r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
    terra::writeRaster(r_tmp, r_tmp_tif)
    fs::file_delete(rast_tif)
    fs::file_move(r_tmp_tif, rast_tif)
    rm(r)
    rm(r_tmp)
} else {
    terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
}
debug: terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
debug: r <- terra::rast(rast_tif)
debug: d_r <- mutate(tidyr::pivot_longer(sf::st_drop_geometry(sf::st_as_sf(terra::zonal(x = r, 
    z = terra::vect(dplyr::select(sf_zones, dplyr::all_of(fld_zones))), 
    fun = zonal_fun, exact = T, na.rm = T, as.polygons = T))), 
    cols = -dplyr::any_of(fld_zones), names_to = "lyr", values_to = zonal_fun), 
    time = readr::parse_datetime(str_replace(lyr, glue("{var}\\|(.*)"), 
        "\\1")))
debug: if (!is.null(zonal_csv)) write_csv(d_r, zonal_csv)
debug: write_csv(d_r, zonal_csv)
debug: if (!keep_nc) unlink(dir_nc, recursive = T)
debug: unlink(dir_nc, recursive = T)
debug: return(d_r)
Downloading 1 requests, up to 42 time slices each
Called from: extractr::ed_extract(ed, var = v, sf_zones = ply, bbox = bb, 
    mask_tif = F, rast_tif = glue("{dir_out}/{nms}/{yr}.tif"), 
    zonal_fun = "mean", zonal_csv = glue("{dir_out}/{nms}/{yr}.csv"), 
    dir_nc = glue("{dir_out}/{nms}/{yr}_nc"), keep_nc = F, n_max_vals_per_req = 1e+05, 
    time_min = time_min, time_max = time_max, verbose = T)
debug: while (i_req <= n_reqs) {
    i_t_beg <- (i_req - 1) * n_t_per_req + 1
    i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
    t_req <- times_todo[c(i_t_beg, i_t_end)]
    t_req_str <- format_ISO8601(t_req, usetz = "Z")
    if (verbose) 
        message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
    ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
        ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
        0), nc)
    unlink(ncs0)
    nc_retry <- T
    nc_n_try <- 1
    n_max_retries
    while (nc_retry) {
        res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
            url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
                bbox[["xmax"]]), latitude = c(bbox[["ymin"]], 
                bbox[["ymax"]]), time = t_req_str, fmt = "nc", 
            store = rerddap::disk(path = dir_nc)))
        if (inherits(res, "try-error")) {
            err <- attr(res, "condition")
            msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
            nc_n_try <- nc_n_try + 1
            if (nc_n_try > n_max_retries) {
                stop(msg)
            }
            else {
                message(msg, "\nRETRYing...")
                Sys.sleep(1)
            }
        }
        else {
            nc_retry <- F
        }
    }
    i_req <- i_req + 1
}
debug: i_t_beg <- (i_req - 1) * n_t_per_req + 1
debug: i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
debug: t_req <- times_todo[c(i_t_beg, i_t_end)]
debug: t_req_str <- format_ISO8601(t_req, usetz = "Z")
debug: if (verbose) message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
debug: message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
Fetching request 1 of 1 (2016-01-01 to 2016-12-01) ~ 19:43:36 UTC
debug: ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
    0), nc)
debug: unlink(ncs0)
debug: nc_retry <- T
debug: nc_n_try <- 1
debug: n_max_retries
debug: while (nc_retry) {
    res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
        url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
            bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
        time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
    if (inherits(res, "try-error")) {
        err <- attr(res, "condition")
        msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
        nc_n_try <- nc_n_try + 1
        if (nc_n_try > n_max_retries) {
            stop(msg)
        }
        else {
            message(msg, "\nRETRYing...")
            Sys.sleep(1)
        }
    }
    else {
        nc_retry <- F
    }
}
debug: res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
    url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
        bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
    time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
debug: if (inherits(res, "try-error")) {
    err <- attr(res, "condition")
    msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
    nc_n_try <- nc_n_try + 1
    if (nc_n_try > n_max_retries) {
        stop(msg)
    }
    else {
        message(msg, "\nRETRYing...")
        Sys.sleep(1)
    }
} else {
    nc_retry <- F
}
debug: nc_retry <- F
debug: (while) nc_retry
debug: i_req <- i_req + 1
debug: (while) i_req <= n_reqs
debug: ncs <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size > 
    0), nc)
debug: r <- terra::rast(ncs)
debug: stopifnot(all(class(terra::time(r)) %in% c("POSIXct", "POSIXt")))
debug: idx <- dplyr::pull(dplyr::filter(dplyr::arrange(dplyr::tibble(idx = 1:terra::nlyr(r), 
    time = terra::time(r)), time), !duplicated(time)), idx)
debug: r <- terra::subset(r, idx)
debug: stopifnot(terra::crs(r, proj = T) == wgs84)
debug: if (mask_tif) r <- terra::mask(r, sf_zones)
debug: lyrs <- glue("{var}|{terra::time(r)}")
debug: if (length(dims_other) > 0 && !all(length(dims[dims_other]) == 
    1)) stop(glue("Other dimensions not yet supported: {paste(dims_other, collapse = ',')}"))
debug: names(r) <- lyrs
debug: if (!is.null(rast_tif)) {
    if (fs::file_exists(rast_tif)) {
        r_tmp_tif <- tempfile(fileext = ".tif")
        r_tmp <- c(rast(rast_tif), r)
        r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
        terra::writeRaster(r_tmp, r_tmp_tif)
        fs::file_delete(rast_tif)
        fs::file_move(r_tmp_tif, rast_tif)
        rm(r)
        rm(r_tmp)
    }
    else {
        terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
    }
    r <- terra::rast(rast_tif)
}
debug: if (fs::file_exists(rast_tif)) {
    r_tmp_tif <- tempfile(fileext = ".tif")
    r_tmp <- c(rast(rast_tif), r)
    r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
    terra::writeRaster(r_tmp, r_tmp_tif)
    fs::file_delete(rast_tif)
    fs::file_move(r_tmp_tif, rast_tif)
    rm(r)
    rm(r_tmp)
} else {
    terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
}
debug: terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
debug: r <- terra::rast(rast_tif)
debug: d_r <- mutate(tidyr::pivot_longer(sf::st_drop_geometry(sf::st_as_sf(terra::zonal(x = r, 
    z = terra::vect(dplyr::select(sf_zones, dplyr::all_of(fld_zones))), 
    fun = zonal_fun, exact = T, na.rm = T, as.polygons = T))), 
    cols = -dplyr::any_of(fld_zones), names_to = "lyr", values_to = zonal_fun), 
    time = readr::parse_datetime(str_replace(lyr, glue("{var}\\|(.*)"), 
        "\\1")))
debug: if (!is.null(zonal_csv)) write_csv(d_r, zonal_csv)
debug: write_csv(d_r, zonal_csv)
debug: if (!keep_nc) unlink(dir_nc, recursive = T)
debug: unlink(dir_nc, recursive = T)
debug: return(d_r)
Downloading 1 requests, up to 42 time slices each
Called from: extractr::ed_extract(ed, var = v, sf_zones = ply, bbox = bb, 
    mask_tif = F, rast_tif = glue("{dir_out}/{nms}/{yr}.tif"), 
    zonal_fun = "mean", zonal_csv = glue("{dir_out}/{nms}/{yr}.csv"), 
    dir_nc = glue("{dir_out}/{nms}/{yr}_nc"), keep_nc = F, n_max_vals_per_req = 1e+05, 
    time_min = time_min, time_max = time_max, verbose = T)
debug: while (i_req <= n_reqs) {
    i_t_beg <- (i_req - 1) * n_t_per_req + 1
    i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
    t_req <- times_todo[c(i_t_beg, i_t_end)]
    t_req_str <- format_ISO8601(t_req, usetz = "Z")
    if (verbose) 
        message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
    ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
        ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
        0), nc)
    unlink(ncs0)
    nc_retry <- T
    nc_n_try <- 1
    n_max_retries
    while (nc_retry) {
        res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
            url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
                bbox[["xmax"]]), latitude = c(bbox[["ymin"]], 
                bbox[["ymax"]]), time = t_req_str, fmt = "nc", 
            store = rerddap::disk(path = dir_nc)))
        if (inherits(res, "try-error")) {
            err <- attr(res, "condition")
            msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
            nc_n_try <- nc_n_try + 1
            if (nc_n_try > n_max_retries) {
                stop(msg)
            }
            else {
                message(msg, "\nRETRYing...")
                Sys.sleep(1)
            }
        }
        else {
            nc_retry <- F
        }
    }
    i_req <- i_req + 1
}
debug: i_t_beg <- (i_req - 1) * n_t_per_req + 1
debug: i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
debug: t_req <- times_todo[c(i_t_beg, i_t_end)]
debug: t_req_str <- format_ISO8601(t_req, usetz = "Z")
debug: if (verbose) message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
debug: message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
Fetching request 1 of 1 (2017-01-01 to 2017-12-01) ~ 19:43:38 UTC
debug: ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
    0), nc)
debug: unlink(ncs0)
debug: nc_retry <- T
debug: nc_n_try <- 1
debug: n_max_retries
debug: while (nc_retry) {
    res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
        url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
            bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
        time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
    if (inherits(res, "try-error")) {
        err <- attr(res, "condition")
        msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
        nc_n_try <- nc_n_try + 1
        if (nc_n_try > n_max_retries) {
            stop(msg)
        }
        else {
            message(msg, "\nRETRYing...")
            Sys.sleep(1)
        }
    }
    else {
        nc_retry <- F
    }
}
debug: res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
    url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
        bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
    time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
debug: if (inherits(res, "try-error")) {
    err <- attr(res, "condition")
    msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
    nc_n_try <- nc_n_try + 1
    if (nc_n_try > n_max_retries) {
        stop(msg)
    }
    else {
        message(msg, "\nRETRYing...")
        Sys.sleep(1)
    }
} else {
    nc_retry <- F
}
debug: nc_retry <- F
debug: (while) nc_retry
debug: i_req <- i_req + 1
debug: (while) i_req <= n_reqs
debug: ncs <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size > 
    0), nc)
debug: r <- terra::rast(ncs)
debug: stopifnot(all(class(terra::time(r)) %in% c("POSIXct", "POSIXt")))
debug: idx <- dplyr::pull(dplyr::filter(dplyr::arrange(dplyr::tibble(idx = 1:terra::nlyr(r), 
    time = terra::time(r)), time), !duplicated(time)), idx)
debug: r <- terra::subset(r, idx)
debug: stopifnot(terra::crs(r, proj = T) == wgs84)
debug: if (mask_tif) r <- terra::mask(r, sf_zones)
debug: lyrs <- glue("{var}|{terra::time(r)}")
debug: if (length(dims_other) > 0 && !all(length(dims[dims_other]) == 
    1)) stop(glue("Other dimensions not yet supported: {paste(dims_other, collapse = ',')}"))
debug: names(r) <- lyrs
debug: if (!is.null(rast_tif)) {
    if (fs::file_exists(rast_tif)) {
        r_tmp_tif <- tempfile(fileext = ".tif")
        r_tmp <- c(rast(rast_tif), r)
        r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
        terra::writeRaster(r_tmp, r_tmp_tif)
        fs::file_delete(rast_tif)
        fs::file_move(r_tmp_tif, rast_tif)
        rm(r)
        rm(r_tmp)
    }
    else {
        terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
    }
    r <- terra::rast(rast_tif)
}
debug: if (fs::file_exists(rast_tif)) {
    r_tmp_tif <- tempfile(fileext = ".tif")
    r_tmp <- c(rast(rast_tif), r)
    r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
    terra::writeRaster(r_tmp, r_tmp_tif)
    fs::file_delete(rast_tif)
    fs::file_move(r_tmp_tif, rast_tif)
    rm(r)
    rm(r_tmp)
} else {
    terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
}
debug: terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
debug: r <- terra::rast(rast_tif)
debug: d_r <- mutate(tidyr::pivot_longer(sf::st_drop_geometry(sf::st_as_sf(terra::zonal(x = r, 
    z = terra::vect(dplyr::select(sf_zones, dplyr::all_of(fld_zones))), 
    fun = zonal_fun, exact = T, na.rm = T, as.polygons = T))), 
    cols = -dplyr::any_of(fld_zones), names_to = "lyr", values_to = zonal_fun), 
    time = readr::parse_datetime(str_replace(lyr, glue("{var}\\|(.*)"), 
        "\\1")))
debug: if (!is.null(zonal_csv)) write_csv(d_r, zonal_csv)
debug: write_csv(d_r, zonal_csv)
debug: if (!keep_nc) unlink(dir_nc, recursive = T)
debug: unlink(dir_nc, recursive = T)
debug: return(d_r)
Downloading 1 requests, up to 42 time slices each
Called from: extractr::ed_extract(ed, var = v, sf_zones = ply, bbox = bb, 
    mask_tif = F, rast_tif = glue("{dir_out}/{nms}/{yr}.tif"), 
    zonal_fun = "mean", zonal_csv = glue("{dir_out}/{nms}/{yr}.csv"), 
    dir_nc = glue("{dir_out}/{nms}/{yr}_nc"), keep_nc = F, n_max_vals_per_req = 1e+05, 
    time_min = time_min, time_max = time_max, verbose = T)
debug: while (i_req <= n_reqs) {
    i_t_beg <- (i_req - 1) * n_t_per_req + 1
    i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
    t_req <- times_todo[c(i_t_beg, i_t_end)]
    t_req_str <- format_ISO8601(t_req, usetz = "Z")
    if (verbose) 
        message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
    ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
        ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
        0), nc)
    unlink(ncs0)
    nc_retry <- T
    nc_n_try <- 1
    n_max_retries
    while (nc_retry) {
        res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
            url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
                bbox[["xmax"]]), latitude = c(bbox[["ymin"]], 
                bbox[["ymax"]]), time = t_req_str, fmt = "nc", 
            store = rerddap::disk(path = dir_nc)))
        if (inherits(res, "try-error")) {
            err <- attr(res, "condition")
            msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
            nc_n_try <- nc_n_try + 1
            if (nc_n_try > n_max_retries) {
                stop(msg)
            }
            else {
                message(msg, "\nRETRYing...")
                Sys.sleep(1)
            }
        }
        else {
            nc_retry <- F
        }
    }
    i_req <- i_req + 1
}
debug: i_t_beg <- (i_req - 1) * n_t_per_req + 1
debug: i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
debug: t_req <- times_todo[c(i_t_beg, i_t_end)]
debug: t_req_str <- format_ISO8601(t_req, usetz = "Z")
debug: if (verbose) message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
debug: message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
Fetching request 1 of 1 (2018-01-01 to 2018-12-01) ~ 19:43:40 UTC
debug: ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
    0), nc)
debug: unlink(ncs0)
debug: nc_retry <- T
debug: nc_n_try <- 1
debug: n_max_retries
debug: while (nc_retry) {
    res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
        url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
            bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
        time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
    if (inherits(res, "try-error")) {
        err <- attr(res, "condition")
        msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
        nc_n_try <- nc_n_try + 1
        if (nc_n_try > n_max_retries) {
            stop(msg)
        }
        else {
            message(msg, "\nRETRYing...")
            Sys.sleep(1)
        }
    }
    else {
        nc_retry <- F
    }
}
debug: res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
    url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
        bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
    time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
debug: if (inherits(res, "try-error")) {
    err <- attr(res, "condition")
    msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
    nc_n_try <- nc_n_try + 1
    if (nc_n_try > n_max_retries) {
        stop(msg)
    }
    else {
        message(msg, "\nRETRYing...")
        Sys.sleep(1)
    }
} else {
    nc_retry <- F
}
debug: nc_retry <- F
debug: (while) nc_retry
debug: i_req <- i_req + 1
debug: (while) i_req <= n_reqs
debug: ncs <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size > 
    0), nc)
debug: r <- terra::rast(ncs)
debug: stopifnot(all(class(terra::time(r)) %in% c("POSIXct", "POSIXt")))
debug: idx <- dplyr::pull(dplyr::filter(dplyr::arrange(dplyr::tibble(idx = 1:terra::nlyr(r), 
    time = terra::time(r)), time), !duplicated(time)), idx)
debug: r <- terra::subset(r, idx)
debug: stopifnot(terra::crs(r, proj = T) == wgs84)
debug: if (mask_tif) r <- terra::mask(r, sf_zones)
debug: lyrs <- glue("{var}|{terra::time(r)}")
debug: if (length(dims_other) > 0 && !all(length(dims[dims_other]) == 
    1)) stop(glue("Other dimensions not yet supported: {paste(dims_other, collapse = ',')}"))
debug: names(r) <- lyrs
debug: if (!is.null(rast_tif)) {
    if (fs::file_exists(rast_tif)) {
        r_tmp_tif <- tempfile(fileext = ".tif")
        r_tmp <- c(rast(rast_tif), r)
        r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
        terra::writeRaster(r_tmp, r_tmp_tif)
        fs::file_delete(rast_tif)
        fs::file_move(r_tmp_tif, rast_tif)
        rm(r)
        rm(r_tmp)
    }
    else {
        terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
    }
    r <- terra::rast(rast_tif)
}
debug: if (fs::file_exists(rast_tif)) {
    r_tmp_tif <- tempfile(fileext = ".tif")
    r_tmp <- c(rast(rast_tif), r)
    r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
    terra::writeRaster(r_tmp, r_tmp_tif)
    fs::file_delete(rast_tif)
    fs::file_move(r_tmp_tif, rast_tif)
    rm(r)
    rm(r_tmp)
} else {
    terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
}
debug: terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
debug: r <- terra::rast(rast_tif)
debug: d_r <- mutate(tidyr::pivot_longer(sf::st_drop_geometry(sf::st_as_sf(terra::zonal(x = r, 
    z = terra::vect(dplyr::select(sf_zones, dplyr::all_of(fld_zones))), 
    fun = zonal_fun, exact = T, na.rm = T, as.polygons = T))), 
    cols = -dplyr::any_of(fld_zones), names_to = "lyr", values_to = zonal_fun), 
    time = readr::parse_datetime(str_replace(lyr, glue("{var}\\|(.*)"), 
        "\\1")))
debug: if (!is.null(zonal_csv)) write_csv(d_r, zonal_csv)
debug: write_csv(d_r, zonal_csv)
debug: if (!keep_nc) unlink(dir_nc, recursive = T)
debug: unlink(dir_nc, recursive = T)
debug: return(d_r)
Downloading 1 requests, up to 42 time slices each
Called from: extractr::ed_extract(ed, var = v, sf_zones = ply, bbox = bb, 
    mask_tif = F, rast_tif = glue("{dir_out}/{nms}/{yr}.tif"), 
    zonal_fun = "mean", zonal_csv = glue("{dir_out}/{nms}/{yr}.csv"), 
    dir_nc = glue("{dir_out}/{nms}/{yr}_nc"), keep_nc = F, n_max_vals_per_req = 1e+05, 
    time_min = time_min, time_max = time_max, verbose = T)
debug: while (i_req <= n_reqs) {
    i_t_beg <- (i_req - 1) * n_t_per_req + 1
    i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
    t_req <- times_todo[c(i_t_beg, i_t_end)]
    t_req_str <- format_ISO8601(t_req, usetz = "Z")
    if (verbose) 
        message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
    ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
        ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
        0), nc)
    unlink(ncs0)
    nc_retry <- T
    nc_n_try <- 1
    n_max_retries
    while (nc_retry) {
        res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
            url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
                bbox[["xmax"]]), latitude = c(bbox[["ymin"]], 
                bbox[["ymax"]]), time = t_req_str, fmt = "nc", 
            store = rerddap::disk(path = dir_nc)))
        if (inherits(res, "try-error")) {
            err <- attr(res, "condition")
            msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
            nc_n_try <- nc_n_try + 1
            if (nc_n_try > n_max_retries) {
                stop(msg)
            }
            else {
                message(msg, "\nRETRYing...")
                Sys.sleep(1)
            }
        }
        else {
            nc_retry <- F
        }
    }
    i_req <- i_req + 1
}
debug: i_t_beg <- (i_req - 1) * n_t_per_req + 1
debug: i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
debug: t_req <- times_todo[c(i_t_beg, i_t_end)]
debug: t_req_str <- format_ISO8601(t_req, usetz = "Z")
debug: if (verbose) message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
debug: message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
Fetching request 1 of 1 (2019-01-01 to 2019-12-01) ~ 19:43:42 UTC
debug: ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
    0), nc)
debug: unlink(ncs0)
debug: nc_retry <- T
debug: nc_n_try <- 1
debug: n_max_retries
debug: while (nc_retry) {
    res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
        url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
            bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
        time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
    if (inherits(res, "try-error")) {
        err <- attr(res, "condition")
        msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
        nc_n_try <- nc_n_try + 1
        if (nc_n_try > n_max_retries) {
            stop(msg)
        }
        else {
            message(msg, "\nRETRYing...")
            Sys.sleep(1)
        }
    }
    else {
        nc_retry <- F
    }
}
debug: res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
    url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
        bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
    time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
debug: if (inherits(res, "try-error")) {
    err <- attr(res, "condition")
    msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
    nc_n_try <- nc_n_try + 1
    if (nc_n_try > n_max_retries) {
        stop(msg)
    }
    else {
        message(msg, "\nRETRYing...")
        Sys.sleep(1)
    }
} else {
    nc_retry <- F
}
debug: nc_retry <- F
debug: (while) nc_retry
debug: i_req <- i_req + 1
debug: (while) i_req <= n_reqs
debug: ncs <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size > 
    0), nc)
debug: r <- terra::rast(ncs)
debug: stopifnot(all(class(terra::time(r)) %in% c("POSIXct", "POSIXt")))
debug: idx <- dplyr::pull(dplyr::filter(dplyr::arrange(dplyr::tibble(idx = 1:terra::nlyr(r), 
    time = terra::time(r)), time), !duplicated(time)), idx)
debug: r <- terra::subset(r, idx)
debug: stopifnot(terra::crs(r, proj = T) == wgs84)
debug: if (mask_tif) r <- terra::mask(r, sf_zones)
debug: lyrs <- glue("{var}|{terra::time(r)}")
debug: if (length(dims_other) > 0 && !all(length(dims[dims_other]) == 
    1)) stop(glue("Other dimensions not yet supported: {paste(dims_other, collapse = ',')}"))
debug: names(r) <- lyrs
debug: if (!is.null(rast_tif)) {
    if (fs::file_exists(rast_tif)) {
        r_tmp_tif <- tempfile(fileext = ".tif")
        r_tmp <- c(rast(rast_tif), r)
        r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
        terra::writeRaster(r_tmp, r_tmp_tif)
        fs::file_delete(rast_tif)
        fs::file_move(r_tmp_tif, rast_tif)
        rm(r)
        rm(r_tmp)
    }
    else {
        terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
    }
    r <- terra::rast(rast_tif)
}
debug: if (fs::file_exists(rast_tif)) {
    r_tmp_tif <- tempfile(fileext = ".tif")
    r_tmp <- c(rast(rast_tif), r)
    r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
    terra::writeRaster(r_tmp, r_tmp_tif)
    fs::file_delete(rast_tif)
    fs::file_move(r_tmp_tif, rast_tif)
    rm(r)
    rm(r_tmp)
} else {
    terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
}
debug: terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
debug: r <- terra::rast(rast_tif)
debug: d_r <- mutate(tidyr::pivot_longer(sf::st_drop_geometry(sf::st_as_sf(terra::zonal(x = r, 
    z = terra::vect(dplyr::select(sf_zones, dplyr::all_of(fld_zones))), 
    fun = zonal_fun, exact = T, na.rm = T, as.polygons = T))), 
    cols = -dplyr::any_of(fld_zones), names_to = "lyr", values_to = zonal_fun), 
    time = readr::parse_datetime(str_replace(lyr, glue("{var}\\|(.*)"), 
        "\\1")))
debug: if (!is.null(zonal_csv)) write_csv(d_r, zonal_csv)
debug: write_csv(d_r, zonal_csv)
debug: if (!keep_nc) unlink(dir_nc, recursive = T)
debug: unlink(dir_nc, recursive = T)
debug: return(d_r)
Downloading 1 requests, up to 42 time slices each
Called from: extractr::ed_extract(ed, var = v, sf_zones = ply, bbox = bb, 
    mask_tif = F, rast_tif = glue("{dir_out}/{nms}/{yr}.tif"), 
    zonal_fun = "mean", zonal_csv = glue("{dir_out}/{nms}/{yr}.csv"), 
    dir_nc = glue("{dir_out}/{nms}/{yr}_nc"), keep_nc = F, n_max_vals_per_req = 1e+05, 
    time_min = time_min, time_max = time_max, verbose = T)
debug: while (i_req <= n_reqs) {
    i_t_beg <- (i_req - 1) * n_t_per_req + 1
    i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
    t_req <- times_todo[c(i_t_beg, i_t_end)]
    t_req_str <- format_ISO8601(t_req, usetz = "Z")
    if (verbose) 
        message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
    ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
        ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
        0), nc)
    unlink(ncs0)
    nc_retry <- T
    nc_n_try <- 1
    n_max_retries
    while (nc_retry) {
        res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
            url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
                bbox[["xmax"]]), latitude = c(bbox[["ymin"]], 
                bbox[["ymax"]]), time = t_req_str, fmt = "nc", 
            store = rerddap::disk(path = dir_nc)))
        if (inherits(res, "try-error")) {
            err <- attr(res, "condition")
            msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
            nc_n_try <- nc_n_try + 1
            if (nc_n_try > n_max_retries) {
                stop(msg)
            }
            else {
                message(msg, "\nRETRYing...")
                Sys.sleep(1)
            }
        }
        else {
            nc_retry <- F
        }
    }
    i_req <- i_req + 1
}
debug: i_t_beg <- (i_req - 1) * n_t_per_req + 1
debug: i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
debug: t_req <- times_todo[c(i_t_beg, i_t_end)]
debug: t_req_str <- format_ISO8601(t_req, usetz = "Z")
debug: if (verbose) message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
debug: message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
Fetching request 1 of 1 (2020-01-01 to 2020-12-01) ~ 19:43:44 UTC
debug: ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
    0), nc)
debug: unlink(ncs0)
debug: nc_retry <- T
debug: nc_n_try <- 1
debug: n_max_retries
debug: while (nc_retry) {
    res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
        url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
            bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
        time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
    if (inherits(res, "try-error")) {
        err <- attr(res, "condition")
        msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
        nc_n_try <- nc_n_try + 1
        if (nc_n_try > n_max_retries) {
            stop(msg)
        }
        else {
            message(msg, "\nRETRYing...")
            Sys.sleep(1)
        }
    }
    else {
        nc_retry <- F
    }
}
debug: res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
    url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
        bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
    time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
debug: if (inherits(res, "try-error")) {
    err <- attr(res, "condition")
    msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
    nc_n_try <- nc_n_try + 1
    if (nc_n_try > n_max_retries) {
        stop(msg)
    }
    else {
        message(msg, "\nRETRYing...")
        Sys.sleep(1)
    }
} else {
    nc_retry <- F
}
debug: nc_retry <- F
debug: (while) nc_retry
debug: i_req <- i_req + 1
debug: (while) i_req <= n_reqs
debug: ncs <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size > 
    0), nc)
debug: r <- terra::rast(ncs)
debug: stopifnot(all(class(terra::time(r)) %in% c("POSIXct", "POSIXt")))
debug: idx <- dplyr::pull(dplyr::filter(dplyr::arrange(dplyr::tibble(idx = 1:terra::nlyr(r), 
    time = terra::time(r)), time), !duplicated(time)), idx)
debug: r <- terra::subset(r, idx)
debug: stopifnot(terra::crs(r, proj = T) == wgs84)
debug: if (mask_tif) r <- terra::mask(r, sf_zones)
debug: lyrs <- glue("{var}|{terra::time(r)}")
debug: if (length(dims_other) > 0 && !all(length(dims[dims_other]) == 
    1)) stop(glue("Other dimensions not yet supported: {paste(dims_other, collapse = ',')}"))
debug: names(r) <- lyrs
debug: if (!is.null(rast_tif)) {
    if (fs::file_exists(rast_tif)) {
        r_tmp_tif <- tempfile(fileext = ".tif")
        r_tmp <- c(rast(rast_tif), r)
        r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
        terra::writeRaster(r_tmp, r_tmp_tif)
        fs::file_delete(rast_tif)
        fs::file_move(r_tmp_tif, rast_tif)
        rm(r)
        rm(r_tmp)
    }
    else {
        terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
    }
    r <- terra::rast(rast_tif)
}
debug: if (fs::file_exists(rast_tif)) {
    r_tmp_tif <- tempfile(fileext = ".tif")
    r_tmp <- c(rast(rast_tif), r)
    r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
    terra::writeRaster(r_tmp, r_tmp_tif)
    fs::file_delete(rast_tif)
    fs::file_move(r_tmp_tif, rast_tif)
    rm(r)
    rm(r_tmp)
} else {
    terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
}
debug: terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
debug: r <- terra::rast(rast_tif)
debug: d_r <- mutate(tidyr::pivot_longer(sf::st_drop_geometry(sf::st_as_sf(terra::zonal(x = r, 
    z = terra::vect(dplyr::select(sf_zones, dplyr::all_of(fld_zones))), 
    fun = zonal_fun, exact = T, na.rm = T, as.polygons = T))), 
    cols = -dplyr::any_of(fld_zones), names_to = "lyr", values_to = zonal_fun), 
    time = readr::parse_datetime(str_replace(lyr, glue("{var}\\|(.*)"), 
        "\\1")))
debug: if (!is.null(zonal_csv)) write_csv(d_r, zonal_csv)
debug: write_csv(d_r, zonal_csv)
debug: if (!keep_nc) unlink(dir_nc, recursive = T)
debug: unlink(dir_nc, recursive = T)
debug: return(d_r)
Downloading 1 requests, up to 42 time slices each
Called from: extractr::ed_extract(ed, var = v, sf_zones = ply, bbox = bb, 
    mask_tif = F, rast_tif = glue("{dir_out}/{nms}/{yr}.tif"), 
    zonal_fun = "mean", zonal_csv = glue("{dir_out}/{nms}/{yr}.csv"), 
    dir_nc = glue("{dir_out}/{nms}/{yr}_nc"), keep_nc = F, n_max_vals_per_req = 1e+05, 
    time_min = time_min, time_max = time_max, verbose = T)
debug: while (i_req <= n_reqs) {
    i_t_beg <- (i_req - 1) * n_t_per_req + 1
    i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
    t_req <- times_todo[c(i_t_beg, i_t_end)]
    t_req_str <- format_ISO8601(t_req, usetz = "Z")
    if (verbose) 
        message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
    ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
        ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
        0), nc)
    unlink(ncs0)
    nc_retry <- T
    nc_n_try <- 1
    n_max_retries
    while (nc_retry) {
        res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
            url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
                bbox[["xmax"]]), latitude = c(bbox[["ymin"]], 
                bbox[["ymax"]]), time = t_req_str, fmt = "nc", 
            store = rerddap::disk(path = dir_nc)))
        if (inherits(res, "try-error")) {
            err <- attr(res, "condition")
            msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
            nc_n_try <- nc_n_try + 1
            if (nc_n_try > n_max_retries) {
                stop(msg)
            }
            else {
                message(msg, "\nRETRYing...")
                Sys.sleep(1)
            }
        }
        else {
            nc_retry <- F
        }
    }
    i_req <- i_req + 1
}
debug: i_t_beg <- (i_req - 1) * n_t_per_req + 1
debug: i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
debug: t_req <- times_todo[c(i_t_beg, i_t_end)]
debug: t_req_str <- format_ISO8601(t_req, usetz = "Z")
debug: if (verbose) message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
debug: message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
Fetching request 1 of 1 (2021-01-01 to 2021-12-01) ~ 19:43:46 UTC
debug: ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
    0), nc)
debug: unlink(ncs0)
debug: nc_retry <- T
debug: nc_n_try <- 1
debug: n_max_retries
debug: while (nc_retry) {
    res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
        url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
            bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
        time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
    if (inherits(res, "try-error")) {
        err <- attr(res, "condition")
        msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
        nc_n_try <- nc_n_try + 1
        if (nc_n_try > n_max_retries) {
            stop(msg)
        }
        else {
            message(msg, "\nRETRYing...")
            Sys.sleep(1)
        }
    }
    else {
        nc_retry <- F
    }
}
debug: res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
    url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
        bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
    time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
debug: if (inherits(res, "try-error")) {
    err <- attr(res, "condition")
    msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
    nc_n_try <- nc_n_try + 1
    if (nc_n_try > n_max_retries) {
        stop(msg)
    }
    else {
        message(msg, "\nRETRYing...")
        Sys.sleep(1)
    }
} else {
    nc_retry <- F
}
debug: nc_retry <- F
debug: (while) nc_retry
debug: i_req <- i_req + 1
debug: (while) i_req <= n_reqs
debug: ncs <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size > 
    0), nc)
debug: r <- terra::rast(ncs)
debug: stopifnot(all(class(terra::time(r)) %in% c("POSIXct", "POSIXt")))
debug: idx <- dplyr::pull(dplyr::filter(dplyr::arrange(dplyr::tibble(idx = 1:terra::nlyr(r), 
    time = terra::time(r)), time), !duplicated(time)), idx)
debug: r <- terra::subset(r, idx)
debug: stopifnot(terra::crs(r, proj = T) == wgs84)
debug: if (mask_tif) r <- terra::mask(r, sf_zones)
debug: lyrs <- glue("{var}|{terra::time(r)}")
debug: if (length(dims_other) > 0 && !all(length(dims[dims_other]) == 
    1)) stop(glue("Other dimensions not yet supported: {paste(dims_other, collapse = ',')}"))
debug: names(r) <- lyrs
debug: if (!is.null(rast_tif)) {
    if (fs::file_exists(rast_tif)) {
        r_tmp_tif <- tempfile(fileext = ".tif")
        r_tmp <- c(rast(rast_tif), r)
        r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
        terra::writeRaster(r_tmp, r_tmp_tif)
        fs::file_delete(rast_tif)
        fs::file_move(r_tmp_tif, rast_tif)
        rm(r)
        rm(r_tmp)
    }
    else {
        terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
    }
    r <- terra::rast(rast_tif)
}
debug: if (fs::file_exists(rast_tif)) {
    r_tmp_tif <- tempfile(fileext = ".tif")
    r_tmp <- c(rast(rast_tif), r)
    r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
    terra::writeRaster(r_tmp, r_tmp_tif)
    fs::file_delete(rast_tif)
    fs::file_move(r_tmp_tif, rast_tif)
    rm(r)
    rm(r_tmp)
} else {
    terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
}
debug: terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
debug: r <- terra::rast(rast_tif)
debug: d_r <- mutate(tidyr::pivot_longer(sf::st_drop_geometry(sf::st_as_sf(terra::zonal(x = r, 
    z = terra::vect(dplyr::select(sf_zones, dplyr::all_of(fld_zones))), 
    fun = zonal_fun, exact = T, na.rm = T, as.polygons = T))), 
    cols = -dplyr::any_of(fld_zones), names_to = "lyr", values_to = zonal_fun), 
    time = readr::parse_datetime(str_replace(lyr, glue("{var}\\|(.*)"), 
        "\\1")))
debug: if (!is.null(zonal_csv)) write_csv(d_r, zonal_csv)
debug: write_csv(d_r, zonal_csv)
debug: if (!keep_nc) unlink(dir_nc, recursive = T)
debug: unlink(dir_nc, recursive = T)
debug: return(d_r)
Downloading 1 requests, up to 42 time slices each
Called from: extractr::ed_extract(ed, var = v, sf_zones = ply, bbox = bb, 
    mask_tif = F, rast_tif = glue("{dir_out}/{nms}/{yr}.tif"), 
    zonal_fun = "mean", zonal_csv = glue("{dir_out}/{nms}/{yr}.csv"), 
    dir_nc = glue("{dir_out}/{nms}/{yr}_nc"), keep_nc = F, n_max_vals_per_req = 1e+05, 
    time_min = time_min, time_max = time_max, verbose = T)
debug: while (i_req <= n_reqs) {
    i_t_beg <- (i_req - 1) * n_t_per_req + 1
    i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
    t_req <- times_todo[c(i_t_beg, i_t_end)]
    t_req_str <- format_ISO8601(t_req, usetz = "Z")
    if (verbose) 
        message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
    ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
        ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
        0), nc)
    unlink(ncs0)
    nc_retry <- T
    nc_n_try <- 1
    n_max_retries
    while (nc_retry) {
        res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
            url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
                bbox[["xmax"]]), latitude = c(bbox[["ymin"]], 
                bbox[["ymax"]]), time = t_req_str, fmt = "nc", 
            store = rerddap::disk(path = dir_nc)))
        if (inherits(res, "try-error")) {
            err <- attr(res, "condition")
            msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
            nc_n_try <- nc_n_try + 1
            if (nc_n_try > n_max_retries) {
                stop(msg)
            }
            else {
                message(msg, "\nRETRYing...")
                Sys.sleep(1)
            }
        }
        else {
            nc_retry <- F
        }
    }
    i_req <- i_req + 1
}
debug: i_t_beg <- (i_req - 1) * n_t_per_req + 1
debug: i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
debug: t_req <- times_todo[c(i_t_beg, i_t_end)]
debug: t_req_str <- format_ISO8601(t_req, usetz = "Z")
debug: if (verbose) message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
debug: message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
Fetching request 1 of 1 (2022-01-01 to 2022-12-01) ~ 19:43:48 UTC
debug: ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
    0), nc)
debug: unlink(ncs0)
debug: nc_retry <- T
debug: nc_n_try <- 1
debug: n_max_retries
debug: while (nc_retry) {
    res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
        url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
            bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
        time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
    if (inherits(res, "try-error")) {
        err <- attr(res, "condition")
        msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
        nc_n_try <- nc_n_try + 1
        if (nc_n_try > n_max_retries) {
            stop(msg)
        }
        else {
            message(msg, "\nRETRYing...")
            Sys.sleep(1)
        }
    }
    else {
        nc_retry <- F
    }
}
debug: res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
    url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
        bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
    time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
debug: if (inherits(res, "try-error")) {
    err <- attr(res, "condition")
    msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
    nc_n_try <- nc_n_try + 1
    if (nc_n_try > n_max_retries) {
        stop(msg)
    }
    else {
        message(msg, "\nRETRYing...")
        Sys.sleep(1)
    }
} else {
    nc_retry <- F
}
debug: nc_retry <- F
debug: (while) nc_retry
debug: i_req <- i_req + 1
debug: (while) i_req <= n_reqs
debug: ncs <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size > 
    0), nc)
debug: r <- terra::rast(ncs)
debug: stopifnot(all(class(terra::time(r)) %in% c("POSIXct", "POSIXt")))
debug: idx <- dplyr::pull(dplyr::filter(dplyr::arrange(dplyr::tibble(idx = 1:terra::nlyr(r), 
    time = terra::time(r)), time), !duplicated(time)), idx)
debug: r <- terra::subset(r, idx)
debug: stopifnot(terra::crs(r, proj = T) == wgs84)
debug: if (mask_tif) r <- terra::mask(r, sf_zones)
debug: lyrs <- glue("{var}|{terra::time(r)}")
debug: if (length(dims_other) > 0 && !all(length(dims[dims_other]) == 
    1)) stop(glue("Other dimensions not yet supported: {paste(dims_other, collapse = ',')}"))
debug: names(r) <- lyrs
debug: if (!is.null(rast_tif)) {
    if (fs::file_exists(rast_tif)) {
        r_tmp_tif <- tempfile(fileext = ".tif")
        r_tmp <- c(rast(rast_tif), r)
        r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
        terra::writeRaster(r_tmp, r_tmp_tif)
        fs::file_delete(rast_tif)
        fs::file_move(r_tmp_tif, rast_tif)
        rm(r)
        rm(r_tmp)
    }
    else {
        terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
    }
    r <- terra::rast(rast_tif)
}
debug: if (fs::file_exists(rast_tif)) {
    r_tmp_tif <- tempfile(fileext = ".tif")
    r_tmp <- c(rast(rast_tif), r)
    r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
    terra::writeRaster(r_tmp, r_tmp_tif)
    fs::file_delete(rast_tif)
    fs::file_move(r_tmp_tif, rast_tif)
    rm(r)
    rm(r_tmp)
} else {
    terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
}
debug: terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
debug: r <- terra::rast(rast_tif)
debug: d_r <- mutate(tidyr::pivot_longer(sf::st_drop_geometry(sf::st_as_sf(terra::zonal(x = r, 
    z = terra::vect(dplyr::select(sf_zones, dplyr::all_of(fld_zones))), 
    fun = zonal_fun, exact = T, na.rm = T, as.polygons = T))), 
    cols = -dplyr::any_of(fld_zones), names_to = "lyr", values_to = zonal_fun), 
    time = readr::parse_datetime(str_replace(lyr, glue("{var}\\|(.*)"), 
        "\\1")))
debug: if (!is.null(zonal_csv)) write_csv(d_r, zonal_csv)
debug: write_csv(d_r, zonal_csv)
debug: if (!keep_nc) unlink(dir_nc, recursive = T)
debug: unlink(dir_nc, recursive = T)
debug: return(d_r)
Downloading 1 requests, up to 42 time slices each
Called from: extractr::ed_extract(ed, var = v, sf_zones = ply, bbox = bb, 
    mask_tif = F, rast_tif = glue("{dir_out}/{nms}/{yr}.tif"), 
    zonal_fun = "mean", zonal_csv = glue("{dir_out}/{nms}/{yr}.csv"), 
    dir_nc = glue("{dir_out}/{nms}/{yr}_nc"), keep_nc = F, n_max_vals_per_req = 1e+05, 
    time_min = time_min, time_max = time_max, verbose = T)
debug: while (i_req <= n_reqs) {
    i_t_beg <- (i_req - 1) * n_t_per_req + 1
    i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
    t_req <- times_todo[c(i_t_beg, i_t_end)]
    t_req_str <- format_ISO8601(t_req, usetz = "Z")
    if (verbose) 
        message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
    ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
        ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
        0), nc)
    unlink(ncs0)
    nc_retry <- T
    nc_n_try <- 1
    n_max_retries
    while (nc_retry) {
        res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
            url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
                bbox[["xmax"]]), latitude = c(bbox[["ymin"]], 
                bbox[["ymax"]]), time = t_req_str, fmt = "nc", 
            store = rerddap::disk(path = dir_nc)))
        if (inherits(res, "try-error")) {
            err <- attr(res, "condition")
            msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
            nc_n_try <- nc_n_try + 1
            if (nc_n_try > n_max_retries) {
                stop(msg)
            }
            else {
                message(msg, "\nRETRYing...")
                Sys.sleep(1)
            }
        }
        else {
            nc_retry <- F
        }
    }
    i_req <- i_req + 1
}
debug: i_t_beg <- (i_req - 1) * n_t_per_req + 1
debug: i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
debug: t_req <- times_todo[c(i_t_beg, i_t_end)]
debug: t_req_str <- format_ISO8601(t_req, usetz = "Z")
debug: if (verbose) message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
debug: message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
Fetching request 1 of 1 (2023-01-01 to 2023-12-01) ~ 19:43:50 UTC
debug: ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
    0), nc)
debug: unlink(ncs0)
debug: nc_retry <- T
debug: nc_n_try <- 1
debug: n_max_retries
debug: while (nc_retry) {
    res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
        url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
            bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
        time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
    if (inherits(res, "try-error")) {
        err <- attr(res, "condition")
        msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
        nc_n_try <- nc_n_try + 1
        if (nc_n_try > n_max_retries) {
            stop(msg)
        }
        else {
            message(msg, "\nRETRYing...")
            Sys.sleep(1)
        }
    }
    else {
        nc_retry <- F
    }
}
debug: res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
    url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
        bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
    time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
debug: if (inherits(res, "try-error")) {
    err <- attr(res, "condition")
    msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
    nc_n_try <- nc_n_try + 1
    if (nc_n_try > n_max_retries) {
        stop(msg)
    }
    else {
        message(msg, "\nRETRYing...")
        Sys.sleep(1)
    }
} else {
    nc_retry <- F
}
debug: nc_retry <- F
debug: (while) nc_retry
debug: i_req <- i_req + 1
debug: (while) i_req <= n_reqs
debug: ncs <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size > 
    0), nc)
debug: r <- terra::rast(ncs)
debug: stopifnot(all(class(terra::time(r)) %in% c("POSIXct", "POSIXt")))
debug: idx <- dplyr::pull(dplyr::filter(dplyr::arrange(dplyr::tibble(idx = 1:terra::nlyr(r), 
    time = terra::time(r)), time), !duplicated(time)), idx)
debug: r <- terra::subset(r, idx)
debug: stopifnot(terra::crs(r, proj = T) == wgs84)
debug: if (mask_tif) r <- terra::mask(r, sf_zones)
debug: lyrs <- glue("{var}|{terra::time(r)}")
debug: if (length(dims_other) > 0 && !all(length(dims[dims_other]) == 
    1)) stop(glue("Other dimensions not yet supported: {paste(dims_other, collapse = ',')}"))
debug: names(r) <- lyrs
debug: if (!is.null(rast_tif)) {
    if (fs::file_exists(rast_tif)) {
        r_tmp_tif <- tempfile(fileext = ".tif")
        r_tmp <- c(rast(rast_tif), r)
        r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
        terra::writeRaster(r_tmp, r_tmp_tif)
        fs::file_delete(rast_tif)
        fs::file_move(r_tmp_tif, rast_tif)
        rm(r)
        rm(r_tmp)
    }
    else {
        terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
    }
    r <- terra::rast(rast_tif)
}
debug: if (fs::file_exists(rast_tif)) {
    r_tmp_tif <- tempfile(fileext = ".tif")
    r_tmp <- c(rast(rast_tif), r)
    r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
    terra::writeRaster(r_tmp, r_tmp_tif)
    fs::file_delete(rast_tif)
    fs::file_move(r_tmp_tif, rast_tif)
    rm(r)
    rm(r_tmp)
} else {
    terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
}
debug: terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
debug: r <- terra::rast(rast_tif)
debug: d_r <- mutate(tidyr::pivot_longer(sf::st_drop_geometry(sf::st_as_sf(terra::zonal(x = r, 
    z = terra::vect(dplyr::select(sf_zones, dplyr::all_of(fld_zones))), 
    fun = zonal_fun, exact = T, na.rm = T, as.polygons = T))), 
    cols = -dplyr::any_of(fld_zones), names_to = "lyr", values_to = zonal_fun), 
    time = readr::parse_datetime(str_replace(lyr, glue("{var}\\|(.*)"), 
        "\\1")))
debug: if (!is.null(zonal_csv)) write_csv(d_r, zonal_csv)
debug: write_csv(d_r, zonal_csv)
debug: if (!keep_nc) unlink(dir_nc, recursive = T)
debug: unlink(dir_nc, recursive = T)
debug: return(d_r)
Downloading 1 requests, up to 42 time slices each
Called from: extractr::ed_extract(ed, var = v, sf_zones = ply, bbox = bb, 
    mask_tif = F, rast_tif = glue("{dir_out}/{nms}/{yr}.tif"), 
    zonal_fun = "mean", zonal_csv = glue("{dir_out}/{nms}/{yr}.csv"), 
    dir_nc = glue("{dir_out}/{nms}/{yr}_nc"), keep_nc = F, n_max_vals_per_req = 1e+05, 
    time_min = time_min, time_max = time_max, verbose = T)
debug: while (i_req <= n_reqs) {
    i_t_beg <- (i_req - 1) * n_t_per_req + 1
    i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
    t_req <- times_todo[c(i_t_beg, i_t_end)]
    t_req_str <- format_ISO8601(t_req, usetz = "Z")
    if (verbose) 
        message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
    ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
        ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
        0), nc)
    unlink(ncs0)
    nc_retry <- T
    nc_n_try <- 1
    n_max_retries
    while (nc_retry) {
        res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
            url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
                bbox[["xmax"]]), latitude = c(bbox[["ymin"]], 
                bbox[["ymax"]]), time = t_req_str, fmt = "nc", 
            store = rerddap::disk(path = dir_nc)))
        if (inherits(res, "try-error")) {
            err <- attr(res, "condition")
            msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
            nc_n_try <- nc_n_try + 1
            if (nc_n_try > n_max_retries) {
                stop(msg)
            }
            else {
                message(msg, "\nRETRYing...")
                Sys.sleep(1)
            }
        }
        else {
            nc_retry <- F
        }
    }
    i_req <- i_req + 1
}
debug: i_t_beg <- (i_req - 1) * n_t_per_req + 1
debug: i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
debug: t_req <- times_todo[c(i_t_beg, i_t_end)]
debug: t_req_str <- format_ISO8601(t_req, usetz = "Z")
debug: if (verbose) message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
debug: message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
Fetching request 1 of 1 (2024-01-01 to 2024-12-01) ~ 19:43:52 UTC
debug: ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
    0), nc)
debug: unlink(ncs0)
debug: nc_retry <- T
debug: nc_n_try <- 1
debug: n_max_retries
debug: while (nc_retry) {
    res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
        url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
            bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
        time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
    if (inherits(res, "try-error")) {
        err <- attr(res, "condition")
        msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
        nc_n_try <- nc_n_try + 1
        if (nc_n_try > n_max_retries) {
            stop(msg)
        }
        else {
            message(msg, "\nRETRYing...")
            Sys.sleep(1)
        }
    }
    else {
        nc_retry <- F
    }
}
debug: res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
    url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
        bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
    time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
debug: if (inherits(res, "try-error")) {
    err <- attr(res, "condition")
    msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
    nc_n_try <- nc_n_try + 1
    if (nc_n_try > n_max_retries) {
        stop(msg)
    }
    else {
        message(msg, "\nRETRYing...")
        Sys.sleep(1)
    }
} else {
    nc_retry <- F
}
debug: nc_retry <- F
debug: (while) nc_retry
debug: i_req <- i_req + 1
debug: (while) i_req <= n_reqs
debug: ncs <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size > 
    0), nc)
debug: r <- terra::rast(ncs)
debug: stopifnot(all(class(terra::time(r)) %in% c("POSIXct", "POSIXt")))
debug: idx <- dplyr::pull(dplyr::filter(dplyr::arrange(dplyr::tibble(idx = 1:terra::nlyr(r), 
    time = terra::time(r)), time), !duplicated(time)), idx)
debug: r <- terra::subset(r, idx)
debug: stopifnot(terra::crs(r, proj = T) == wgs84)
debug: if (mask_tif) r <- terra::mask(r, sf_zones)
debug: lyrs <- glue("{var}|{terra::time(r)}")
debug: if (length(dims_other) > 0 && !all(length(dims[dims_other]) == 
    1)) stop(glue("Other dimensions not yet supported: {paste(dims_other, collapse = ',')}"))
debug: names(r) <- lyrs
debug: if (!is.null(rast_tif)) {
    if (fs::file_exists(rast_tif)) {
        r_tmp_tif <- tempfile(fileext = ".tif")
        r_tmp <- c(rast(rast_tif), r)
        r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
        terra::writeRaster(r_tmp, r_tmp_tif)
        fs::file_delete(rast_tif)
        fs::file_move(r_tmp_tif, rast_tif)
        rm(r)
        rm(r_tmp)
    }
    else {
        terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
    }
    r <- terra::rast(rast_tif)
}
debug: if (fs::file_exists(rast_tif)) {
    r_tmp_tif <- tempfile(fileext = ".tif")
    r_tmp <- c(rast(rast_tif), r)
    r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
    terra::writeRaster(r_tmp, r_tmp_tif)
    fs::file_delete(rast_tif)
    fs::file_move(r_tmp_tif, rast_tif)
    rm(r)
    rm(r_tmp)
} else {
    terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
}
debug: terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
debug: r <- terra::rast(rast_tif)
debug: d_r <- mutate(tidyr::pivot_longer(sf::st_drop_geometry(sf::st_as_sf(terra::zonal(x = r, 
    z = terra::vect(dplyr::select(sf_zones, dplyr::all_of(fld_zones))), 
    fun = zonal_fun, exact = T, na.rm = T, as.polygons = T))), 
    cols = -dplyr::any_of(fld_zones), names_to = "lyr", values_to = zonal_fun), 
    time = readr::parse_datetime(str_replace(lyr, glue("{var}\\|(.*)"), 
        "\\1")))
debug: if (!is.null(zonal_csv)) write_csv(d_r, zonal_csv)
debug: write_csv(d_r, zonal_csv)
debug: if (!keep_nc) unlink(dir_nc, recursive = T)
debug: unlink(dir_nc, recursive = T)
debug: return(d_r)
Downloading 1 requests, up to 42 time slices each
Called from: extractr::ed_extract(ed, var = v, sf_zones = ply, bbox = bb, 
    mask_tif = F, rast_tif = glue("{dir_out}/{nms}/{yr}.tif"), 
    zonal_fun = "mean", zonal_csv = glue("{dir_out}/{nms}/{yr}.csv"), 
    dir_nc = glue("{dir_out}/{nms}/{yr}_nc"), keep_nc = F, n_max_vals_per_req = 1e+05, 
    time_min = time_min, time_max = time_max, verbose = T)
debug: while (i_req <= n_reqs) {
    i_t_beg <- (i_req - 1) * n_t_per_req + 1
    i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
    t_req <- times_todo[c(i_t_beg, i_t_end)]
    t_req_str <- format_ISO8601(t_req, usetz = "Z")
    if (verbose) 
        message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
    ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
        ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
        0), nc)
    unlink(ncs0)
    nc_retry <- T
    nc_n_try <- 1
    n_max_retries
    while (nc_retry) {
        res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
            url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
                bbox[["xmax"]]), latitude = c(bbox[["ymin"]], 
                bbox[["ymax"]]), time = t_req_str, fmt = "nc", 
            store = rerddap::disk(path = dir_nc)))
        if (inherits(res, "try-error")) {
            err <- attr(res, "condition")
            msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
            nc_n_try <- nc_n_try + 1
            if (nc_n_try > n_max_retries) {
                stop(msg)
            }
            else {
                message(msg, "\nRETRYing...")
                Sys.sleep(1)
            }
        }
        else {
            nc_retry <- F
        }
    }
    i_req <- i_req + 1
}
debug: i_t_beg <- (i_req - 1) * n_t_per_req + 1
debug: i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
debug: t_req <- times_todo[c(i_t_beg, i_t_end)]
debug: t_req_str <- format_ISO8601(t_req, usetz = "Z")
debug: if (verbose) message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
debug: message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
Fetching request 1 of 1 (2025-01-01 to 2025-07-01) ~ 19:43:54 UTC
debug: ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
    0), nc)
debug: unlink(ncs0)
debug: nc_retry <- T
debug: nc_n_try <- 1
debug: n_max_retries
debug: while (nc_retry) {
    res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
        url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
            bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
        time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
    if (inherits(res, "try-error")) {
        err <- attr(res, "condition")
        msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
        nc_n_try <- nc_n_try + 1
        if (nc_n_try > n_max_retries) {
            stop(msg)
        }
        else {
            message(msg, "\nRETRYing...")
            Sys.sleep(1)
        }
    }
    else {
        nc_retry <- F
    }
}
debug: res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
    url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
        bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
    time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
debug: if (inherits(res, "try-error")) {
    err <- attr(res, "condition")
    msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
    nc_n_try <- nc_n_try + 1
    if (nc_n_try > n_max_retries) {
        stop(msg)
    }
    else {
        message(msg, "\nRETRYing...")
        Sys.sleep(1)
    }
} else {
    nc_retry <- F
}
debug: nc_retry <- F
debug: (while) nc_retry
debug: i_req <- i_req + 1
debug: (while) i_req <= n_reqs
debug: ncs <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size > 
    0), nc)
debug: r <- terra::rast(ncs)
debug: stopifnot(all(class(terra::time(r)) %in% c("POSIXct", "POSIXt")))
debug: idx <- dplyr::pull(dplyr::filter(dplyr::arrange(dplyr::tibble(idx = 1:terra::nlyr(r), 
    time = terra::time(r)), time), !duplicated(time)), idx)
debug: r <- terra::subset(r, idx)
debug: stopifnot(terra::crs(r, proj = T) == wgs84)
debug: if (mask_tif) r <- terra::mask(r, sf_zones)
debug: lyrs <- glue("{var}|{terra::time(r)}")
debug: if (length(dims_other) > 0 && !all(length(dims[dims_other]) == 
    1)) stop(glue("Other dimensions not yet supported: {paste(dims_other, collapse = ',')}"))
debug: names(r) <- lyrs
debug: if (!is.null(rast_tif)) {
    if (fs::file_exists(rast_tif)) {
        r_tmp_tif <- tempfile(fileext = ".tif")
        r_tmp <- c(rast(rast_tif), r)
        r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
        terra::writeRaster(r_tmp, r_tmp_tif)
        fs::file_delete(rast_tif)
        fs::file_move(r_tmp_tif, rast_tif)
        rm(r)
        rm(r_tmp)
    }
    else {
        terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
    }
    r <- terra::rast(rast_tif)
}
debug: if (fs::file_exists(rast_tif)) {
    r_tmp_tif <- tempfile(fileext = ".tif")
    r_tmp <- c(rast(rast_tif), r)
    r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
    terra::writeRaster(r_tmp, r_tmp_tif)
    fs::file_delete(rast_tif)
    fs::file_move(r_tmp_tif, rast_tif)
    rm(r)
    rm(r_tmp)
} else {
    terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
}
debug: terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
debug: r <- terra::rast(rast_tif)
debug: d_r <- mutate(tidyr::pivot_longer(sf::st_drop_geometry(sf::st_as_sf(terra::zonal(x = r, 
    z = terra::vect(dplyr::select(sf_zones, dplyr::all_of(fld_zones))), 
    fun = zonal_fun, exact = T, na.rm = T, as.polygons = T))), 
    cols = -dplyr::any_of(fld_zones), names_to = "lyr", values_to = zonal_fun), 
    time = readr::parse_datetime(str_replace(lyr, glue("{var}\\|(.*)"), 
        "\\1")))
debug: if (!is.null(zonal_csv)) write_csv(d_r, zonal_csv)
debug: write_csv(d_r, zonal_csv)
debug: if (!keep_nc) unlink(dir_nc, recursive = T)
debug: unlink(dir_nc, recursive = T)
debug: return(d_r)
Downloading 1 requests, up to 190 time slices each
Called from: extractr::ed_extract(ed, var = v, sf_zones = ply, bbox = bb, 
    mask_tif = F, rast_tif = glue("{dir_out}/{nms}/{yr}.tif"), 
    zonal_fun = "mean", zonal_csv = glue("{dir_out}/{nms}/{yr}.csv"), 
    dir_nc = glue("{dir_out}/{nms}/{yr}_nc"), keep_nc = F, n_max_vals_per_req = 1e+05, 
    time_min = time_min, time_max = time_max, verbose = T)
debug: while (i_req <= n_reqs) {
    i_t_beg <- (i_req - 1) * n_t_per_req + 1
    i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
    t_req <- times_todo[c(i_t_beg, i_t_end)]
    t_req_str <- format_ISO8601(t_req, usetz = "Z")
    if (verbose) 
        message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
    ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
        ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
        0), nc)
    unlink(ncs0)
    nc_retry <- T
    nc_n_try <- 1
    n_max_retries
    while (nc_retry) {
        res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
            url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
                bbox[["xmax"]]), latitude = c(bbox[["ymin"]], 
                bbox[["ymax"]]), time = t_req_str, fmt = "nc", 
            store = rerddap::disk(path = dir_nc)))
        if (inherits(res, "try-error")) {
            err <- attr(res, "condition")
            msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
            nc_n_try <- nc_n_try + 1
            if (nc_n_try > n_max_retries) {
                stop(msg)
            }
            else {
                message(msg, "\nRETRYing...")
                Sys.sleep(1)
            }
        }
        else {
            nc_retry <- F
        }
    }
    i_req <- i_req + 1
}
debug: i_t_beg <- (i_req - 1) * n_t_per_req + 1
debug: i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
debug: t_req <- times_todo[c(i_t_beg, i_t_end)]
debug: t_req_str <- format_ISO8601(t_req, usetz = "Z")
debug: if (verbose) message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
debug: message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
Fetching request 1 of 1 (1998-01-01 to 1998-12-01) ~ 19:43:56 UTC
debug: ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
    0), nc)
debug: unlink(ncs0)
debug: nc_retry <- T
debug: nc_n_try <- 1
debug: n_max_retries
debug: while (nc_retry) {
    res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
        url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
            bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
        time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
    if (inherits(res, "try-error")) {
        err <- attr(res, "condition")
        msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
        nc_n_try <- nc_n_try + 1
        if (nc_n_try > n_max_retries) {
            stop(msg)
        }
        else {
            message(msg, "\nRETRYing...")
            Sys.sleep(1)
        }
    }
    else {
        nc_retry <- F
    }
}
debug: res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
    url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
        bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
    time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
debug: if (inherits(res, "try-error")) {
    err <- attr(res, "condition")
    msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
    nc_n_try <- nc_n_try + 1
    if (nc_n_try > n_max_retries) {
        stop(msg)
    }
    else {
        message(msg, "\nRETRYing...")
        Sys.sleep(1)
    }
} else {
    nc_retry <- F
}
debug: nc_retry <- F
debug: (while) nc_retry
debug: i_req <- i_req + 1
debug: (while) i_req <= n_reqs
debug: ncs <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size > 
    0), nc)
debug: r <- terra::rast(ncs)
debug: stopifnot(all(class(terra::time(r)) %in% c("POSIXct", "POSIXt")))
debug: idx <- dplyr::pull(dplyr::filter(dplyr::arrange(dplyr::tibble(idx = 1:terra::nlyr(r), 
    time = terra::time(r)), time), !duplicated(time)), idx)
debug: r <- terra::subset(r, idx)
debug: stopifnot(terra::crs(r, proj = T) == wgs84)
debug: if (mask_tif) r <- terra::mask(r, sf_zones)
debug: lyrs <- glue("{var}|{terra::time(r)}")
debug: if (length(dims_other) > 0 && !all(length(dims[dims_other]) == 
    1)) stop(glue("Other dimensions not yet supported: {paste(dims_other, collapse = ',')}"))
debug: names(r) <- lyrs
debug: if (!is.null(rast_tif)) {
    if (fs::file_exists(rast_tif)) {
        r_tmp_tif <- tempfile(fileext = ".tif")
        r_tmp <- c(rast(rast_tif), r)
        r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
        terra::writeRaster(r_tmp, r_tmp_tif)
        fs::file_delete(rast_tif)
        fs::file_move(r_tmp_tif, rast_tif)
        rm(r)
        rm(r_tmp)
    }
    else {
        terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
    }
    r <- terra::rast(rast_tif)
}
debug: if (fs::file_exists(rast_tif)) {
    r_tmp_tif <- tempfile(fileext = ".tif")
    r_tmp <- c(rast(rast_tif), r)
    r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
    terra::writeRaster(r_tmp, r_tmp_tif)
    fs::file_delete(rast_tif)
    fs::file_move(r_tmp_tif, rast_tif)
    rm(r)
    rm(r_tmp)
} else {
    terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
}
debug: terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
debug: r <- terra::rast(rast_tif)
debug: d_r <- mutate(tidyr::pivot_longer(sf::st_drop_geometry(sf::st_as_sf(terra::zonal(x = r, 
    z = terra::vect(dplyr::select(sf_zones, dplyr::all_of(fld_zones))), 
    fun = zonal_fun, exact = T, na.rm = T, as.polygons = T))), 
    cols = -dplyr::any_of(fld_zones), names_to = "lyr", values_to = zonal_fun), 
    time = readr::parse_datetime(str_replace(lyr, glue("{var}\\|(.*)"), 
        "\\1")))
debug: if (!is.null(zonal_csv)) write_csv(d_r, zonal_csv)
debug: write_csv(d_r, zonal_csv)
debug: if (!keep_nc) unlink(dir_nc, recursive = T)
debug: unlink(dir_nc, recursive = T)
debug: return(d_r)
Downloading 1 requests, up to 190 time slices each
Called from: extractr::ed_extract(ed, var = v, sf_zones = ply, bbox = bb, 
    mask_tif = F, rast_tif = glue("{dir_out}/{nms}/{yr}.tif"), 
    zonal_fun = "mean", zonal_csv = glue("{dir_out}/{nms}/{yr}.csv"), 
    dir_nc = glue("{dir_out}/{nms}/{yr}_nc"), keep_nc = F, n_max_vals_per_req = 1e+05, 
    time_min = time_min, time_max = time_max, verbose = T)
debug: while (i_req <= n_reqs) {
    i_t_beg <- (i_req - 1) * n_t_per_req + 1
    i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
    t_req <- times_todo[c(i_t_beg, i_t_end)]
    t_req_str <- format_ISO8601(t_req, usetz = "Z")
    if (verbose) 
        message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
    ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
        ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
        0), nc)
    unlink(ncs0)
    nc_retry <- T
    nc_n_try <- 1
    n_max_retries
    while (nc_retry) {
        res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
            url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
                bbox[["xmax"]]), latitude = c(bbox[["ymin"]], 
                bbox[["ymax"]]), time = t_req_str, fmt = "nc", 
            store = rerddap::disk(path = dir_nc)))
        if (inherits(res, "try-error")) {
            err <- attr(res, "condition")
            msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
            nc_n_try <- nc_n_try + 1
            if (nc_n_try > n_max_retries) {
                stop(msg)
            }
            else {
                message(msg, "\nRETRYing...")
                Sys.sleep(1)
            }
        }
        else {
            nc_retry <- F
        }
    }
    i_req <- i_req + 1
}
debug: i_t_beg <- (i_req - 1) * n_t_per_req + 1
debug: i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
debug: t_req <- times_todo[c(i_t_beg, i_t_end)]
debug: t_req_str <- format_ISO8601(t_req, usetz = "Z")
debug: if (verbose) message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
debug: message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
Fetching request 1 of 1 (1999-01-01 to 1999-12-01) ~ 19:43:58 UTC
debug: ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
    0), nc)
debug: unlink(ncs0)
debug: nc_retry <- T
debug: nc_n_try <- 1
debug: n_max_retries
debug: while (nc_retry) {
    res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
        url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
            bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
        time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
    if (inherits(res, "try-error")) {
        err <- attr(res, "condition")
        msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
        nc_n_try <- nc_n_try + 1
        if (nc_n_try > n_max_retries) {
            stop(msg)
        }
        else {
            message(msg, "\nRETRYing...")
            Sys.sleep(1)
        }
    }
    else {
        nc_retry <- F
    }
}
debug: res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
    url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
        bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
    time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
debug: if (inherits(res, "try-error")) {
    err <- attr(res, "condition")
    msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
    nc_n_try <- nc_n_try + 1
    if (nc_n_try > n_max_retries) {
        stop(msg)
    }
    else {
        message(msg, "\nRETRYing...")
        Sys.sleep(1)
    }
} else {
    nc_retry <- F
}
debug: nc_retry <- F
debug: (while) nc_retry
debug: i_req <- i_req + 1
debug: (while) i_req <= n_reqs
debug: ncs <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size > 
    0), nc)
debug: r <- terra::rast(ncs)
debug: stopifnot(all(class(terra::time(r)) %in% c("POSIXct", "POSIXt")))
debug: idx <- dplyr::pull(dplyr::filter(dplyr::arrange(dplyr::tibble(idx = 1:terra::nlyr(r), 
    time = terra::time(r)), time), !duplicated(time)), idx)
debug: r <- terra::subset(r, idx)
debug: stopifnot(terra::crs(r, proj = T) == wgs84)
debug: if (mask_tif) r <- terra::mask(r, sf_zones)
debug: lyrs <- glue("{var}|{terra::time(r)}")
debug: if (length(dims_other) > 0 && !all(length(dims[dims_other]) == 
    1)) stop(glue("Other dimensions not yet supported: {paste(dims_other, collapse = ',')}"))
debug: names(r) <- lyrs
debug: if (!is.null(rast_tif)) {
    if (fs::file_exists(rast_tif)) {
        r_tmp_tif <- tempfile(fileext = ".tif")
        r_tmp <- c(rast(rast_tif), r)
        r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
        terra::writeRaster(r_tmp, r_tmp_tif)
        fs::file_delete(rast_tif)
        fs::file_move(r_tmp_tif, rast_tif)
        rm(r)
        rm(r_tmp)
    }
    else {
        terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
    }
    r <- terra::rast(rast_tif)
}
debug: if (fs::file_exists(rast_tif)) {
    r_tmp_tif <- tempfile(fileext = ".tif")
    r_tmp <- c(rast(rast_tif), r)
    r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
    terra::writeRaster(r_tmp, r_tmp_tif)
    fs::file_delete(rast_tif)
    fs::file_move(r_tmp_tif, rast_tif)
    rm(r)
    rm(r_tmp)
} else {
    terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
}
debug: terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
debug: r <- terra::rast(rast_tif)
debug: d_r <- mutate(tidyr::pivot_longer(sf::st_drop_geometry(sf::st_as_sf(terra::zonal(x = r, 
    z = terra::vect(dplyr::select(sf_zones, dplyr::all_of(fld_zones))), 
    fun = zonal_fun, exact = T, na.rm = T, as.polygons = T))), 
    cols = -dplyr::any_of(fld_zones), names_to = "lyr", values_to = zonal_fun), 
    time = readr::parse_datetime(str_replace(lyr, glue("{var}\\|(.*)"), 
        "\\1")))
debug: if (!is.null(zonal_csv)) write_csv(d_r, zonal_csv)
debug: write_csv(d_r, zonal_csv)
debug: if (!keep_nc) unlink(dir_nc, recursive = T)
debug: unlink(dir_nc, recursive = T)
debug: return(d_r)
Downloading 1 requests, up to 190 time slices each
Called from: extractr::ed_extract(ed, var = v, sf_zones = ply, bbox = bb, 
    mask_tif = F, rast_tif = glue("{dir_out}/{nms}/{yr}.tif"), 
    zonal_fun = "mean", zonal_csv = glue("{dir_out}/{nms}/{yr}.csv"), 
    dir_nc = glue("{dir_out}/{nms}/{yr}_nc"), keep_nc = F, n_max_vals_per_req = 1e+05, 
    time_min = time_min, time_max = time_max, verbose = T)
debug: while (i_req <= n_reqs) {
    i_t_beg <- (i_req - 1) * n_t_per_req + 1
    i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
    t_req <- times_todo[c(i_t_beg, i_t_end)]
    t_req_str <- format_ISO8601(t_req, usetz = "Z")
    if (verbose) 
        message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
    ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
        ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
        0), nc)
    unlink(ncs0)
    nc_retry <- T
    nc_n_try <- 1
    n_max_retries
    while (nc_retry) {
        res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
            url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
                bbox[["xmax"]]), latitude = c(bbox[["ymin"]], 
                bbox[["ymax"]]), time = t_req_str, fmt = "nc", 
            store = rerddap::disk(path = dir_nc)))
        if (inherits(res, "try-error")) {
            err <- attr(res, "condition")
            msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
            nc_n_try <- nc_n_try + 1
            if (nc_n_try > n_max_retries) {
                stop(msg)
            }
            else {
                message(msg, "\nRETRYing...")
                Sys.sleep(1)
            }
        }
        else {
            nc_retry <- F
        }
    }
    i_req <- i_req + 1
}
debug: i_t_beg <- (i_req - 1) * n_t_per_req + 1
debug: i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
debug: t_req <- times_todo[c(i_t_beg, i_t_end)]
debug: t_req_str <- format_ISO8601(t_req, usetz = "Z")
debug: if (verbose) message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
debug: message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
Fetching request 1 of 1 (2000-01-01 to 2000-12-01) ~ 19:44:00 UTC
debug: ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
    0), nc)
debug: unlink(ncs0)
debug: nc_retry <- T
debug: nc_n_try <- 1
debug: n_max_retries
debug: while (nc_retry) {
    res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
        url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
            bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
        time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
    if (inherits(res, "try-error")) {
        err <- attr(res, "condition")
        msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
        nc_n_try <- nc_n_try + 1
        if (nc_n_try > n_max_retries) {
            stop(msg)
        }
        else {
            message(msg, "\nRETRYing...")
            Sys.sleep(1)
        }
    }
    else {
        nc_retry <- F
    }
}
debug: res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
    url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
        bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
    time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
debug: if (inherits(res, "try-error")) {
    err <- attr(res, "condition")
    msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
    nc_n_try <- nc_n_try + 1
    if (nc_n_try > n_max_retries) {
        stop(msg)
    }
    else {
        message(msg, "\nRETRYing...")
        Sys.sleep(1)
    }
} else {
    nc_retry <- F
}
debug: nc_retry <- F
debug: (while) nc_retry
debug: i_req <- i_req + 1
debug: (while) i_req <= n_reqs
debug: ncs <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size > 
    0), nc)
debug: r <- terra::rast(ncs)
debug: stopifnot(all(class(terra::time(r)) %in% c("POSIXct", "POSIXt")))
debug: idx <- dplyr::pull(dplyr::filter(dplyr::arrange(dplyr::tibble(idx = 1:terra::nlyr(r), 
    time = terra::time(r)), time), !duplicated(time)), idx)
debug: r <- terra::subset(r, idx)
debug: stopifnot(terra::crs(r, proj = T) == wgs84)
debug: if (mask_tif) r <- terra::mask(r, sf_zones)
debug: lyrs <- glue("{var}|{terra::time(r)}")
debug: if (length(dims_other) > 0 && !all(length(dims[dims_other]) == 
    1)) stop(glue("Other dimensions not yet supported: {paste(dims_other, collapse = ',')}"))
debug: names(r) <- lyrs
debug: if (!is.null(rast_tif)) {
    if (fs::file_exists(rast_tif)) {
        r_tmp_tif <- tempfile(fileext = ".tif")
        r_tmp <- c(rast(rast_tif), r)
        r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
        terra::writeRaster(r_tmp, r_tmp_tif)
        fs::file_delete(rast_tif)
        fs::file_move(r_tmp_tif, rast_tif)
        rm(r)
        rm(r_tmp)
    }
    else {
        terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
    }
    r <- terra::rast(rast_tif)
}
debug: if (fs::file_exists(rast_tif)) {
    r_tmp_tif <- tempfile(fileext = ".tif")
    r_tmp <- c(rast(rast_tif), r)
    r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
    terra::writeRaster(r_tmp, r_tmp_tif)
    fs::file_delete(rast_tif)
    fs::file_move(r_tmp_tif, rast_tif)
    rm(r)
    rm(r_tmp)
} else {
    terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
}
debug: terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
debug: r <- terra::rast(rast_tif)
debug: d_r <- mutate(tidyr::pivot_longer(sf::st_drop_geometry(sf::st_as_sf(terra::zonal(x = r, 
    z = terra::vect(dplyr::select(sf_zones, dplyr::all_of(fld_zones))), 
    fun = zonal_fun, exact = T, na.rm = T, as.polygons = T))), 
    cols = -dplyr::any_of(fld_zones), names_to = "lyr", values_to = zonal_fun), 
    time = readr::parse_datetime(str_replace(lyr, glue("{var}\\|(.*)"), 
        "\\1")))
debug: if (!is.null(zonal_csv)) write_csv(d_r, zonal_csv)
debug: write_csv(d_r, zonal_csv)
debug: if (!keep_nc) unlink(dir_nc, recursive = T)
debug: unlink(dir_nc, recursive = T)
debug: return(d_r)
Downloading 1 requests, up to 190 time slices each
Called from: extractr::ed_extract(ed, var = v, sf_zones = ply, bbox = bb, 
    mask_tif = F, rast_tif = glue("{dir_out}/{nms}/{yr}.tif"), 
    zonal_fun = "mean", zonal_csv = glue("{dir_out}/{nms}/{yr}.csv"), 
    dir_nc = glue("{dir_out}/{nms}/{yr}_nc"), keep_nc = F, n_max_vals_per_req = 1e+05, 
    time_min = time_min, time_max = time_max, verbose = T)
debug: while (i_req <= n_reqs) {
    i_t_beg <- (i_req - 1) * n_t_per_req + 1
    i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
    t_req <- times_todo[c(i_t_beg, i_t_end)]
    t_req_str <- format_ISO8601(t_req, usetz = "Z")
    if (verbose) 
        message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
    ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
        ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
        0), nc)
    unlink(ncs0)
    nc_retry <- T
    nc_n_try <- 1
    n_max_retries
    while (nc_retry) {
        res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
            url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
                bbox[["xmax"]]), latitude = c(bbox[["ymin"]], 
                bbox[["ymax"]]), time = t_req_str, fmt = "nc", 
            store = rerddap::disk(path = dir_nc)))
        if (inherits(res, "try-error")) {
            err <- attr(res, "condition")
            msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
            nc_n_try <- nc_n_try + 1
            if (nc_n_try > n_max_retries) {
                stop(msg)
            }
            else {
                message(msg, "\nRETRYing...")
                Sys.sleep(1)
            }
        }
        else {
            nc_retry <- F
        }
    }
    i_req <- i_req + 1
}
debug: i_t_beg <- (i_req - 1) * n_t_per_req + 1
debug: i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
debug: t_req <- times_todo[c(i_t_beg, i_t_end)]
debug: t_req_str <- format_ISO8601(t_req, usetz = "Z")
debug: if (verbose) message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
debug: message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
Fetching request 1 of 1 (2001-01-01 to 2001-12-01) ~ 19:44:02 UTC
debug: ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
    0), nc)
debug: unlink(ncs0)
debug: nc_retry <- T
debug: nc_n_try <- 1
debug: n_max_retries
debug: while (nc_retry) {
    res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
        url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
            bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
        time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
    if (inherits(res, "try-error")) {
        err <- attr(res, "condition")
        msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
        nc_n_try <- nc_n_try + 1
        if (nc_n_try > n_max_retries) {
            stop(msg)
        }
        else {
            message(msg, "\nRETRYing...")
            Sys.sleep(1)
        }
    }
    else {
        nc_retry <- F
    }
}
debug: res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
    url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
        bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
    time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
debug: if (inherits(res, "try-error")) {
    err <- attr(res, "condition")
    msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
    nc_n_try <- nc_n_try + 1
    if (nc_n_try > n_max_retries) {
        stop(msg)
    }
    else {
        message(msg, "\nRETRYing...")
        Sys.sleep(1)
    }
} else {
    nc_retry <- F
}
debug: nc_retry <- F
debug: (while) nc_retry
debug: i_req <- i_req + 1
debug: (while) i_req <= n_reqs
debug: ncs <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size > 
    0), nc)
debug: r <- terra::rast(ncs)
debug: stopifnot(all(class(terra::time(r)) %in% c("POSIXct", "POSIXt")))
debug: idx <- dplyr::pull(dplyr::filter(dplyr::arrange(dplyr::tibble(idx = 1:terra::nlyr(r), 
    time = terra::time(r)), time), !duplicated(time)), idx)
debug: r <- terra::subset(r, idx)
debug: stopifnot(terra::crs(r, proj = T) == wgs84)
debug: if (mask_tif) r <- terra::mask(r, sf_zones)
debug: lyrs <- glue("{var}|{terra::time(r)}")
debug: if (length(dims_other) > 0 && !all(length(dims[dims_other]) == 
    1)) stop(glue("Other dimensions not yet supported: {paste(dims_other, collapse = ',')}"))
debug: names(r) <- lyrs
debug: if (!is.null(rast_tif)) {
    if (fs::file_exists(rast_tif)) {
        r_tmp_tif <- tempfile(fileext = ".tif")
        r_tmp <- c(rast(rast_tif), r)
        r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
        terra::writeRaster(r_tmp, r_tmp_tif)
        fs::file_delete(rast_tif)
        fs::file_move(r_tmp_tif, rast_tif)
        rm(r)
        rm(r_tmp)
    }
    else {
        terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
    }
    r <- terra::rast(rast_tif)
}
debug: if (fs::file_exists(rast_tif)) {
    r_tmp_tif <- tempfile(fileext = ".tif")
    r_tmp <- c(rast(rast_tif), r)
    r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
    terra::writeRaster(r_tmp, r_tmp_tif)
    fs::file_delete(rast_tif)
    fs::file_move(r_tmp_tif, rast_tif)
    rm(r)
    rm(r_tmp)
} else {
    terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
}
debug: terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
debug: r <- terra::rast(rast_tif)
debug: d_r <- mutate(tidyr::pivot_longer(sf::st_drop_geometry(sf::st_as_sf(terra::zonal(x = r, 
    z = terra::vect(dplyr::select(sf_zones, dplyr::all_of(fld_zones))), 
    fun = zonal_fun, exact = T, na.rm = T, as.polygons = T))), 
    cols = -dplyr::any_of(fld_zones), names_to = "lyr", values_to = zonal_fun), 
    time = readr::parse_datetime(str_replace(lyr, glue("{var}\\|(.*)"), 
        "\\1")))
debug: if (!is.null(zonal_csv)) write_csv(d_r, zonal_csv)
debug: write_csv(d_r, zonal_csv)
debug: if (!keep_nc) unlink(dir_nc, recursive = T)
debug: unlink(dir_nc, recursive = T)
debug: return(d_r)
Downloading 1 requests, up to 190 time slices each
Called from: extractr::ed_extract(ed, var = v, sf_zones = ply, bbox = bb, 
    mask_tif = F, rast_tif = glue("{dir_out}/{nms}/{yr}.tif"), 
    zonal_fun = "mean", zonal_csv = glue("{dir_out}/{nms}/{yr}.csv"), 
    dir_nc = glue("{dir_out}/{nms}/{yr}_nc"), keep_nc = F, n_max_vals_per_req = 1e+05, 
    time_min = time_min, time_max = time_max, verbose = T)
debug: while (i_req <= n_reqs) {
    i_t_beg <- (i_req - 1) * n_t_per_req + 1
    i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
    t_req <- times_todo[c(i_t_beg, i_t_end)]
    t_req_str <- format_ISO8601(t_req, usetz = "Z")
    if (verbose) 
        message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
    ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
        ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
        0), nc)
    unlink(ncs0)
    nc_retry <- T
    nc_n_try <- 1
    n_max_retries
    while (nc_retry) {
        res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
            url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
                bbox[["xmax"]]), latitude = c(bbox[["ymin"]], 
                bbox[["ymax"]]), time = t_req_str, fmt = "nc", 
            store = rerddap::disk(path = dir_nc)))
        if (inherits(res, "try-error")) {
            err <- attr(res, "condition")
            msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
            nc_n_try <- nc_n_try + 1
            if (nc_n_try > n_max_retries) {
                stop(msg)
            }
            else {
                message(msg, "\nRETRYing...")
                Sys.sleep(1)
            }
        }
        else {
            nc_retry <- F
        }
    }
    i_req <- i_req + 1
}
debug: i_t_beg <- (i_req - 1) * n_t_per_req + 1
debug: i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
debug: t_req <- times_todo[c(i_t_beg, i_t_end)]
debug: t_req_str <- format_ISO8601(t_req, usetz = "Z")
debug: if (verbose) message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
debug: message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
Fetching request 1 of 1 (2002-01-01 to 2002-12-01) ~ 19:44:03 UTC
debug: ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
    0), nc)
debug: unlink(ncs0)
debug: nc_retry <- T
debug: nc_n_try <- 1
debug: n_max_retries
debug: while (nc_retry) {
    res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
        url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
            bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
        time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
    if (inherits(res, "try-error")) {
        err <- attr(res, "condition")
        msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
        nc_n_try <- nc_n_try + 1
        if (nc_n_try > n_max_retries) {
            stop(msg)
        }
        else {
            message(msg, "\nRETRYing...")
            Sys.sleep(1)
        }
    }
    else {
        nc_retry <- F
    }
}
debug: res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
    url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
        bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
    time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
debug: if (inherits(res, "try-error")) {
    err <- attr(res, "condition")
    msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
    nc_n_try <- nc_n_try + 1
    if (nc_n_try > n_max_retries) {
        stop(msg)
    }
    else {
        message(msg, "\nRETRYing...")
        Sys.sleep(1)
    }
} else {
    nc_retry <- F
}
debug: nc_retry <- F
debug: (while) nc_retry
debug: i_req <- i_req + 1
debug: (while) i_req <= n_reqs
debug: ncs <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size > 
    0), nc)
debug: r <- terra::rast(ncs)
debug: stopifnot(all(class(terra::time(r)) %in% c("POSIXct", "POSIXt")))
debug: idx <- dplyr::pull(dplyr::filter(dplyr::arrange(dplyr::tibble(idx = 1:terra::nlyr(r), 
    time = terra::time(r)), time), !duplicated(time)), idx)
debug: r <- terra::subset(r, idx)
debug: stopifnot(terra::crs(r, proj = T) == wgs84)
debug: if (mask_tif) r <- terra::mask(r, sf_zones)
debug: lyrs <- glue("{var}|{terra::time(r)}")
debug: if (length(dims_other) > 0 && !all(length(dims[dims_other]) == 
    1)) stop(glue("Other dimensions not yet supported: {paste(dims_other, collapse = ',')}"))
debug: names(r) <- lyrs
debug: if (!is.null(rast_tif)) {
    if (fs::file_exists(rast_tif)) {
        r_tmp_tif <- tempfile(fileext = ".tif")
        r_tmp <- c(rast(rast_tif), r)
        r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
        terra::writeRaster(r_tmp, r_tmp_tif)
        fs::file_delete(rast_tif)
        fs::file_move(r_tmp_tif, rast_tif)
        rm(r)
        rm(r_tmp)
    }
    else {
        terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
    }
    r <- terra::rast(rast_tif)
}
debug: if (fs::file_exists(rast_tif)) {
    r_tmp_tif <- tempfile(fileext = ".tif")
    r_tmp <- c(rast(rast_tif), r)
    r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
    terra::writeRaster(r_tmp, r_tmp_tif)
    fs::file_delete(rast_tif)
    fs::file_move(r_tmp_tif, rast_tif)
    rm(r)
    rm(r_tmp)
} else {
    terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
}
debug: terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
debug: r <- terra::rast(rast_tif)
debug: d_r <- mutate(tidyr::pivot_longer(sf::st_drop_geometry(sf::st_as_sf(terra::zonal(x = r, 
    z = terra::vect(dplyr::select(sf_zones, dplyr::all_of(fld_zones))), 
    fun = zonal_fun, exact = T, na.rm = T, as.polygons = T))), 
    cols = -dplyr::any_of(fld_zones), names_to = "lyr", values_to = zonal_fun), 
    time = readr::parse_datetime(str_replace(lyr, glue("{var}\\|(.*)"), 
        "\\1")))
debug: if (!is.null(zonal_csv)) write_csv(d_r, zonal_csv)
debug: write_csv(d_r, zonal_csv)
debug: if (!keep_nc) unlink(dir_nc, recursive = T)
debug: unlink(dir_nc, recursive = T)
debug: return(d_r)
Downloading 1 requests, up to 190 time slices each
Called from: extractr::ed_extract(ed, var = v, sf_zones = ply, bbox = bb, 
    mask_tif = F, rast_tif = glue("{dir_out}/{nms}/{yr}.tif"), 
    zonal_fun = "mean", zonal_csv = glue("{dir_out}/{nms}/{yr}.csv"), 
    dir_nc = glue("{dir_out}/{nms}/{yr}_nc"), keep_nc = F, n_max_vals_per_req = 1e+05, 
    time_min = time_min, time_max = time_max, verbose = T)
debug: while (i_req <= n_reqs) {
    i_t_beg <- (i_req - 1) * n_t_per_req + 1
    i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
    t_req <- times_todo[c(i_t_beg, i_t_end)]
    t_req_str <- format_ISO8601(t_req, usetz = "Z")
    if (verbose) 
        message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
    ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
        ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
        0), nc)
    unlink(ncs0)
    nc_retry <- T
    nc_n_try <- 1
    n_max_retries
    while (nc_retry) {
        res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
            url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
                bbox[["xmax"]]), latitude = c(bbox[["ymin"]], 
                bbox[["ymax"]]), time = t_req_str, fmt = "nc", 
            store = rerddap::disk(path = dir_nc)))
        if (inherits(res, "try-error")) {
            err <- attr(res, "condition")
            msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
            nc_n_try <- nc_n_try + 1
            if (nc_n_try > n_max_retries) {
                stop(msg)
            }
            else {
                message(msg, "\nRETRYing...")
                Sys.sleep(1)
            }
        }
        else {
            nc_retry <- F
        }
    }
    i_req <- i_req + 1
}
debug: i_t_beg <- (i_req - 1) * n_t_per_req + 1
debug: i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
debug: t_req <- times_todo[c(i_t_beg, i_t_end)]
debug: t_req_str <- format_ISO8601(t_req, usetz = "Z")
debug: if (verbose) message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
debug: message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
Fetching request 1 of 1 (2003-01-01 to 2003-12-01) ~ 19:44:05 UTC
debug: ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
    0), nc)
debug: unlink(ncs0)
debug: nc_retry <- T
debug: nc_n_try <- 1
debug: n_max_retries
debug: while (nc_retry) {
    res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
        url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
            bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
        time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
    if (inherits(res, "try-error")) {
        err <- attr(res, "condition")
        msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
        nc_n_try <- nc_n_try + 1
        if (nc_n_try > n_max_retries) {
            stop(msg)
        }
        else {
            message(msg, "\nRETRYing...")
            Sys.sleep(1)
        }
    }
    else {
        nc_retry <- F
    }
}
debug: res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
    url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
        bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
    time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
debug: if (inherits(res, "try-error")) {
    err <- attr(res, "condition")
    msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
    nc_n_try <- nc_n_try + 1
    if (nc_n_try > n_max_retries) {
        stop(msg)
    }
    else {
        message(msg, "\nRETRYing...")
        Sys.sleep(1)
    }
} else {
    nc_retry <- F
}
debug: nc_retry <- F
debug: (while) nc_retry
debug: i_req <- i_req + 1
debug: (while) i_req <= n_reqs
debug: ncs <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size > 
    0), nc)
debug: r <- terra::rast(ncs)
debug: stopifnot(all(class(terra::time(r)) %in% c("POSIXct", "POSIXt")))
debug: idx <- dplyr::pull(dplyr::filter(dplyr::arrange(dplyr::tibble(idx = 1:terra::nlyr(r), 
    time = terra::time(r)), time), !duplicated(time)), idx)
debug: r <- terra::subset(r, idx)
debug: stopifnot(terra::crs(r, proj = T) == wgs84)
debug: if (mask_tif) r <- terra::mask(r, sf_zones)
debug: lyrs <- glue("{var}|{terra::time(r)}")
debug: if (length(dims_other) > 0 && !all(length(dims[dims_other]) == 
    1)) stop(glue("Other dimensions not yet supported: {paste(dims_other, collapse = ',')}"))
debug: names(r) <- lyrs
debug: if (!is.null(rast_tif)) {
    if (fs::file_exists(rast_tif)) {
        r_tmp_tif <- tempfile(fileext = ".tif")
        r_tmp <- c(rast(rast_tif), r)
        r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
        terra::writeRaster(r_tmp, r_tmp_tif)
        fs::file_delete(rast_tif)
        fs::file_move(r_tmp_tif, rast_tif)
        rm(r)
        rm(r_tmp)
    }
    else {
        terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
    }
    r <- terra::rast(rast_tif)
}
debug: if (fs::file_exists(rast_tif)) {
    r_tmp_tif <- tempfile(fileext = ".tif")
    r_tmp <- c(rast(rast_tif), r)
    r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
    terra::writeRaster(r_tmp, r_tmp_tif)
    fs::file_delete(rast_tif)
    fs::file_move(r_tmp_tif, rast_tif)
    rm(r)
    rm(r_tmp)
} else {
    terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
}
debug: terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
debug: r <- terra::rast(rast_tif)
debug: d_r <- mutate(tidyr::pivot_longer(sf::st_drop_geometry(sf::st_as_sf(terra::zonal(x = r, 
    z = terra::vect(dplyr::select(sf_zones, dplyr::all_of(fld_zones))), 
    fun = zonal_fun, exact = T, na.rm = T, as.polygons = T))), 
    cols = -dplyr::any_of(fld_zones), names_to = "lyr", values_to = zonal_fun), 
    time = readr::parse_datetime(str_replace(lyr, glue("{var}\\|(.*)"), 
        "\\1")))
debug: if (!is.null(zonal_csv)) write_csv(d_r, zonal_csv)
debug: write_csv(d_r, zonal_csv)
debug: if (!keep_nc) unlink(dir_nc, recursive = T)
debug: unlink(dir_nc, recursive = T)
debug: return(d_r)
Downloading 1 requests, up to 190 time slices each
Called from: extractr::ed_extract(ed, var = v, sf_zones = ply, bbox = bb, 
    mask_tif = F, rast_tif = glue("{dir_out}/{nms}/{yr}.tif"), 
    zonal_fun = "mean", zonal_csv = glue("{dir_out}/{nms}/{yr}.csv"), 
    dir_nc = glue("{dir_out}/{nms}/{yr}_nc"), keep_nc = F, n_max_vals_per_req = 1e+05, 
    time_min = time_min, time_max = time_max, verbose = T)
debug: while (i_req <= n_reqs) {
    i_t_beg <- (i_req - 1) * n_t_per_req + 1
    i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
    t_req <- times_todo[c(i_t_beg, i_t_end)]
    t_req_str <- format_ISO8601(t_req, usetz = "Z")
    if (verbose) 
        message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
    ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
        ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
        0), nc)
    unlink(ncs0)
    nc_retry <- T
    nc_n_try <- 1
    n_max_retries
    while (nc_retry) {
        res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
            url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
                bbox[["xmax"]]), latitude = c(bbox[["ymin"]], 
                bbox[["ymax"]]), time = t_req_str, fmt = "nc", 
            store = rerddap::disk(path = dir_nc)))
        if (inherits(res, "try-error")) {
            err <- attr(res, "condition")
            msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
            nc_n_try <- nc_n_try + 1
            if (nc_n_try > n_max_retries) {
                stop(msg)
            }
            else {
                message(msg, "\nRETRYing...")
                Sys.sleep(1)
            }
        }
        else {
            nc_retry <- F
        }
    }
    i_req <- i_req + 1
}
debug: i_t_beg <- (i_req - 1) * n_t_per_req + 1
debug: i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
debug: t_req <- times_todo[c(i_t_beg, i_t_end)]
debug: t_req_str <- format_ISO8601(t_req, usetz = "Z")
debug: if (verbose) message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
debug: message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
Fetching request 1 of 1 (2004-01-01 to 2004-12-01) ~ 19:44:07 UTC
debug: ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
    0), nc)
debug: unlink(ncs0)
debug: nc_retry <- T
debug: nc_n_try <- 1
debug: n_max_retries
debug: while (nc_retry) {
    res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
        url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
            bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
        time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
    if (inherits(res, "try-error")) {
        err <- attr(res, "condition")
        msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
        nc_n_try <- nc_n_try + 1
        if (nc_n_try > n_max_retries) {
            stop(msg)
        }
        else {
            message(msg, "\nRETRYing...")
            Sys.sleep(1)
        }
    }
    else {
        nc_retry <- F
    }
}
debug: res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
    url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
        bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
    time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
debug: if (inherits(res, "try-error")) {
    err <- attr(res, "condition")
    msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
    nc_n_try <- nc_n_try + 1
    if (nc_n_try > n_max_retries) {
        stop(msg)
    }
    else {
        message(msg, "\nRETRYing...")
        Sys.sleep(1)
    }
} else {
    nc_retry <- F
}
debug: nc_retry <- F
debug: (while) nc_retry
debug: i_req <- i_req + 1
debug: (while) i_req <= n_reqs
debug: ncs <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size > 
    0), nc)
debug: r <- terra::rast(ncs)
debug: stopifnot(all(class(terra::time(r)) %in% c("POSIXct", "POSIXt")))
debug: idx <- dplyr::pull(dplyr::filter(dplyr::arrange(dplyr::tibble(idx = 1:terra::nlyr(r), 
    time = terra::time(r)), time), !duplicated(time)), idx)
debug: r <- terra::subset(r, idx)
debug: stopifnot(terra::crs(r, proj = T) == wgs84)
debug: if (mask_tif) r <- terra::mask(r, sf_zones)
debug: lyrs <- glue("{var}|{terra::time(r)}")
debug: if (length(dims_other) > 0 && !all(length(dims[dims_other]) == 
    1)) stop(glue("Other dimensions not yet supported: {paste(dims_other, collapse = ',')}"))
debug: names(r) <- lyrs
debug: if (!is.null(rast_tif)) {
    if (fs::file_exists(rast_tif)) {
        r_tmp_tif <- tempfile(fileext = ".tif")
        r_tmp <- c(rast(rast_tif), r)
        r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
        terra::writeRaster(r_tmp, r_tmp_tif)
        fs::file_delete(rast_tif)
        fs::file_move(r_tmp_tif, rast_tif)
        rm(r)
        rm(r_tmp)
    }
    else {
        terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
    }
    r <- terra::rast(rast_tif)
}
debug: if (fs::file_exists(rast_tif)) {
    r_tmp_tif <- tempfile(fileext = ".tif")
    r_tmp <- c(rast(rast_tif), r)
    r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
    terra::writeRaster(r_tmp, r_tmp_tif)
    fs::file_delete(rast_tif)
    fs::file_move(r_tmp_tif, rast_tif)
    rm(r)
    rm(r_tmp)
} else {
    terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
}
debug: terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
debug: r <- terra::rast(rast_tif)
debug: d_r <- mutate(tidyr::pivot_longer(sf::st_drop_geometry(sf::st_as_sf(terra::zonal(x = r, 
    z = terra::vect(dplyr::select(sf_zones, dplyr::all_of(fld_zones))), 
    fun = zonal_fun, exact = T, na.rm = T, as.polygons = T))), 
    cols = -dplyr::any_of(fld_zones), names_to = "lyr", values_to = zonal_fun), 
    time = readr::parse_datetime(str_replace(lyr, glue("{var}\\|(.*)"), 
        "\\1")))
debug: if (!is.null(zonal_csv)) write_csv(d_r, zonal_csv)
debug: write_csv(d_r, zonal_csv)
debug: if (!keep_nc) unlink(dir_nc, recursive = T)
debug: unlink(dir_nc, recursive = T)
debug: return(d_r)
Downloading 1 requests, up to 190 time slices each
Called from: extractr::ed_extract(ed, var = v, sf_zones = ply, bbox = bb, 
    mask_tif = F, rast_tif = glue("{dir_out}/{nms}/{yr}.tif"), 
    zonal_fun = "mean", zonal_csv = glue("{dir_out}/{nms}/{yr}.csv"), 
    dir_nc = glue("{dir_out}/{nms}/{yr}_nc"), keep_nc = F, n_max_vals_per_req = 1e+05, 
    time_min = time_min, time_max = time_max, verbose = T)
debug: while (i_req <= n_reqs) {
    i_t_beg <- (i_req - 1) * n_t_per_req + 1
    i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
    t_req <- times_todo[c(i_t_beg, i_t_end)]
    t_req_str <- format_ISO8601(t_req, usetz = "Z")
    if (verbose) 
        message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
    ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
        ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
        0), nc)
    unlink(ncs0)
    nc_retry <- T
    nc_n_try <- 1
    n_max_retries
    while (nc_retry) {
        res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
            url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
                bbox[["xmax"]]), latitude = c(bbox[["ymin"]], 
                bbox[["ymax"]]), time = t_req_str, fmt = "nc", 
            store = rerddap::disk(path = dir_nc)))
        if (inherits(res, "try-error")) {
            err <- attr(res, "condition")
            msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
            nc_n_try <- nc_n_try + 1
            if (nc_n_try > n_max_retries) {
                stop(msg)
            }
            else {
                message(msg, "\nRETRYing...")
                Sys.sleep(1)
            }
        }
        else {
            nc_retry <- F
        }
    }
    i_req <- i_req + 1
}
debug: i_t_beg <- (i_req - 1) * n_t_per_req + 1
debug: i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
debug: t_req <- times_todo[c(i_t_beg, i_t_end)]
debug: t_req_str <- format_ISO8601(t_req, usetz = "Z")
debug: if (verbose) message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
debug: message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
Fetching request 1 of 1 (2005-01-01 to 2005-12-01) ~ 19:44:09 UTC
debug: ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
    0), nc)
debug: unlink(ncs0)
debug: nc_retry <- T
debug: nc_n_try <- 1
debug: n_max_retries
debug: while (nc_retry) {
    res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
        url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
            bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
        time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
    if (inherits(res, "try-error")) {
        err <- attr(res, "condition")
        msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
        nc_n_try <- nc_n_try + 1
        if (nc_n_try > n_max_retries) {
            stop(msg)
        }
        else {
            message(msg, "\nRETRYing...")
            Sys.sleep(1)
        }
    }
    else {
        nc_retry <- F
    }
}
debug: res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
    url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
        bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
    time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
debug: if (inherits(res, "try-error")) {
    err <- attr(res, "condition")
    msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
    nc_n_try <- nc_n_try + 1
    if (nc_n_try > n_max_retries) {
        stop(msg)
    }
    else {
        message(msg, "\nRETRYing...")
        Sys.sleep(1)
    }
} else {
    nc_retry <- F
}
debug: nc_retry <- F
debug: (while) nc_retry
debug: i_req <- i_req + 1
debug: (while) i_req <= n_reqs
debug: ncs <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size > 
    0), nc)
debug: r <- terra::rast(ncs)
debug: stopifnot(all(class(terra::time(r)) %in% c("POSIXct", "POSIXt")))
debug: idx <- dplyr::pull(dplyr::filter(dplyr::arrange(dplyr::tibble(idx = 1:terra::nlyr(r), 
    time = terra::time(r)), time), !duplicated(time)), idx)
debug: r <- terra::subset(r, idx)
debug: stopifnot(terra::crs(r, proj = T) == wgs84)
debug: if (mask_tif) r <- terra::mask(r, sf_zones)
debug: lyrs <- glue("{var}|{terra::time(r)}")
debug: if (length(dims_other) > 0 && !all(length(dims[dims_other]) == 
    1)) stop(glue("Other dimensions not yet supported: {paste(dims_other, collapse = ',')}"))
debug: names(r) <- lyrs
debug: if (!is.null(rast_tif)) {
    if (fs::file_exists(rast_tif)) {
        r_tmp_tif <- tempfile(fileext = ".tif")
        r_tmp <- c(rast(rast_tif), r)
        r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
        terra::writeRaster(r_tmp, r_tmp_tif)
        fs::file_delete(rast_tif)
        fs::file_move(r_tmp_tif, rast_tif)
        rm(r)
        rm(r_tmp)
    }
    else {
        terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
    }
    r <- terra::rast(rast_tif)
}
debug: if (fs::file_exists(rast_tif)) {
    r_tmp_tif <- tempfile(fileext = ".tif")
    r_tmp <- c(rast(rast_tif), r)
    r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
    terra::writeRaster(r_tmp, r_tmp_tif)
    fs::file_delete(rast_tif)
    fs::file_move(r_tmp_tif, rast_tif)
    rm(r)
    rm(r_tmp)
} else {
    terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
}
debug: terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
debug: r <- terra::rast(rast_tif)
debug: d_r <- mutate(tidyr::pivot_longer(sf::st_drop_geometry(sf::st_as_sf(terra::zonal(x = r, 
    z = terra::vect(dplyr::select(sf_zones, dplyr::all_of(fld_zones))), 
    fun = zonal_fun, exact = T, na.rm = T, as.polygons = T))), 
    cols = -dplyr::any_of(fld_zones), names_to = "lyr", values_to = zonal_fun), 
    time = readr::parse_datetime(str_replace(lyr, glue("{var}\\|(.*)"), 
        "\\1")))
debug: if (!is.null(zonal_csv)) write_csv(d_r, zonal_csv)
debug: write_csv(d_r, zonal_csv)
debug: if (!keep_nc) unlink(dir_nc, recursive = T)
debug: unlink(dir_nc, recursive = T)
debug: return(d_r)
Downloading 1 requests, up to 190 time slices each
Called from: extractr::ed_extract(ed, var = v, sf_zones = ply, bbox = bb, 
    mask_tif = F, rast_tif = glue("{dir_out}/{nms}/{yr}.tif"), 
    zonal_fun = "mean", zonal_csv = glue("{dir_out}/{nms}/{yr}.csv"), 
    dir_nc = glue("{dir_out}/{nms}/{yr}_nc"), keep_nc = F, n_max_vals_per_req = 1e+05, 
    time_min = time_min, time_max = time_max, verbose = T)
debug: while (i_req <= n_reqs) {
    i_t_beg <- (i_req - 1) * n_t_per_req + 1
    i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
    t_req <- times_todo[c(i_t_beg, i_t_end)]
    t_req_str <- format_ISO8601(t_req, usetz = "Z")
    if (verbose) 
        message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
    ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
        ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
        0), nc)
    unlink(ncs0)
    nc_retry <- T
    nc_n_try <- 1
    n_max_retries
    while (nc_retry) {
        res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
            url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
                bbox[["xmax"]]), latitude = c(bbox[["ymin"]], 
                bbox[["ymax"]]), time = t_req_str, fmt = "nc", 
            store = rerddap::disk(path = dir_nc)))
        if (inherits(res, "try-error")) {
            err <- attr(res, "condition")
            msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
            nc_n_try <- nc_n_try + 1
            if (nc_n_try > n_max_retries) {
                stop(msg)
            }
            else {
                message(msg, "\nRETRYing...")
                Sys.sleep(1)
            }
        }
        else {
            nc_retry <- F
        }
    }
    i_req <- i_req + 1
}
debug: i_t_beg <- (i_req - 1) * n_t_per_req + 1
debug: i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
debug: t_req <- times_todo[c(i_t_beg, i_t_end)]
debug: t_req_str <- format_ISO8601(t_req, usetz = "Z")
debug: if (verbose) message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
debug: message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
Fetching request 1 of 1 (2006-01-01 to 2006-12-01) ~ 19:44:11 UTC
debug: ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
    0), nc)
debug: unlink(ncs0)
debug: nc_retry <- T
debug: nc_n_try <- 1
debug: n_max_retries
debug: while (nc_retry) {
    res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
        url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
            bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
        time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
    if (inherits(res, "try-error")) {
        err <- attr(res, "condition")
        msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
        nc_n_try <- nc_n_try + 1
        if (nc_n_try > n_max_retries) {
            stop(msg)
        }
        else {
            message(msg, "\nRETRYing...")
            Sys.sleep(1)
        }
    }
    else {
        nc_retry <- F
    }
}
debug: res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
    url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
        bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
    time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
debug: if (inherits(res, "try-error")) {
    err <- attr(res, "condition")
    msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
    nc_n_try <- nc_n_try + 1
    if (nc_n_try > n_max_retries) {
        stop(msg)
    }
    else {
        message(msg, "\nRETRYing...")
        Sys.sleep(1)
    }
} else {
    nc_retry <- F
}
debug: nc_retry <- F
debug: (while) nc_retry
debug: i_req <- i_req + 1
debug: (while) i_req <= n_reqs
debug: ncs <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size > 
    0), nc)
debug: r <- terra::rast(ncs)
debug: stopifnot(all(class(terra::time(r)) %in% c("POSIXct", "POSIXt")))
debug: idx <- dplyr::pull(dplyr::filter(dplyr::arrange(dplyr::tibble(idx = 1:terra::nlyr(r), 
    time = terra::time(r)), time), !duplicated(time)), idx)
debug: r <- terra::subset(r, idx)
debug: stopifnot(terra::crs(r, proj = T) == wgs84)
debug: if (mask_tif) r <- terra::mask(r, sf_zones)
debug: lyrs <- glue("{var}|{terra::time(r)}")
debug: if (length(dims_other) > 0 && !all(length(dims[dims_other]) == 
    1)) stop(glue("Other dimensions not yet supported: {paste(dims_other, collapse = ',')}"))
debug: names(r) <- lyrs
debug: if (!is.null(rast_tif)) {
    if (fs::file_exists(rast_tif)) {
        r_tmp_tif <- tempfile(fileext = ".tif")
        r_tmp <- c(rast(rast_tif), r)
        r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
        terra::writeRaster(r_tmp, r_tmp_tif)
        fs::file_delete(rast_tif)
        fs::file_move(r_tmp_tif, rast_tif)
        rm(r)
        rm(r_tmp)
    }
    else {
        terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
    }
    r <- terra::rast(rast_tif)
}
debug: if (fs::file_exists(rast_tif)) {
    r_tmp_tif <- tempfile(fileext = ".tif")
    r_tmp <- c(rast(rast_tif), r)
    r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
    terra::writeRaster(r_tmp, r_tmp_tif)
    fs::file_delete(rast_tif)
    fs::file_move(r_tmp_tif, rast_tif)
    rm(r)
    rm(r_tmp)
} else {
    terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
}
debug: terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
debug: r <- terra::rast(rast_tif)
debug: d_r <- mutate(tidyr::pivot_longer(sf::st_drop_geometry(sf::st_as_sf(terra::zonal(x = r, 
    z = terra::vect(dplyr::select(sf_zones, dplyr::all_of(fld_zones))), 
    fun = zonal_fun, exact = T, na.rm = T, as.polygons = T))), 
    cols = -dplyr::any_of(fld_zones), names_to = "lyr", values_to = zonal_fun), 
    time = readr::parse_datetime(str_replace(lyr, glue("{var}\\|(.*)"), 
        "\\1")))
debug: if (!is.null(zonal_csv)) write_csv(d_r, zonal_csv)
debug: write_csv(d_r, zonal_csv)
debug: if (!keep_nc) unlink(dir_nc, recursive = T)
debug: unlink(dir_nc, recursive = T)
debug: return(d_r)
Downloading 1 requests, up to 190 time slices each
Called from: extractr::ed_extract(ed, var = v, sf_zones = ply, bbox = bb, 
    mask_tif = F, rast_tif = glue("{dir_out}/{nms}/{yr}.tif"), 
    zonal_fun = "mean", zonal_csv = glue("{dir_out}/{nms}/{yr}.csv"), 
    dir_nc = glue("{dir_out}/{nms}/{yr}_nc"), keep_nc = F, n_max_vals_per_req = 1e+05, 
    time_min = time_min, time_max = time_max, verbose = T)
debug: while (i_req <= n_reqs) {
    i_t_beg <- (i_req - 1) * n_t_per_req + 1
    i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
    t_req <- times_todo[c(i_t_beg, i_t_end)]
    t_req_str <- format_ISO8601(t_req, usetz = "Z")
    if (verbose) 
        message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
    ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
        ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
        0), nc)
    unlink(ncs0)
    nc_retry <- T
    nc_n_try <- 1
    n_max_retries
    while (nc_retry) {
        res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
            url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
                bbox[["xmax"]]), latitude = c(bbox[["ymin"]], 
                bbox[["ymax"]]), time = t_req_str, fmt = "nc", 
            store = rerddap::disk(path = dir_nc)))
        if (inherits(res, "try-error")) {
            err <- attr(res, "condition")
            msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
            nc_n_try <- nc_n_try + 1
            if (nc_n_try > n_max_retries) {
                stop(msg)
            }
            else {
                message(msg, "\nRETRYing...")
                Sys.sleep(1)
            }
        }
        else {
            nc_retry <- F
        }
    }
    i_req <- i_req + 1
}
debug: i_t_beg <- (i_req - 1) * n_t_per_req + 1
debug: i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
debug: t_req <- times_todo[c(i_t_beg, i_t_end)]
debug: t_req_str <- format_ISO8601(t_req, usetz = "Z")
debug: if (verbose) message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
debug: message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
Fetching request 1 of 1 (2007-01-01 to 2007-12-01) ~ 19:44:13 UTC
debug: ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
    0), nc)
debug: unlink(ncs0)
debug: nc_retry <- T
debug: nc_n_try <- 1
debug: n_max_retries
debug: while (nc_retry) {
    res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
        url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
            bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
        time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
    if (inherits(res, "try-error")) {
        err <- attr(res, "condition")
        msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
        nc_n_try <- nc_n_try + 1
        if (nc_n_try > n_max_retries) {
            stop(msg)
        }
        else {
            message(msg, "\nRETRYing...")
            Sys.sleep(1)
        }
    }
    else {
        nc_retry <- F
    }
}
debug: res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
    url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
        bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
    time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
debug: if (inherits(res, "try-error")) {
    err <- attr(res, "condition")
    msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
    nc_n_try <- nc_n_try + 1
    if (nc_n_try > n_max_retries) {
        stop(msg)
    }
    else {
        message(msg, "\nRETRYing...")
        Sys.sleep(1)
    }
} else {
    nc_retry <- F
}
debug: nc_retry <- F
debug: (while) nc_retry
debug: i_req <- i_req + 1
debug: (while) i_req <= n_reqs
debug: ncs <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size > 
    0), nc)
debug: r <- terra::rast(ncs)
debug: stopifnot(all(class(terra::time(r)) %in% c("POSIXct", "POSIXt")))
debug: idx <- dplyr::pull(dplyr::filter(dplyr::arrange(dplyr::tibble(idx = 1:terra::nlyr(r), 
    time = terra::time(r)), time), !duplicated(time)), idx)
debug: r <- terra::subset(r, idx)
debug: stopifnot(terra::crs(r, proj = T) == wgs84)
debug: if (mask_tif) r <- terra::mask(r, sf_zones)
debug: lyrs <- glue("{var}|{terra::time(r)}")
debug: if (length(dims_other) > 0 && !all(length(dims[dims_other]) == 
    1)) stop(glue("Other dimensions not yet supported: {paste(dims_other, collapse = ',')}"))
debug: names(r) <- lyrs
debug: if (!is.null(rast_tif)) {
    if (fs::file_exists(rast_tif)) {
        r_tmp_tif <- tempfile(fileext = ".tif")
        r_tmp <- c(rast(rast_tif), r)
        r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
        terra::writeRaster(r_tmp, r_tmp_tif)
        fs::file_delete(rast_tif)
        fs::file_move(r_tmp_tif, rast_tif)
        rm(r)
        rm(r_tmp)
    }
    else {
        terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
    }
    r <- terra::rast(rast_tif)
}
debug: if (fs::file_exists(rast_tif)) {
    r_tmp_tif <- tempfile(fileext = ".tif")
    r_tmp <- c(rast(rast_tif), r)
    r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
    terra::writeRaster(r_tmp, r_tmp_tif)
    fs::file_delete(rast_tif)
    fs::file_move(r_tmp_tif, rast_tif)
    rm(r)
    rm(r_tmp)
} else {
    terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
}
debug: terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
debug: r <- terra::rast(rast_tif)
debug: d_r <- mutate(tidyr::pivot_longer(sf::st_drop_geometry(sf::st_as_sf(terra::zonal(x = r, 
    z = terra::vect(dplyr::select(sf_zones, dplyr::all_of(fld_zones))), 
    fun = zonal_fun, exact = T, na.rm = T, as.polygons = T))), 
    cols = -dplyr::any_of(fld_zones), names_to = "lyr", values_to = zonal_fun), 
    time = readr::parse_datetime(str_replace(lyr, glue("{var}\\|(.*)"), 
        "\\1")))
debug: if (!is.null(zonal_csv)) write_csv(d_r, zonal_csv)
debug: write_csv(d_r, zonal_csv)
debug: if (!keep_nc) unlink(dir_nc, recursive = T)
debug: unlink(dir_nc, recursive = T)
debug: return(d_r)
Downloading 1 requests, up to 190 time slices each
Called from: extractr::ed_extract(ed, var = v, sf_zones = ply, bbox = bb, 
    mask_tif = F, rast_tif = glue("{dir_out}/{nms}/{yr}.tif"), 
    zonal_fun = "mean", zonal_csv = glue("{dir_out}/{nms}/{yr}.csv"), 
    dir_nc = glue("{dir_out}/{nms}/{yr}_nc"), keep_nc = F, n_max_vals_per_req = 1e+05, 
    time_min = time_min, time_max = time_max, verbose = T)
debug: while (i_req <= n_reqs) {
    i_t_beg <- (i_req - 1) * n_t_per_req + 1
    i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
    t_req <- times_todo[c(i_t_beg, i_t_end)]
    t_req_str <- format_ISO8601(t_req, usetz = "Z")
    if (verbose) 
        message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
    ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
        ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
        0), nc)
    unlink(ncs0)
    nc_retry <- T
    nc_n_try <- 1
    n_max_retries
    while (nc_retry) {
        res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
            url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
                bbox[["xmax"]]), latitude = c(bbox[["ymin"]], 
                bbox[["ymax"]]), time = t_req_str, fmt = "nc", 
            store = rerddap::disk(path = dir_nc)))
        if (inherits(res, "try-error")) {
            err <- attr(res, "condition")
            msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
            nc_n_try <- nc_n_try + 1
            if (nc_n_try > n_max_retries) {
                stop(msg)
            }
            else {
                message(msg, "\nRETRYing...")
                Sys.sleep(1)
            }
        }
        else {
            nc_retry <- F
        }
    }
    i_req <- i_req + 1
}
debug: i_t_beg <- (i_req - 1) * n_t_per_req + 1
debug: i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
debug: t_req <- times_todo[c(i_t_beg, i_t_end)]
debug: t_req_str <- format_ISO8601(t_req, usetz = "Z")
debug: if (verbose) message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
debug: message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
Fetching request 1 of 1 (2008-01-01 to 2008-12-01) ~ 19:44:14 UTC
debug: ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
    0), nc)
debug: unlink(ncs0)
debug: nc_retry <- T
debug: nc_n_try <- 1
debug: n_max_retries
debug: while (nc_retry) {
    res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
        url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
            bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
        time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
    if (inherits(res, "try-error")) {
        err <- attr(res, "condition")
        msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
        nc_n_try <- nc_n_try + 1
        if (nc_n_try > n_max_retries) {
            stop(msg)
        }
        else {
            message(msg, "\nRETRYing...")
            Sys.sleep(1)
        }
    }
    else {
        nc_retry <- F
    }
}
debug: res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
    url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
        bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
    time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
debug: if (inherits(res, "try-error")) {
    err <- attr(res, "condition")
    msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
    nc_n_try <- nc_n_try + 1
    if (nc_n_try > n_max_retries) {
        stop(msg)
    }
    else {
        message(msg, "\nRETRYing...")
        Sys.sleep(1)
    }
} else {
    nc_retry <- F
}
debug: nc_retry <- F
debug: (while) nc_retry
debug: i_req <- i_req + 1
debug: (while) i_req <= n_reqs
debug: ncs <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size > 
    0), nc)
debug: r <- terra::rast(ncs)
debug: stopifnot(all(class(terra::time(r)) %in% c("POSIXct", "POSIXt")))
debug: idx <- dplyr::pull(dplyr::filter(dplyr::arrange(dplyr::tibble(idx = 1:terra::nlyr(r), 
    time = terra::time(r)), time), !duplicated(time)), idx)
debug: r <- terra::subset(r, idx)
debug: stopifnot(terra::crs(r, proj = T) == wgs84)
debug: if (mask_tif) r <- terra::mask(r, sf_zones)
debug: lyrs <- glue("{var}|{terra::time(r)}")
debug: if (length(dims_other) > 0 && !all(length(dims[dims_other]) == 
    1)) stop(glue("Other dimensions not yet supported: {paste(dims_other, collapse = ',')}"))
debug: names(r) <- lyrs
debug: if (!is.null(rast_tif)) {
    if (fs::file_exists(rast_tif)) {
        r_tmp_tif <- tempfile(fileext = ".tif")
        r_tmp <- c(rast(rast_tif), r)
        r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
        terra::writeRaster(r_tmp, r_tmp_tif)
        fs::file_delete(rast_tif)
        fs::file_move(r_tmp_tif, rast_tif)
        rm(r)
        rm(r_tmp)
    }
    else {
        terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
    }
    r <- terra::rast(rast_tif)
}
debug: if (fs::file_exists(rast_tif)) {
    r_tmp_tif <- tempfile(fileext = ".tif")
    r_tmp <- c(rast(rast_tif), r)
    r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
    terra::writeRaster(r_tmp, r_tmp_tif)
    fs::file_delete(rast_tif)
    fs::file_move(r_tmp_tif, rast_tif)
    rm(r)
    rm(r_tmp)
} else {
    terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
}
debug: terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
debug: r <- terra::rast(rast_tif)
debug: d_r <- mutate(tidyr::pivot_longer(sf::st_drop_geometry(sf::st_as_sf(terra::zonal(x = r, 
    z = terra::vect(dplyr::select(sf_zones, dplyr::all_of(fld_zones))), 
    fun = zonal_fun, exact = T, na.rm = T, as.polygons = T))), 
    cols = -dplyr::any_of(fld_zones), names_to = "lyr", values_to = zonal_fun), 
    time = readr::parse_datetime(str_replace(lyr, glue("{var}\\|(.*)"), 
        "\\1")))
debug: if (!is.null(zonal_csv)) write_csv(d_r, zonal_csv)
debug: write_csv(d_r, zonal_csv)
debug: if (!keep_nc) unlink(dir_nc, recursive = T)
debug: unlink(dir_nc, recursive = T)
debug: return(d_r)
Downloading 1 requests, up to 190 time slices each
Called from: extractr::ed_extract(ed, var = v, sf_zones = ply, bbox = bb, 
    mask_tif = F, rast_tif = glue("{dir_out}/{nms}/{yr}.tif"), 
    zonal_fun = "mean", zonal_csv = glue("{dir_out}/{nms}/{yr}.csv"), 
    dir_nc = glue("{dir_out}/{nms}/{yr}_nc"), keep_nc = F, n_max_vals_per_req = 1e+05, 
    time_min = time_min, time_max = time_max, verbose = T)
debug: while (i_req <= n_reqs) {
    i_t_beg <- (i_req - 1) * n_t_per_req + 1
    i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
    t_req <- times_todo[c(i_t_beg, i_t_end)]
    t_req_str <- format_ISO8601(t_req, usetz = "Z")
    if (verbose) 
        message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
    ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
        ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
        0), nc)
    unlink(ncs0)
    nc_retry <- T
    nc_n_try <- 1
    n_max_retries
    while (nc_retry) {
        res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
            url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
                bbox[["xmax"]]), latitude = c(bbox[["ymin"]], 
                bbox[["ymax"]]), time = t_req_str, fmt = "nc", 
            store = rerddap::disk(path = dir_nc)))
        if (inherits(res, "try-error")) {
            err <- attr(res, "condition")
            msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
            nc_n_try <- nc_n_try + 1
            if (nc_n_try > n_max_retries) {
                stop(msg)
            }
            else {
                message(msg, "\nRETRYing...")
                Sys.sleep(1)
            }
        }
        else {
            nc_retry <- F
        }
    }
    i_req <- i_req + 1
}
debug: i_t_beg <- (i_req - 1) * n_t_per_req + 1
debug: i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
debug: t_req <- times_todo[c(i_t_beg, i_t_end)]
debug: t_req_str <- format_ISO8601(t_req, usetz = "Z")
debug: if (verbose) message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
debug: message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
Fetching request 1 of 1 (2009-01-01 to 2009-12-01) ~ 19:44:16 UTC
debug: ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
    0), nc)
debug: unlink(ncs0)
debug: nc_retry <- T
debug: nc_n_try <- 1
debug: n_max_retries
debug: while (nc_retry) {
    res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
        url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
            bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
        time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
    if (inherits(res, "try-error")) {
        err <- attr(res, "condition")
        msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
        nc_n_try <- nc_n_try + 1
        if (nc_n_try > n_max_retries) {
            stop(msg)
        }
        else {
            message(msg, "\nRETRYing...")
            Sys.sleep(1)
        }
    }
    else {
        nc_retry <- F
    }
}
debug: res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
    url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
        bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
    time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
debug: if (inherits(res, "try-error")) {
    err <- attr(res, "condition")
    msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
    nc_n_try <- nc_n_try + 1
    if (nc_n_try > n_max_retries) {
        stop(msg)
    }
    else {
        message(msg, "\nRETRYing...")
        Sys.sleep(1)
    }
} else {
    nc_retry <- F
}
debug: nc_retry <- F
debug: (while) nc_retry
debug: i_req <- i_req + 1
debug: (while) i_req <= n_reqs
debug: ncs <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size > 
    0), nc)
debug: r <- terra::rast(ncs)
debug: stopifnot(all(class(terra::time(r)) %in% c("POSIXct", "POSIXt")))
debug: idx <- dplyr::pull(dplyr::filter(dplyr::arrange(dplyr::tibble(idx = 1:terra::nlyr(r), 
    time = terra::time(r)), time), !duplicated(time)), idx)
debug: r <- terra::subset(r, idx)
debug: stopifnot(terra::crs(r, proj = T) == wgs84)
debug: if (mask_tif) r <- terra::mask(r, sf_zones)
debug: lyrs <- glue("{var}|{terra::time(r)}")
debug: if (length(dims_other) > 0 && !all(length(dims[dims_other]) == 
    1)) stop(glue("Other dimensions not yet supported: {paste(dims_other, collapse = ',')}"))
debug: names(r) <- lyrs
debug: if (!is.null(rast_tif)) {
    if (fs::file_exists(rast_tif)) {
        r_tmp_tif <- tempfile(fileext = ".tif")
        r_tmp <- c(rast(rast_tif), r)
        r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
        terra::writeRaster(r_tmp, r_tmp_tif)
        fs::file_delete(rast_tif)
        fs::file_move(r_tmp_tif, rast_tif)
        rm(r)
        rm(r_tmp)
    }
    else {
        terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
    }
    r <- terra::rast(rast_tif)
}
debug: if (fs::file_exists(rast_tif)) {
    r_tmp_tif <- tempfile(fileext = ".tif")
    r_tmp <- c(rast(rast_tif), r)
    r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
    terra::writeRaster(r_tmp, r_tmp_tif)
    fs::file_delete(rast_tif)
    fs::file_move(r_tmp_tif, rast_tif)
    rm(r)
    rm(r_tmp)
} else {
    terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
}
debug: terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
debug: r <- terra::rast(rast_tif)
debug: d_r <- mutate(tidyr::pivot_longer(sf::st_drop_geometry(sf::st_as_sf(terra::zonal(x = r, 
    z = terra::vect(dplyr::select(sf_zones, dplyr::all_of(fld_zones))), 
    fun = zonal_fun, exact = T, na.rm = T, as.polygons = T))), 
    cols = -dplyr::any_of(fld_zones), names_to = "lyr", values_to = zonal_fun), 
    time = readr::parse_datetime(str_replace(lyr, glue("{var}\\|(.*)"), 
        "\\1")))
debug: if (!is.null(zonal_csv)) write_csv(d_r, zonal_csv)
debug: write_csv(d_r, zonal_csv)
debug: if (!keep_nc) unlink(dir_nc, recursive = T)
debug: unlink(dir_nc, recursive = T)
debug: return(d_r)
Downloading 1 requests, up to 190 time slices each
Called from: extractr::ed_extract(ed, var = v, sf_zones = ply, bbox = bb, 
    mask_tif = F, rast_tif = glue("{dir_out}/{nms}/{yr}.tif"), 
    zonal_fun = "mean", zonal_csv = glue("{dir_out}/{nms}/{yr}.csv"), 
    dir_nc = glue("{dir_out}/{nms}/{yr}_nc"), keep_nc = F, n_max_vals_per_req = 1e+05, 
    time_min = time_min, time_max = time_max, verbose = T)
debug: while (i_req <= n_reqs) {
    i_t_beg <- (i_req - 1) * n_t_per_req + 1
    i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
    t_req <- times_todo[c(i_t_beg, i_t_end)]
    t_req_str <- format_ISO8601(t_req, usetz = "Z")
    if (verbose) 
        message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
    ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
        ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
        0), nc)
    unlink(ncs0)
    nc_retry <- T
    nc_n_try <- 1
    n_max_retries
    while (nc_retry) {
        res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
            url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
                bbox[["xmax"]]), latitude = c(bbox[["ymin"]], 
                bbox[["ymax"]]), time = t_req_str, fmt = "nc", 
            store = rerddap::disk(path = dir_nc)))
        if (inherits(res, "try-error")) {
            err <- attr(res, "condition")
            msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
            nc_n_try <- nc_n_try + 1
            if (nc_n_try > n_max_retries) {
                stop(msg)
            }
            else {
                message(msg, "\nRETRYing...")
                Sys.sleep(1)
            }
        }
        else {
            nc_retry <- F
        }
    }
    i_req <- i_req + 1
}
debug: i_t_beg <- (i_req - 1) * n_t_per_req + 1
debug: i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
debug: t_req <- times_todo[c(i_t_beg, i_t_end)]
debug: t_req_str <- format_ISO8601(t_req, usetz = "Z")
debug: if (verbose) message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
debug: message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
Fetching request 1 of 1 (2010-01-01 to 2010-12-01) ~ 19:44:18 UTC
debug: ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
    0), nc)
debug: unlink(ncs0)
debug: nc_retry <- T
debug: nc_n_try <- 1
debug: n_max_retries
debug: while (nc_retry) {
    res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
        url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
            bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
        time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
    if (inherits(res, "try-error")) {
        err <- attr(res, "condition")
        msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
        nc_n_try <- nc_n_try + 1
        if (nc_n_try > n_max_retries) {
            stop(msg)
        }
        else {
            message(msg, "\nRETRYing...")
            Sys.sleep(1)
        }
    }
    else {
        nc_retry <- F
    }
}
debug: res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
    url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
        bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
    time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
debug: if (inherits(res, "try-error")) {
    err <- attr(res, "condition")
    msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
    nc_n_try <- nc_n_try + 1
    if (nc_n_try > n_max_retries) {
        stop(msg)
    }
    else {
        message(msg, "\nRETRYing...")
        Sys.sleep(1)
    }
} else {
    nc_retry <- F
}
debug: nc_retry <- F
debug: (while) nc_retry
debug: i_req <- i_req + 1
debug: (while) i_req <= n_reqs
debug: ncs <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size > 
    0), nc)
debug: r <- terra::rast(ncs)
debug: stopifnot(all(class(terra::time(r)) %in% c("POSIXct", "POSIXt")))
debug: idx <- dplyr::pull(dplyr::filter(dplyr::arrange(dplyr::tibble(idx = 1:terra::nlyr(r), 
    time = terra::time(r)), time), !duplicated(time)), idx)
debug: r <- terra::subset(r, idx)
debug: stopifnot(terra::crs(r, proj = T) == wgs84)
debug: if (mask_tif) r <- terra::mask(r, sf_zones)
debug: lyrs <- glue("{var}|{terra::time(r)}")
debug: if (length(dims_other) > 0 && !all(length(dims[dims_other]) == 
    1)) stop(glue("Other dimensions not yet supported: {paste(dims_other, collapse = ',')}"))
debug: names(r) <- lyrs
debug: if (!is.null(rast_tif)) {
    if (fs::file_exists(rast_tif)) {
        r_tmp_tif <- tempfile(fileext = ".tif")
        r_tmp <- c(rast(rast_tif), r)
        r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
        terra::writeRaster(r_tmp, r_tmp_tif)
        fs::file_delete(rast_tif)
        fs::file_move(r_tmp_tif, rast_tif)
        rm(r)
        rm(r_tmp)
    }
    else {
        terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
    }
    r <- terra::rast(rast_tif)
}
debug: if (fs::file_exists(rast_tif)) {
    r_tmp_tif <- tempfile(fileext = ".tif")
    r_tmp <- c(rast(rast_tif), r)
    r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
    terra::writeRaster(r_tmp, r_tmp_tif)
    fs::file_delete(rast_tif)
    fs::file_move(r_tmp_tif, rast_tif)
    rm(r)
    rm(r_tmp)
} else {
    terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
}
debug: terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
debug: r <- terra::rast(rast_tif)
debug: d_r <- mutate(tidyr::pivot_longer(sf::st_drop_geometry(sf::st_as_sf(terra::zonal(x = r, 
    z = terra::vect(dplyr::select(sf_zones, dplyr::all_of(fld_zones))), 
    fun = zonal_fun, exact = T, na.rm = T, as.polygons = T))), 
    cols = -dplyr::any_of(fld_zones), names_to = "lyr", values_to = zonal_fun), 
    time = readr::parse_datetime(str_replace(lyr, glue("{var}\\|(.*)"), 
        "\\1")))
debug: if (!is.null(zonal_csv)) write_csv(d_r, zonal_csv)
debug: write_csv(d_r, zonal_csv)
debug: if (!keep_nc) unlink(dir_nc, recursive = T)
debug: unlink(dir_nc, recursive = T)
debug: return(d_r)
Downloading 1 requests, up to 190 time slices each
Called from: extractr::ed_extract(ed, var = v, sf_zones = ply, bbox = bb, 
    mask_tif = F, rast_tif = glue("{dir_out}/{nms}/{yr}.tif"), 
    zonal_fun = "mean", zonal_csv = glue("{dir_out}/{nms}/{yr}.csv"), 
    dir_nc = glue("{dir_out}/{nms}/{yr}_nc"), keep_nc = F, n_max_vals_per_req = 1e+05, 
    time_min = time_min, time_max = time_max, verbose = T)
debug: while (i_req <= n_reqs) {
    i_t_beg <- (i_req - 1) * n_t_per_req + 1
    i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
    t_req <- times_todo[c(i_t_beg, i_t_end)]
    t_req_str <- format_ISO8601(t_req, usetz = "Z")
    if (verbose) 
        message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
    ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
        ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
        0), nc)
    unlink(ncs0)
    nc_retry <- T
    nc_n_try <- 1
    n_max_retries
    while (nc_retry) {
        res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
            url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
                bbox[["xmax"]]), latitude = c(bbox[["ymin"]], 
                bbox[["ymax"]]), time = t_req_str, fmt = "nc", 
            store = rerddap::disk(path = dir_nc)))
        if (inherits(res, "try-error")) {
            err <- attr(res, "condition")
            msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
            nc_n_try <- nc_n_try + 1
            if (nc_n_try > n_max_retries) {
                stop(msg)
            }
            else {
                message(msg, "\nRETRYing...")
                Sys.sleep(1)
            }
        }
        else {
            nc_retry <- F
        }
    }
    i_req <- i_req + 1
}
debug: i_t_beg <- (i_req - 1) * n_t_per_req + 1
debug: i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
debug: t_req <- times_todo[c(i_t_beg, i_t_end)]
debug: t_req_str <- format_ISO8601(t_req, usetz = "Z")
debug: if (verbose) message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
debug: message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
Fetching request 1 of 1 (2011-01-01 to 2011-12-01) ~ 19:44:20 UTC
debug: ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
    0), nc)
debug: unlink(ncs0)
debug: nc_retry <- T
debug: nc_n_try <- 1
debug: n_max_retries
debug: while (nc_retry) {
    res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
        url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
            bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
        time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
    if (inherits(res, "try-error")) {
        err <- attr(res, "condition")
        msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
        nc_n_try <- nc_n_try + 1
        if (nc_n_try > n_max_retries) {
            stop(msg)
        }
        else {
            message(msg, "\nRETRYing...")
            Sys.sleep(1)
        }
    }
    else {
        nc_retry <- F
    }
}
debug: res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
    url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
        bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
    time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
debug: if (inherits(res, "try-error")) {
    err <- attr(res, "condition")
    msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
    nc_n_try <- nc_n_try + 1
    if (nc_n_try > n_max_retries) {
        stop(msg)
    }
    else {
        message(msg, "\nRETRYing...")
        Sys.sleep(1)
    }
} else {
    nc_retry <- F
}
debug: nc_retry <- F
debug: (while) nc_retry
debug: i_req <- i_req + 1
debug: (while) i_req <= n_reqs
debug: ncs <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size > 
    0), nc)
debug: r <- terra::rast(ncs)
debug: stopifnot(all(class(terra::time(r)) %in% c("POSIXct", "POSIXt")))
debug: idx <- dplyr::pull(dplyr::filter(dplyr::arrange(dplyr::tibble(idx = 1:terra::nlyr(r), 
    time = terra::time(r)), time), !duplicated(time)), idx)
debug: r <- terra::subset(r, idx)
debug: stopifnot(terra::crs(r, proj = T) == wgs84)
debug: if (mask_tif) r <- terra::mask(r, sf_zones)
debug: lyrs <- glue("{var}|{terra::time(r)}")
debug: if (length(dims_other) > 0 && !all(length(dims[dims_other]) == 
    1)) stop(glue("Other dimensions not yet supported: {paste(dims_other, collapse = ',')}"))
debug: names(r) <- lyrs
debug: if (!is.null(rast_tif)) {
    if (fs::file_exists(rast_tif)) {
        r_tmp_tif <- tempfile(fileext = ".tif")
        r_tmp <- c(rast(rast_tif), r)
        r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
        terra::writeRaster(r_tmp, r_tmp_tif)
        fs::file_delete(rast_tif)
        fs::file_move(r_tmp_tif, rast_tif)
        rm(r)
        rm(r_tmp)
    }
    else {
        terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
    }
    r <- terra::rast(rast_tif)
}
debug: if (fs::file_exists(rast_tif)) {
    r_tmp_tif <- tempfile(fileext = ".tif")
    r_tmp <- c(rast(rast_tif), r)
    r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
    terra::writeRaster(r_tmp, r_tmp_tif)
    fs::file_delete(rast_tif)
    fs::file_move(r_tmp_tif, rast_tif)
    rm(r)
    rm(r_tmp)
} else {
    terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
}
debug: terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
debug: r <- terra::rast(rast_tif)
debug: d_r <- mutate(tidyr::pivot_longer(sf::st_drop_geometry(sf::st_as_sf(terra::zonal(x = r, 
    z = terra::vect(dplyr::select(sf_zones, dplyr::all_of(fld_zones))), 
    fun = zonal_fun, exact = T, na.rm = T, as.polygons = T))), 
    cols = -dplyr::any_of(fld_zones), names_to = "lyr", values_to = zonal_fun), 
    time = readr::parse_datetime(str_replace(lyr, glue("{var}\\|(.*)"), 
        "\\1")))
debug: if (!is.null(zonal_csv)) write_csv(d_r, zonal_csv)
debug: write_csv(d_r, zonal_csv)
debug: if (!keep_nc) unlink(dir_nc, recursive = T)
debug: unlink(dir_nc, recursive = T)
debug: return(d_r)
Downloading 1 requests, up to 190 time slices each
Called from: extractr::ed_extract(ed, var = v, sf_zones = ply, bbox = bb, 
    mask_tif = F, rast_tif = glue("{dir_out}/{nms}/{yr}.tif"), 
    zonal_fun = "mean", zonal_csv = glue("{dir_out}/{nms}/{yr}.csv"), 
    dir_nc = glue("{dir_out}/{nms}/{yr}_nc"), keep_nc = F, n_max_vals_per_req = 1e+05, 
    time_min = time_min, time_max = time_max, verbose = T)
debug: while (i_req <= n_reqs) {
    i_t_beg <- (i_req - 1) * n_t_per_req + 1
    i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
    t_req <- times_todo[c(i_t_beg, i_t_end)]
    t_req_str <- format_ISO8601(t_req, usetz = "Z")
    if (verbose) 
        message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
    ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
        ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
        0), nc)
    unlink(ncs0)
    nc_retry <- T
    nc_n_try <- 1
    n_max_retries
    while (nc_retry) {
        res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
            url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
                bbox[["xmax"]]), latitude = c(bbox[["ymin"]], 
                bbox[["ymax"]]), time = t_req_str, fmt = "nc", 
            store = rerddap::disk(path = dir_nc)))
        if (inherits(res, "try-error")) {
            err <- attr(res, "condition")
            msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
            nc_n_try <- nc_n_try + 1
            if (nc_n_try > n_max_retries) {
                stop(msg)
            }
            else {
                message(msg, "\nRETRYing...")
                Sys.sleep(1)
            }
        }
        else {
            nc_retry <- F
        }
    }
    i_req <- i_req + 1
}
debug: i_t_beg <- (i_req - 1) * n_t_per_req + 1
debug: i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
debug: t_req <- times_todo[c(i_t_beg, i_t_end)]
debug: t_req_str <- format_ISO8601(t_req, usetz = "Z")
debug: if (verbose) message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
debug: message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
Fetching request 1 of 1 (2012-01-01 to 2012-12-01) ~ 19:44:21 UTC
debug: ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
    0), nc)
debug: unlink(ncs0)
debug: nc_retry <- T
debug: nc_n_try <- 1
debug: n_max_retries
debug: while (nc_retry) {
    res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
        url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
            bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
        time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
    if (inherits(res, "try-error")) {
        err <- attr(res, "condition")
        msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
        nc_n_try <- nc_n_try + 1
        if (nc_n_try > n_max_retries) {
            stop(msg)
        }
        else {
            message(msg, "\nRETRYing...")
            Sys.sleep(1)
        }
    }
    else {
        nc_retry <- F
    }
}
debug: res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
    url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
        bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
    time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
debug: if (inherits(res, "try-error")) {
    err <- attr(res, "condition")
    msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
    nc_n_try <- nc_n_try + 1
    if (nc_n_try > n_max_retries) {
        stop(msg)
    }
    else {
        message(msg, "\nRETRYing...")
        Sys.sleep(1)
    }
} else {
    nc_retry <- F
}
debug: nc_retry <- F
debug: (while) nc_retry
debug: i_req <- i_req + 1
debug: (while) i_req <= n_reqs
debug: ncs <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size > 
    0), nc)
debug: r <- terra::rast(ncs)
debug: stopifnot(all(class(terra::time(r)) %in% c("POSIXct", "POSIXt")))
debug: idx <- dplyr::pull(dplyr::filter(dplyr::arrange(dplyr::tibble(idx = 1:terra::nlyr(r), 
    time = terra::time(r)), time), !duplicated(time)), idx)
debug: r <- terra::subset(r, idx)
debug: stopifnot(terra::crs(r, proj = T) == wgs84)
debug: if (mask_tif) r <- terra::mask(r, sf_zones)
debug: lyrs <- glue("{var}|{terra::time(r)}")
debug: if (length(dims_other) > 0 && !all(length(dims[dims_other]) == 
    1)) stop(glue("Other dimensions not yet supported: {paste(dims_other, collapse = ',')}"))
debug: names(r) <- lyrs
debug: if (!is.null(rast_tif)) {
    if (fs::file_exists(rast_tif)) {
        r_tmp_tif <- tempfile(fileext = ".tif")
        r_tmp <- c(rast(rast_tif), r)
        r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
        terra::writeRaster(r_tmp, r_tmp_tif)
        fs::file_delete(rast_tif)
        fs::file_move(r_tmp_tif, rast_tif)
        rm(r)
        rm(r_tmp)
    }
    else {
        terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
    }
    r <- terra::rast(rast_tif)
}
debug: if (fs::file_exists(rast_tif)) {
    r_tmp_tif <- tempfile(fileext = ".tif")
    r_tmp <- c(rast(rast_tif), r)
    r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
    terra::writeRaster(r_tmp, r_tmp_tif)
    fs::file_delete(rast_tif)
    fs::file_move(r_tmp_tif, rast_tif)
    rm(r)
    rm(r_tmp)
} else {
    terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
}
debug: terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
debug: r <- terra::rast(rast_tif)
debug: d_r <- mutate(tidyr::pivot_longer(sf::st_drop_geometry(sf::st_as_sf(terra::zonal(x = r, 
    z = terra::vect(dplyr::select(sf_zones, dplyr::all_of(fld_zones))), 
    fun = zonal_fun, exact = T, na.rm = T, as.polygons = T))), 
    cols = -dplyr::any_of(fld_zones), names_to = "lyr", values_to = zonal_fun), 
    time = readr::parse_datetime(str_replace(lyr, glue("{var}\\|(.*)"), 
        "\\1")))
debug: if (!is.null(zonal_csv)) write_csv(d_r, zonal_csv)
debug: write_csv(d_r, zonal_csv)
debug: if (!keep_nc) unlink(dir_nc, recursive = T)
debug: unlink(dir_nc, recursive = T)
debug: return(d_r)
Downloading 1 requests, up to 190 time slices each
Called from: extractr::ed_extract(ed, var = v, sf_zones = ply, bbox = bb, 
    mask_tif = F, rast_tif = glue("{dir_out}/{nms}/{yr}.tif"), 
    zonal_fun = "mean", zonal_csv = glue("{dir_out}/{nms}/{yr}.csv"), 
    dir_nc = glue("{dir_out}/{nms}/{yr}_nc"), keep_nc = F, n_max_vals_per_req = 1e+05, 
    time_min = time_min, time_max = time_max, verbose = T)
debug: while (i_req <= n_reqs) {
    i_t_beg <- (i_req - 1) * n_t_per_req + 1
    i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
    t_req <- times_todo[c(i_t_beg, i_t_end)]
    t_req_str <- format_ISO8601(t_req, usetz = "Z")
    if (verbose) 
        message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
    ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
        ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
        0), nc)
    unlink(ncs0)
    nc_retry <- T
    nc_n_try <- 1
    n_max_retries
    while (nc_retry) {
        res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
            url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
                bbox[["xmax"]]), latitude = c(bbox[["ymin"]], 
                bbox[["ymax"]]), time = t_req_str, fmt = "nc", 
            store = rerddap::disk(path = dir_nc)))
        if (inherits(res, "try-error")) {
            err <- attr(res, "condition")
            msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
            nc_n_try <- nc_n_try + 1
            if (nc_n_try > n_max_retries) {
                stop(msg)
            }
            else {
                message(msg, "\nRETRYing...")
                Sys.sleep(1)
            }
        }
        else {
            nc_retry <- F
        }
    }
    i_req <- i_req + 1
}
debug: i_t_beg <- (i_req - 1) * n_t_per_req + 1
debug: i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
debug: t_req <- times_todo[c(i_t_beg, i_t_end)]
debug: t_req_str <- format_ISO8601(t_req, usetz = "Z")
debug: if (verbose) message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
debug: message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
Fetching request 1 of 1 (2013-01-01 to 2013-12-01) ~ 19:44:23 UTC
debug: ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
    0), nc)
debug: unlink(ncs0)
debug: nc_retry <- T
debug: nc_n_try <- 1
debug: n_max_retries
debug: while (nc_retry) {
    res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
        url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
            bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
        time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
    if (inherits(res, "try-error")) {
        err <- attr(res, "condition")
        msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
        nc_n_try <- nc_n_try + 1
        if (nc_n_try > n_max_retries) {
            stop(msg)
        }
        else {
            message(msg, "\nRETRYing...")
            Sys.sleep(1)
        }
    }
    else {
        nc_retry <- F
    }
}
debug: res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
    url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
        bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
    time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
debug: if (inherits(res, "try-error")) {
    err <- attr(res, "condition")
    msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
    nc_n_try <- nc_n_try + 1
    if (nc_n_try > n_max_retries) {
        stop(msg)
    }
    else {
        message(msg, "\nRETRYing...")
        Sys.sleep(1)
    }
} else {
    nc_retry <- F
}
debug: nc_retry <- F
debug: (while) nc_retry
debug: i_req <- i_req + 1
debug: (while) i_req <= n_reqs
debug: ncs <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size > 
    0), nc)
debug: r <- terra::rast(ncs)
debug: stopifnot(all(class(terra::time(r)) %in% c("POSIXct", "POSIXt")))
debug: idx <- dplyr::pull(dplyr::filter(dplyr::arrange(dplyr::tibble(idx = 1:terra::nlyr(r), 
    time = terra::time(r)), time), !duplicated(time)), idx)
debug: r <- terra::subset(r, idx)
debug: stopifnot(terra::crs(r, proj = T) == wgs84)
debug: if (mask_tif) r <- terra::mask(r, sf_zones)
debug: lyrs <- glue("{var}|{terra::time(r)}")
debug: if (length(dims_other) > 0 && !all(length(dims[dims_other]) == 
    1)) stop(glue("Other dimensions not yet supported: {paste(dims_other, collapse = ',')}"))
debug: names(r) <- lyrs
debug: if (!is.null(rast_tif)) {
    if (fs::file_exists(rast_tif)) {
        r_tmp_tif <- tempfile(fileext = ".tif")
        r_tmp <- c(rast(rast_tif), r)
        r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
        terra::writeRaster(r_tmp, r_tmp_tif)
        fs::file_delete(rast_tif)
        fs::file_move(r_tmp_tif, rast_tif)
        rm(r)
        rm(r_tmp)
    }
    else {
        terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
    }
    r <- terra::rast(rast_tif)
}
debug: if (fs::file_exists(rast_tif)) {
    r_tmp_tif <- tempfile(fileext = ".tif")
    r_tmp <- c(rast(rast_tif), r)
    r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
    terra::writeRaster(r_tmp, r_tmp_tif)
    fs::file_delete(rast_tif)
    fs::file_move(r_tmp_tif, rast_tif)
    rm(r)
    rm(r_tmp)
} else {
    terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
}
debug: terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
debug: r <- terra::rast(rast_tif)
debug: d_r <- mutate(tidyr::pivot_longer(sf::st_drop_geometry(sf::st_as_sf(terra::zonal(x = r, 
    z = terra::vect(dplyr::select(sf_zones, dplyr::all_of(fld_zones))), 
    fun = zonal_fun, exact = T, na.rm = T, as.polygons = T))), 
    cols = -dplyr::any_of(fld_zones), names_to = "lyr", values_to = zonal_fun), 
    time = readr::parse_datetime(str_replace(lyr, glue("{var}\\|(.*)"), 
        "\\1")))
debug: if (!is.null(zonal_csv)) write_csv(d_r, zonal_csv)
debug: write_csv(d_r, zonal_csv)
debug: if (!keep_nc) unlink(dir_nc, recursive = T)
debug: unlink(dir_nc, recursive = T)
debug: return(d_r)
Downloading 1 requests, up to 190 time slices each
Called from: extractr::ed_extract(ed, var = v, sf_zones = ply, bbox = bb, 
    mask_tif = F, rast_tif = glue("{dir_out}/{nms}/{yr}.tif"), 
    zonal_fun = "mean", zonal_csv = glue("{dir_out}/{nms}/{yr}.csv"), 
    dir_nc = glue("{dir_out}/{nms}/{yr}_nc"), keep_nc = F, n_max_vals_per_req = 1e+05, 
    time_min = time_min, time_max = time_max, verbose = T)
debug: while (i_req <= n_reqs) {
    i_t_beg <- (i_req - 1) * n_t_per_req + 1
    i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
    t_req <- times_todo[c(i_t_beg, i_t_end)]
    t_req_str <- format_ISO8601(t_req, usetz = "Z")
    if (verbose) 
        message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
    ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
        ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
        0), nc)
    unlink(ncs0)
    nc_retry <- T
    nc_n_try <- 1
    n_max_retries
    while (nc_retry) {
        res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
            url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
                bbox[["xmax"]]), latitude = c(bbox[["ymin"]], 
                bbox[["ymax"]]), time = t_req_str, fmt = "nc", 
            store = rerddap::disk(path = dir_nc)))
        if (inherits(res, "try-error")) {
            err <- attr(res, "condition")
            msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
            nc_n_try <- nc_n_try + 1
            if (nc_n_try > n_max_retries) {
                stop(msg)
            }
            else {
                message(msg, "\nRETRYing...")
                Sys.sleep(1)
            }
        }
        else {
            nc_retry <- F
        }
    }
    i_req <- i_req + 1
}
debug: i_t_beg <- (i_req - 1) * n_t_per_req + 1
debug: i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
debug: t_req <- times_todo[c(i_t_beg, i_t_end)]
debug: t_req_str <- format_ISO8601(t_req, usetz = "Z")
debug: if (verbose) message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
debug: message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
Fetching request 1 of 1 (2014-01-01 to 2014-12-01) ~ 19:44:25 UTC
debug: ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
    0), nc)
debug: unlink(ncs0)
debug: nc_retry <- T
debug: nc_n_try <- 1
debug: n_max_retries
debug: while (nc_retry) {
    res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
        url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
            bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
        time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
    if (inherits(res, "try-error")) {
        err <- attr(res, "condition")
        msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
        nc_n_try <- nc_n_try + 1
        if (nc_n_try > n_max_retries) {
            stop(msg)
        }
        else {
            message(msg, "\nRETRYing...")
            Sys.sleep(1)
        }
    }
    else {
        nc_retry <- F
    }
}
debug: res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
    url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
        bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
    time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
debug: if (inherits(res, "try-error")) {
    err <- attr(res, "condition")
    msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
    nc_n_try <- nc_n_try + 1
    if (nc_n_try > n_max_retries) {
        stop(msg)
    }
    else {
        message(msg, "\nRETRYing...")
        Sys.sleep(1)
    }
} else {
    nc_retry <- F
}
debug: nc_retry <- F
debug: (while) nc_retry
debug: i_req <- i_req + 1
debug: (while) i_req <= n_reqs
debug: ncs <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size > 
    0), nc)
debug: r <- terra::rast(ncs)
debug: stopifnot(all(class(terra::time(r)) %in% c("POSIXct", "POSIXt")))
debug: idx <- dplyr::pull(dplyr::filter(dplyr::arrange(dplyr::tibble(idx = 1:terra::nlyr(r), 
    time = terra::time(r)), time), !duplicated(time)), idx)
debug: r <- terra::subset(r, idx)
debug: stopifnot(terra::crs(r, proj = T) == wgs84)
debug: if (mask_tif) r <- terra::mask(r, sf_zones)
debug: lyrs <- glue("{var}|{terra::time(r)}")
debug: if (length(dims_other) > 0 && !all(length(dims[dims_other]) == 
    1)) stop(glue("Other dimensions not yet supported: {paste(dims_other, collapse = ',')}"))
debug: names(r) <- lyrs
debug: if (!is.null(rast_tif)) {
    if (fs::file_exists(rast_tif)) {
        r_tmp_tif <- tempfile(fileext = ".tif")
        r_tmp <- c(rast(rast_tif), r)
        r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
        terra::writeRaster(r_tmp, r_tmp_tif)
        fs::file_delete(rast_tif)
        fs::file_move(r_tmp_tif, rast_tif)
        rm(r)
        rm(r_tmp)
    }
    else {
        terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
    }
    r <- terra::rast(rast_tif)
}
debug: if (fs::file_exists(rast_tif)) {
    r_tmp_tif <- tempfile(fileext = ".tif")
    r_tmp <- c(rast(rast_tif), r)
    r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
    terra::writeRaster(r_tmp, r_tmp_tif)
    fs::file_delete(rast_tif)
    fs::file_move(r_tmp_tif, rast_tif)
    rm(r)
    rm(r_tmp)
} else {
    terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
}
debug: terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
debug: r <- terra::rast(rast_tif)
debug: d_r <- mutate(tidyr::pivot_longer(sf::st_drop_geometry(sf::st_as_sf(terra::zonal(x = r, 
    z = terra::vect(dplyr::select(sf_zones, dplyr::all_of(fld_zones))), 
    fun = zonal_fun, exact = T, na.rm = T, as.polygons = T))), 
    cols = -dplyr::any_of(fld_zones), names_to = "lyr", values_to = zonal_fun), 
    time = readr::parse_datetime(str_replace(lyr, glue("{var}\\|(.*)"), 
        "\\1")))
debug: if (!is.null(zonal_csv)) write_csv(d_r, zonal_csv)
debug: write_csv(d_r, zonal_csv)
debug: if (!keep_nc) unlink(dir_nc, recursive = T)
debug: unlink(dir_nc, recursive = T)
debug: return(d_r)
Downloading 1 requests, up to 190 time slices each
Called from: extractr::ed_extract(ed, var = v, sf_zones = ply, bbox = bb, 
    mask_tif = F, rast_tif = glue("{dir_out}/{nms}/{yr}.tif"), 
    zonal_fun = "mean", zonal_csv = glue("{dir_out}/{nms}/{yr}.csv"), 
    dir_nc = glue("{dir_out}/{nms}/{yr}_nc"), keep_nc = F, n_max_vals_per_req = 1e+05, 
    time_min = time_min, time_max = time_max, verbose = T)
debug: while (i_req <= n_reqs) {
    i_t_beg <- (i_req - 1) * n_t_per_req + 1
    i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
    t_req <- times_todo[c(i_t_beg, i_t_end)]
    t_req_str <- format_ISO8601(t_req, usetz = "Z")
    if (verbose) 
        message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
    ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
        ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
        0), nc)
    unlink(ncs0)
    nc_retry <- T
    nc_n_try <- 1
    n_max_retries
    while (nc_retry) {
        res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
            url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
                bbox[["xmax"]]), latitude = c(bbox[["ymin"]], 
                bbox[["ymax"]]), time = t_req_str, fmt = "nc", 
            store = rerddap::disk(path = dir_nc)))
        if (inherits(res, "try-error")) {
            err <- attr(res, "condition")
            msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
            nc_n_try <- nc_n_try + 1
            if (nc_n_try > n_max_retries) {
                stop(msg)
            }
            else {
                message(msg, "\nRETRYing...")
                Sys.sleep(1)
            }
        }
        else {
            nc_retry <- F
        }
    }
    i_req <- i_req + 1
}
debug: i_t_beg <- (i_req - 1) * n_t_per_req + 1
debug: i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
debug: t_req <- times_todo[c(i_t_beg, i_t_end)]
debug: t_req_str <- format_ISO8601(t_req, usetz = "Z")
debug: if (verbose) message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
debug: message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
Fetching request 1 of 1 (2015-01-01 to 2015-12-01) ~ 19:44:27 UTC
debug: ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
    0), nc)
debug: unlink(ncs0)
debug: nc_retry <- T
debug: nc_n_try <- 1
debug: n_max_retries
debug: while (nc_retry) {
    res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
        url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
            bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
        time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
    if (inherits(res, "try-error")) {
        err <- attr(res, "condition")
        msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
        nc_n_try <- nc_n_try + 1
        if (nc_n_try > n_max_retries) {
            stop(msg)
        }
        else {
            message(msg, "\nRETRYing...")
            Sys.sleep(1)
        }
    }
    else {
        nc_retry <- F
    }
}
debug: res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
    url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
        bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
    time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
debug: if (inherits(res, "try-error")) {
    err <- attr(res, "condition")
    msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
    nc_n_try <- nc_n_try + 1
    if (nc_n_try > n_max_retries) {
        stop(msg)
    }
    else {
        message(msg, "\nRETRYing...")
        Sys.sleep(1)
    }
} else {
    nc_retry <- F
}
debug: nc_retry <- F
debug: (while) nc_retry
debug: i_req <- i_req + 1
debug: (while) i_req <= n_reqs
debug: ncs <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size > 
    0), nc)
debug: r <- terra::rast(ncs)
debug: stopifnot(all(class(terra::time(r)) %in% c("POSIXct", "POSIXt")))
debug: idx <- dplyr::pull(dplyr::filter(dplyr::arrange(dplyr::tibble(idx = 1:terra::nlyr(r), 
    time = terra::time(r)), time), !duplicated(time)), idx)
debug: r <- terra::subset(r, idx)
debug: stopifnot(terra::crs(r, proj = T) == wgs84)
debug: if (mask_tif) r <- terra::mask(r, sf_zones)
debug: lyrs <- glue("{var}|{terra::time(r)}")
debug: if (length(dims_other) > 0 && !all(length(dims[dims_other]) == 
    1)) stop(glue("Other dimensions not yet supported: {paste(dims_other, collapse = ',')}"))
debug: names(r) <- lyrs
debug: if (!is.null(rast_tif)) {
    if (fs::file_exists(rast_tif)) {
        r_tmp_tif <- tempfile(fileext = ".tif")
        r_tmp <- c(rast(rast_tif), r)
        r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
        terra::writeRaster(r_tmp, r_tmp_tif)
        fs::file_delete(rast_tif)
        fs::file_move(r_tmp_tif, rast_tif)
        rm(r)
        rm(r_tmp)
    }
    else {
        terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
    }
    r <- terra::rast(rast_tif)
}
debug: if (fs::file_exists(rast_tif)) {
    r_tmp_tif <- tempfile(fileext = ".tif")
    r_tmp <- c(rast(rast_tif), r)
    r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
    terra::writeRaster(r_tmp, r_tmp_tif)
    fs::file_delete(rast_tif)
    fs::file_move(r_tmp_tif, rast_tif)
    rm(r)
    rm(r_tmp)
} else {
    terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
}
debug: terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
debug: r <- terra::rast(rast_tif)
debug: d_r <- mutate(tidyr::pivot_longer(sf::st_drop_geometry(sf::st_as_sf(terra::zonal(x = r, 
    z = terra::vect(dplyr::select(sf_zones, dplyr::all_of(fld_zones))), 
    fun = zonal_fun, exact = T, na.rm = T, as.polygons = T))), 
    cols = -dplyr::any_of(fld_zones), names_to = "lyr", values_to = zonal_fun), 
    time = readr::parse_datetime(str_replace(lyr, glue("{var}\\|(.*)"), 
        "\\1")))
debug: if (!is.null(zonal_csv)) write_csv(d_r, zonal_csv)
debug: write_csv(d_r, zonal_csv)
debug: if (!keep_nc) unlink(dir_nc, recursive = T)
debug: unlink(dir_nc, recursive = T)
debug: return(d_r)
Downloading 1 requests, up to 190 time slices each
Called from: extractr::ed_extract(ed, var = v, sf_zones = ply, bbox = bb, 
    mask_tif = F, rast_tif = glue("{dir_out}/{nms}/{yr}.tif"), 
    zonal_fun = "mean", zonal_csv = glue("{dir_out}/{nms}/{yr}.csv"), 
    dir_nc = glue("{dir_out}/{nms}/{yr}_nc"), keep_nc = F, n_max_vals_per_req = 1e+05, 
    time_min = time_min, time_max = time_max, verbose = T)
debug: while (i_req <= n_reqs) {
    i_t_beg <- (i_req - 1) * n_t_per_req + 1
    i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
    t_req <- times_todo[c(i_t_beg, i_t_end)]
    t_req_str <- format_ISO8601(t_req, usetz = "Z")
    if (verbose) 
        message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
    ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
        ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
        0), nc)
    unlink(ncs0)
    nc_retry <- T
    nc_n_try <- 1
    n_max_retries
    while (nc_retry) {
        res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
            url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
                bbox[["xmax"]]), latitude = c(bbox[["ymin"]], 
                bbox[["ymax"]]), time = t_req_str, fmt = "nc", 
            store = rerddap::disk(path = dir_nc)))
        if (inherits(res, "try-error")) {
            err <- attr(res, "condition")
            msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
            nc_n_try <- nc_n_try + 1
            if (nc_n_try > n_max_retries) {
                stop(msg)
            }
            else {
                message(msg, "\nRETRYing...")
                Sys.sleep(1)
            }
        }
        else {
            nc_retry <- F
        }
    }
    i_req <- i_req + 1
}
debug: i_t_beg <- (i_req - 1) * n_t_per_req + 1
debug: i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
debug: t_req <- times_todo[c(i_t_beg, i_t_end)]
debug: t_req_str <- format_ISO8601(t_req, usetz = "Z")
debug: if (verbose) message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
debug: message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
Fetching request 1 of 1 (2016-01-01 to 2016-12-01) ~ 19:44:28 UTC
debug: ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
    0), nc)
debug: unlink(ncs0)
debug: nc_retry <- T
debug: nc_n_try <- 1
debug: n_max_retries
debug: while (nc_retry) {
    res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
        url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
            bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
        time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
    if (inherits(res, "try-error")) {
        err <- attr(res, "condition")
        msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
        nc_n_try <- nc_n_try + 1
        if (nc_n_try > n_max_retries) {
            stop(msg)
        }
        else {
            message(msg, "\nRETRYing...")
            Sys.sleep(1)
        }
    }
    else {
        nc_retry <- F
    }
}
debug: res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
    url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
        bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
    time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
debug: if (inherits(res, "try-error")) {
    err <- attr(res, "condition")
    msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
    nc_n_try <- nc_n_try + 1
    if (nc_n_try > n_max_retries) {
        stop(msg)
    }
    else {
        message(msg, "\nRETRYing...")
        Sys.sleep(1)
    }
} else {
    nc_retry <- F
}
debug: nc_retry <- F
debug: (while) nc_retry
debug: i_req <- i_req + 1
debug: (while) i_req <= n_reqs
debug: ncs <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size > 
    0), nc)
debug: r <- terra::rast(ncs)
debug: stopifnot(all(class(terra::time(r)) %in% c("POSIXct", "POSIXt")))
debug: idx <- dplyr::pull(dplyr::filter(dplyr::arrange(dplyr::tibble(idx = 1:terra::nlyr(r), 
    time = terra::time(r)), time), !duplicated(time)), idx)
debug: r <- terra::subset(r, idx)
debug: stopifnot(terra::crs(r, proj = T) == wgs84)
debug: if (mask_tif) r <- terra::mask(r, sf_zones)
debug: lyrs <- glue("{var}|{terra::time(r)}")
debug: if (length(dims_other) > 0 && !all(length(dims[dims_other]) == 
    1)) stop(glue("Other dimensions not yet supported: {paste(dims_other, collapse = ',')}"))
debug: names(r) <- lyrs
debug: if (!is.null(rast_tif)) {
    if (fs::file_exists(rast_tif)) {
        r_tmp_tif <- tempfile(fileext = ".tif")
        r_tmp <- c(rast(rast_tif), r)
        r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
        terra::writeRaster(r_tmp, r_tmp_tif)
        fs::file_delete(rast_tif)
        fs::file_move(r_tmp_tif, rast_tif)
        rm(r)
        rm(r_tmp)
    }
    else {
        terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
    }
    r <- terra::rast(rast_tif)
}
debug: if (fs::file_exists(rast_tif)) {
    r_tmp_tif <- tempfile(fileext = ".tif")
    r_tmp <- c(rast(rast_tif), r)
    r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
    terra::writeRaster(r_tmp, r_tmp_tif)
    fs::file_delete(rast_tif)
    fs::file_move(r_tmp_tif, rast_tif)
    rm(r)
    rm(r_tmp)
} else {
    terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
}
debug: terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
debug: r <- terra::rast(rast_tif)
debug: d_r <- mutate(tidyr::pivot_longer(sf::st_drop_geometry(sf::st_as_sf(terra::zonal(x = r, 
    z = terra::vect(dplyr::select(sf_zones, dplyr::all_of(fld_zones))), 
    fun = zonal_fun, exact = T, na.rm = T, as.polygons = T))), 
    cols = -dplyr::any_of(fld_zones), names_to = "lyr", values_to = zonal_fun), 
    time = readr::parse_datetime(str_replace(lyr, glue("{var}\\|(.*)"), 
        "\\1")))
debug: if (!is.null(zonal_csv)) write_csv(d_r, zonal_csv)
debug: write_csv(d_r, zonal_csv)
debug: if (!keep_nc) unlink(dir_nc, recursive = T)
debug: unlink(dir_nc, recursive = T)
debug: return(d_r)
Downloading 1 requests, up to 190 time slices each
Called from: extractr::ed_extract(ed, var = v, sf_zones = ply, bbox = bb, 
    mask_tif = F, rast_tif = glue("{dir_out}/{nms}/{yr}.tif"), 
    zonal_fun = "mean", zonal_csv = glue("{dir_out}/{nms}/{yr}.csv"), 
    dir_nc = glue("{dir_out}/{nms}/{yr}_nc"), keep_nc = F, n_max_vals_per_req = 1e+05, 
    time_min = time_min, time_max = time_max, verbose = T)
debug: while (i_req <= n_reqs) {
    i_t_beg <- (i_req - 1) * n_t_per_req + 1
    i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
    t_req <- times_todo[c(i_t_beg, i_t_end)]
    t_req_str <- format_ISO8601(t_req, usetz = "Z")
    if (verbose) 
        message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
    ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
        ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
        0), nc)
    unlink(ncs0)
    nc_retry <- T
    nc_n_try <- 1
    n_max_retries
    while (nc_retry) {
        res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
            url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
                bbox[["xmax"]]), latitude = c(bbox[["ymin"]], 
                bbox[["ymax"]]), time = t_req_str, fmt = "nc", 
            store = rerddap::disk(path = dir_nc)))
        if (inherits(res, "try-error")) {
            err <- attr(res, "condition")
            msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
            nc_n_try <- nc_n_try + 1
            if (nc_n_try > n_max_retries) {
                stop(msg)
            }
            else {
                message(msg, "\nRETRYing...")
                Sys.sleep(1)
            }
        }
        else {
            nc_retry <- F
        }
    }
    i_req <- i_req + 1
}
debug: i_t_beg <- (i_req - 1) * n_t_per_req + 1
debug: i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
debug: t_req <- times_todo[c(i_t_beg, i_t_end)]
debug: t_req_str <- format_ISO8601(t_req, usetz = "Z")
debug: if (verbose) message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
debug: message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
Fetching request 1 of 1 (2017-01-01 to 2017-12-01) ~ 19:44:31 UTC
debug: ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
    0), nc)
debug: unlink(ncs0)
debug: nc_retry <- T
debug: nc_n_try <- 1
debug: n_max_retries
debug: while (nc_retry) {
    res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
        url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
            bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
        time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
    if (inherits(res, "try-error")) {
        err <- attr(res, "condition")
        msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
        nc_n_try <- nc_n_try + 1
        if (nc_n_try > n_max_retries) {
            stop(msg)
        }
        else {
            message(msg, "\nRETRYing...")
            Sys.sleep(1)
        }
    }
    else {
        nc_retry <- F
    }
}
debug: res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
    url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
        bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
    time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
debug: if (inherits(res, "try-error")) {
    err <- attr(res, "condition")
    msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
    nc_n_try <- nc_n_try + 1
    if (nc_n_try > n_max_retries) {
        stop(msg)
    }
    else {
        message(msg, "\nRETRYing...")
        Sys.sleep(1)
    }
} else {
    nc_retry <- F
}
debug: nc_retry <- F
debug: (while) nc_retry
debug: i_req <- i_req + 1
debug: (while) i_req <= n_reqs
debug: ncs <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size > 
    0), nc)
debug: r <- terra::rast(ncs)
debug: stopifnot(all(class(terra::time(r)) %in% c("POSIXct", "POSIXt")))
debug: idx <- dplyr::pull(dplyr::filter(dplyr::arrange(dplyr::tibble(idx = 1:terra::nlyr(r), 
    time = terra::time(r)), time), !duplicated(time)), idx)
debug: r <- terra::subset(r, idx)
debug: stopifnot(terra::crs(r, proj = T) == wgs84)
debug: if (mask_tif) r <- terra::mask(r, sf_zones)
debug: lyrs <- glue("{var}|{terra::time(r)}")
debug: if (length(dims_other) > 0 && !all(length(dims[dims_other]) == 
    1)) stop(glue("Other dimensions not yet supported: {paste(dims_other, collapse = ',')}"))
debug: names(r) <- lyrs
debug: if (!is.null(rast_tif)) {
    if (fs::file_exists(rast_tif)) {
        r_tmp_tif <- tempfile(fileext = ".tif")
        r_tmp <- c(rast(rast_tif), r)
        r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
        terra::writeRaster(r_tmp, r_tmp_tif)
        fs::file_delete(rast_tif)
        fs::file_move(r_tmp_tif, rast_tif)
        rm(r)
        rm(r_tmp)
    }
    else {
        terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
    }
    r <- terra::rast(rast_tif)
}
debug: if (fs::file_exists(rast_tif)) {
    r_tmp_tif <- tempfile(fileext = ".tif")
    r_tmp <- c(rast(rast_tif), r)
    r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
    terra::writeRaster(r_tmp, r_tmp_tif)
    fs::file_delete(rast_tif)
    fs::file_move(r_tmp_tif, rast_tif)
    rm(r)
    rm(r_tmp)
} else {
    terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
}
debug: terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
debug: r <- terra::rast(rast_tif)
debug: d_r <- mutate(tidyr::pivot_longer(sf::st_drop_geometry(sf::st_as_sf(terra::zonal(x = r, 
    z = terra::vect(dplyr::select(sf_zones, dplyr::all_of(fld_zones))), 
    fun = zonal_fun, exact = T, na.rm = T, as.polygons = T))), 
    cols = -dplyr::any_of(fld_zones), names_to = "lyr", values_to = zonal_fun), 
    time = readr::parse_datetime(str_replace(lyr, glue("{var}\\|(.*)"), 
        "\\1")))
debug: if (!is.null(zonal_csv)) write_csv(d_r, zonal_csv)
debug: write_csv(d_r, zonal_csv)
debug: if (!keep_nc) unlink(dir_nc, recursive = T)
debug: unlink(dir_nc, recursive = T)
debug: return(d_r)
Downloading 1 requests, up to 190 time slices each
Called from: extractr::ed_extract(ed, var = v, sf_zones = ply, bbox = bb, 
    mask_tif = F, rast_tif = glue("{dir_out}/{nms}/{yr}.tif"), 
    zonal_fun = "mean", zonal_csv = glue("{dir_out}/{nms}/{yr}.csv"), 
    dir_nc = glue("{dir_out}/{nms}/{yr}_nc"), keep_nc = F, n_max_vals_per_req = 1e+05, 
    time_min = time_min, time_max = time_max, verbose = T)
debug: while (i_req <= n_reqs) {
    i_t_beg <- (i_req - 1) * n_t_per_req + 1
    i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
    t_req <- times_todo[c(i_t_beg, i_t_end)]
    t_req_str <- format_ISO8601(t_req, usetz = "Z")
    if (verbose) 
        message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
    ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
        ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
        0), nc)
    unlink(ncs0)
    nc_retry <- T
    nc_n_try <- 1
    n_max_retries
    while (nc_retry) {
        res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
            url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
                bbox[["xmax"]]), latitude = c(bbox[["ymin"]], 
                bbox[["ymax"]]), time = t_req_str, fmt = "nc", 
            store = rerddap::disk(path = dir_nc)))
        if (inherits(res, "try-error")) {
            err <- attr(res, "condition")
            msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
            nc_n_try <- nc_n_try + 1
            if (nc_n_try > n_max_retries) {
                stop(msg)
            }
            else {
                message(msg, "\nRETRYing...")
                Sys.sleep(1)
            }
        }
        else {
            nc_retry <- F
        }
    }
    i_req <- i_req + 1
}
debug: i_t_beg <- (i_req - 1) * n_t_per_req + 1
debug: i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
debug: t_req <- times_todo[c(i_t_beg, i_t_end)]
debug: t_req_str <- format_ISO8601(t_req, usetz = "Z")
debug: if (verbose) message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
debug: message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
Fetching request 1 of 1 (2018-01-01 to 2018-12-01) ~ 19:44:32 UTC
debug: ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
    0), nc)
debug: unlink(ncs0)
debug: nc_retry <- T
debug: nc_n_try <- 1
debug: n_max_retries
debug: while (nc_retry) {
    res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
        url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
            bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
        time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
    if (inherits(res, "try-error")) {
        err <- attr(res, "condition")
        msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
        nc_n_try <- nc_n_try + 1
        if (nc_n_try > n_max_retries) {
            stop(msg)
        }
        else {
            message(msg, "\nRETRYing...")
            Sys.sleep(1)
        }
    }
    else {
        nc_retry <- F
    }
}
debug: res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
    url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
        bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
    time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
debug: if (inherits(res, "try-error")) {
    err <- attr(res, "condition")
    msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
    nc_n_try <- nc_n_try + 1
    if (nc_n_try > n_max_retries) {
        stop(msg)
    }
    else {
        message(msg, "\nRETRYing...")
        Sys.sleep(1)
    }
} else {
    nc_retry <- F
}
debug: nc_retry <- F
debug: (while) nc_retry
debug: i_req <- i_req + 1
debug: (while) i_req <= n_reqs
debug: ncs <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size > 
    0), nc)
debug: r <- terra::rast(ncs)
debug: stopifnot(all(class(terra::time(r)) %in% c("POSIXct", "POSIXt")))
debug: idx <- dplyr::pull(dplyr::filter(dplyr::arrange(dplyr::tibble(idx = 1:terra::nlyr(r), 
    time = terra::time(r)), time), !duplicated(time)), idx)
debug: r <- terra::subset(r, idx)
debug: stopifnot(terra::crs(r, proj = T) == wgs84)
debug: if (mask_tif) r <- terra::mask(r, sf_zones)
debug: lyrs <- glue("{var}|{terra::time(r)}")
debug: if (length(dims_other) > 0 && !all(length(dims[dims_other]) == 
    1)) stop(glue("Other dimensions not yet supported: {paste(dims_other, collapse = ',')}"))
debug: names(r) <- lyrs
debug: if (!is.null(rast_tif)) {
    if (fs::file_exists(rast_tif)) {
        r_tmp_tif <- tempfile(fileext = ".tif")
        r_tmp <- c(rast(rast_tif), r)
        r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
        terra::writeRaster(r_tmp, r_tmp_tif)
        fs::file_delete(rast_tif)
        fs::file_move(r_tmp_tif, rast_tif)
        rm(r)
        rm(r_tmp)
    }
    else {
        terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
    }
    r <- terra::rast(rast_tif)
}
debug: if (fs::file_exists(rast_tif)) {
    r_tmp_tif <- tempfile(fileext = ".tif")
    r_tmp <- c(rast(rast_tif), r)
    r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
    terra::writeRaster(r_tmp, r_tmp_tif)
    fs::file_delete(rast_tif)
    fs::file_move(r_tmp_tif, rast_tif)
    rm(r)
    rm(r_tmp)
} else {
    terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
}
debug: terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
debug: r <- terra::rast(rast_tif)
debug: d_r <- mutate(tidyr::pivot_longer(sf::st_drop_geometry(sf::st_as_sf(terra::zonal(x = r, 
    z = terra::vect(dplyr::select(sf_zones, dplyr::all_of(fld_zones))), 
    fun = zonal_fun, exact = T, na.rm = T, as.polygons = T))), 
    cols = -dplyr::any_of(fld_zones), names_to = "lyr", values_to = zonal_fun), 
    time = readr::parse_datetime(str_replace(lyr, glue("{var}\\|(.*)"), 
        "\\1")))
debug: if (!is.null(zonal_csv)) write_csv(d_r, zonal_csv)
debug: write_csv(d_r, zonal_csv)
debug: if (!keep_nc) unlink(dir_nc, recursive = T)
debug: unlink(dir_nc, recursive = T)
debug: return(d_r)
Downloading 1 requests, up to 190 time slices each
Called from: extractr::ed_extract(ed, var = v, sf_zones = ply, bbox = bb, 
    mask_tif = F, rast_tif = glue("{dir_out}/{nms}/{yr}.tif"), 
    zonal_fun = "mean", zonal_csv = glue("{dir_out}/{nms}/{yr}.csv"), 
    dir_nc = glue("{dir_out}/{nms}/{yr}_nc"), keep_nc = F, n_max_vals_per_req = 1e+05, 
    time_min = time_min, time_max = time_max, verbose = T)
debug: while (i_req <= n_reqs) {
    i_t_beg <- (i_req - 1) * n_t_per_req + 1
    i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
    t_req <- times_todo[c(i_t_beg, i_t_end)]
    t_req_str <- format_ISO8601(t_req, usetz = "Z")
    if (verbose) 
        message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
    ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
        ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
        0), nc)
    unlink(ncs0)
    nc_retry <- T
    nc_n_try <- 1
    n_max_retries
    while (nc_retry) {
        res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
            url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
                bbox[["xmax"]]), latitude = c(bbox[["ymin"]], 
                bbox[["ymax"]]), time = t_req_str, fmt = "nc", 
            store = rerddap::disk(path = dir_nc)))
        if (inherits(res, "try-error")) {
            err <- attr(res, "condition")
            msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
            nc_n_try <- nc_n_try + 1
            if (nc_n_try > n_max_retries) {
                stop(msg)
            }
            else {
                message(msg, "\nRETRYing...")
                Sys.sleep(1)
            }
        }
        else {
            nc_retry <- F
        }
    }
    i_req <- i_req + 1
}
debug: i_t_beg <- (i_req - 1) * n_t_per_req + 1
debug: i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
debug: t_req <- times_todo[c(i_t_beg, i_t_end)]
debug: t_req_str <- format_ISO8601(t_req, usetz = "Z")
debug: if (verbose) message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
debug: message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
Fetching request 1 of 1 (2019-01-01 to 2019-12-01) ~ 19:44:34 UTC
debug: ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
    0), nc)
debug: unlink(ncs0)
debug: nc_retry <- T
debug: nc_n_try <- 1
debug: n_max_retries
debug: while (nc_retry) {
    res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
        url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
            bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
        time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
    if (inherits(res, "try-error")) {
        err <- attr(res, "condition")
        msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
        nc_n_try <- nc_n_try + 1
        if (nc_n_try > n_max_retries) {
            stop(msg)
        }
        else {
            message(msg, "\nRETRYing...")
            Sys.sleep(1)
        }
    }
    else {
        nc_retry <- F
    }
}
debug: res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
    url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
        bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
    time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
debug: if (inherits(res, "try-error")) {
    err <- attr(res, "condition")
    msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
    nc_n_try <- nc_n_try + 1
    if (nc_n_try > n_max_retries) {
        stop(msg)
    }
    else {
        message(msg, "\nRETRYing...")
        Sys.sleep(1)
    }
} else {
    nc_retry <- F
}
debug: nc_retry <- F
debug: (while) nc_retry
debug: i_req <- i_req + 1
debug: (while) i_req <= n_reqs
debug: ncs <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size > 
    0), nc)
debug: r <- terra::rast(ncs)
debug: stopifnot(all(class(terra::time(r)) %in% c("POSIXct", "POSIXt")))
debug: idx <- dplyr::pull(dplyr::filter(dplyr::arrange(dplyr::tibble(idx = 1:terra::nlyr(r), 
    time = terra::time(r)), time), !duplicated(time)), idx)
debug: r <- terra::subset(r, idx)
debug: stopifnot(terra::crs(r, proj = T) == wgs84)
debug: if (mask_tif) r <- terra::mask(r, sf_zones)
debug: lyrs <- glue("{var}|{terra::time(r)}")
debug: if (length(dims_other) > 0 && !all(length(dims[dims_other]) == 
    1)) stop(glue("Other dimensions not yet supported: {paste(dims_other, collapse = ',')}"))
debug: names(r) <- lyrs
debug: if (!is.null(rast_tif)) {
    if (fs::file_exists(rast_tif)) {
        r_tmp_tif <- tempfile(fileext = ".tif")
        r_tmp <- c(rast(rast_tif), r)
        r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
        terra::writeRaster(r_tmp, r_tmp_tif)
        fs::file_delete(rast_tif)
        fs::file_move(r_tmp_tif, rast_tif)
        rm(r)
        rm(r_tmp)
    }
    else {
        terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
    }
    r <- terra::rast(rast_tif)
}
debug: if (fs::file_exists(rast_tif)) {
    r_tmp_tif <- tempfile(fileext = ".tif")
    r_tmp <- c(rast(rast_tif), r)
    r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
    terra::writeRaster(r_tmp, r_tmp_tif)
    fs::file_delete(rast_tif)
    fs::file_move(r_tmp_tif, rast_tif)
    rm(r)
    rm(r_tmp)
} else {
    terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
}
debug: terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
debug: r <- terra::rast(rast_tif)
debug: d_r <- mutate(tidyr::pivot_longer(sf::st_drop_geometry(sf::st_as_sf(terra::zonal(x = r, 
    z = terra::vect(dplyr::select(sf_zones, dplyr::all_of(fld_zones))), 
    fun = zonal_fun, exact = T, na.rm = T, as.polygons = T))), 
    cols = -dplyr::any_of(fld_zones), names_to = "lyr", values_to = zonal_fun), 
    time = readr::parse_datetime(str_replace(lyr, glue("{var}\\|(.*)"), 
        "\\1")))
debug: if (!is.null(zonal_csv)) write_csv(d_r, zonal_csv)
debug: write_csv(d_r, zonal_csv)
debug: if (!keep_nc) unlink(dir_nc, recursive = T)
debug: unlink(dir_nc, recursive = T)
debug: return(d_r)
Downloading 1 requests, up to 190 time slices each
Called from: extractr::ed_extract(ed, var = v, sf_zones = ply, bbox = bb, 
    mask_tif = F, rast_tif = glue("{dir_out}/{nms}/{yr}.tif"), 
    zonal_fun = "mean", zonal_csv = glue("{dir_out}/{nms}/{yr}.csv"), 
    dir_nc = glue("{dir_out}/{nms}/{yr}_nc"), keep_nc = F, n_max_vals_per_req = 1e+05, 
    time_min = time_min, time_max = time_max, verbose = T)
debug: while (i_req <= n_reqs) {
    i_t_beg <- (i_req - 1) * n_t_per_req + 1
    i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
    t_req <- times_todo[c(i_t_beg, i_t_end)]
    t_req_str <- format_ISO8601(t_req, usetz = "Z")
    if (verbose) 
        message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
    ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
        ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
        0), nc)
    unlink(ncs0)
    nc_retry <- T
    nc_n_try <- 1
    n_max_retries
    while (nc_retry) {
        res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
            url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
                bbox[["xmax"]]), latitude = c(bbox[["ymin"]], 
                bbox[["ymax"]]), time = t_req_str, fmt = "nc", 
            store = rerddap::disk(path = dir_nc)))
        if (inherits(res, "try-error")) {
            err <- attr(res, "condition")
            msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
            nc_n_try <- nc_n_try + 1
            if (nc_n_try > n_max_retries) {
                stop(msg)
            }
            else {
                message(msg, "\nRETRYing...")
                Sys.sleep(1)
            }
        }
        else {
            nc_retry <- F
        }
    }
    i_req <- i_req + 1
}
debug: i_t_beg <- (i_req - 1) * n_t_per_req + 1
debug: i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
debug: t_req <- times_todo[c(i_t_beg, i_t_end)]
debug: t_req_str <- format_ISO8601(t_req, usetz = "Z")
debug: if (verbose) message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
debug: message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
Fetching request 1 of 1 (2020-01-01 to 2020-12-01) ~ 19:44:36 UTC
debug: ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
    0), nc)
debug: unlink(ncs0)
debug: nc_retry <- T
debug: nc_n_try <- 1
debug: n_max_retries
debug: while (nc_retry) {
    res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
        url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
            bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
        time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
    if (inherits(res, "try-error")) {
        err <- attr(res, "condition")
        msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
        nc_n_try <- nc_n_try + 1
        if (nc_n_try > n_max_retries) {
            stop(msg)
        }
        else {
            message(msg, "\nRETRYing...")
            Sys.sleep(1)
        }
    }
    else {
        nc_retry <- F
    }
}
debug: res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
    url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
        bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
    time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
debug: if (inherits(res, "try-error")) {
    err <- attr(res, "condition")
    msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
    nc_n_try <- nc_n_try + 1
    if (nc_n_try > n_max_retries) {
        stop(msg)
    }
    else {
        message(msg, "\nRETRYing...")
        Sys.sleep(1)
    }
} else {
    nc_retry <- F
}
debug: nc_retry <- F
debug: (while) nc_retry
debug: i_req <- i_req + 1
debug: (while) i_req <= n_reqs
debug: ncs <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size > 
    0), nc)
debug: r <- terra::rast(ncs)
debug: stopifnot(all(class(terra::time(r)) %in% c("POSIXct", "POSIXt")))
debug: idx <- dplyr::pull(dplyr::filter(dplyr::arrange(dplyr::tibble(idx = 1:terra::nlyr(r), 
    time = terra::time(r)), time), !duplicated(time)), idx)
debug: r <- terra::subset(r, idx)
debug: stopifnot(terra::crs(r, proj = T) == wgs84)
debug: if (mask_tif) r <- terra::mask(r, sf_zones)
debug: lyrs <- glue("{var}|{terra::time(r)}")
debug: if (length(dims_other) > 0 && !all(length(dims[dims_other]) == 
    1)) stop(glue("Other dimensions not yet supported: {paste(dims_other, collapse = ',')}"))
debug: names(r) <- lyrs
debug: if (!is.null(rast_tif)) {
    if (fs::file_exists(rast_tif)) {
        r_tmp_tif <- tempfile(fileext = ".tif")
        r_tmp <- c(rast(rast_tif), r)
        r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
        terra::writeRaster(r_tmp, r_tmp_tif)
        fs::file_delete(rast_tif)
        fs::file_move(r_tmp_tif, rast_tif)
        rm(r)
        rm(r_tmp)
    }
    else {
        terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
    }
    r <- terra::rast(rast_tif)
}
debug: if (fs::file_exists(rast_tif)) {
    r_tmp_tif <- tempfile(fileext = ".tif")
    r_tmp <- c(rast(rast_tif), r)
    r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
    terra::writeRaster(r_tmp, r_tmp_tif)
    fs::file_delete(rast_tif)
    fs::file_move(r_tmp_tif, rast_tif)
    rm(r)
    rm(r_tmp)
} else {
    terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
}
debug: terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
debug: r <- terra::rast(rast_tif)
debug: d_r <- mutate(tidyr::pivot_longer(sf::st_drop_geometry(sf::st_as_sf(terra::zonal(x = r, 
    z = terra::vect(dplyr::select(sf_zones, dplyr::all_of(fld_zones))), 
    fun = zonal_fun, exact = T, na.rm = T, as.polygons = T))), 
    cols = -dplyr::any_of(fld_zones), names_to = "lyr", values_to = zonal_fun), 
    time = readr::parse_datetime(str_replace(lyr, glue("{var}\\|(.*)"), 
        "\\1")))
debug: if (!is.null(zonal_csv)) write_csv(d_r, zonal_csv)
debug: write_csv(d_r, zonal_csv)
debug: if (!keep_nc) unlink(dir_nc, recursive = T)
debug: unlink(dir_nc, recursive = T)
debug: return(d_r)
Downloading 1 requests, up to 190 time slices each
Called from: extractr::ed_extract(ed, var = v, sf_zones = ply, bbox = bb, 
    mask_tif = F, rast_tif = glue("{dir_out}/{nms}/{yr}.tif"), 
    zonal_fun = "mean", zonal_csv = glue("{dir_out}/{nms}/{yr}.csv"), 
    dir_nc = glue("{dir_out}/{nms}/{yr}_nc"), keep_nc = F, n_max_vals_per_req = 1e+05, 
    time_min = time_min, time_max = time_max, verbose = T)
debug: while (i_req <= n_reqs) {
    i_t_beg <- (i_req - 1) * n_t_per_req + 1
    i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
    t_req <- times_todo[c(i_t_beg, i_t_end)]
    t_req_str <- format_ISO8601(t_req, usetz = "Z")
    if (verbose) 
        message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
    ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
        ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
        0), nc)
    unlink(ncs0)
    nc_retry <- T
    nc_n_try <- 1
    n_max_retries
    while (nc_retry) {
        res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
            url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
                bbox[["xmax"]]), latitude = c(bbox[["ymin"]], 
                bbox[["ymax"]]), time = t_req_str, fmt = "nc", 
            store = rerddap::disk(path = dir_nc)))
        if (inherits(res, "try-error")) {
            err <- attr(res, "condition")
            msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
            nc_n_try <- nc_n_try + 1
            if (nc_n_try > n_max_retries) {
                stop(msg)
            }
            else {
                message(msg, "\nRETRYing...")
                Sys.sleep(1)
            }
        }
        else {
            nc_retry <- F
        }
    }
    i_req <- i_req + 1
}
debug: i_t_beg <- (i_req - 1) * n_t_per_req + 1
debug: i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
debug: t_req <- times_todo[c(i_t_beg, i_t_end)]
debug: t_req_str <- format_ISO8601(t_req, usetz = "Z")
debug: if (verbose) message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
debug: message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
Fetching request 1 of 1 (2021-01-01 to 2021-12-01) ~ 19:44:38 UTC
debug: ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
    0), nc)
debug: unlink(ncs0)
debug: nc_retry <- T
debug: nc_n_try <- 1
debug: n_max_retries
debug: while (nc_retry) {
    res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
        url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
            bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
        time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
    if (inherits(res, "try-error")) {
        err <- attr(res, "condition")
        msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
        nc_n_try <- nc_n_try + 1
        if (nc_n_try > n_max_retries) {
            stop(msg)
        }
        else {
            message(msg, "\nRETRYing...")
            Sys.sleep(1)
        }
    }
    else {
        nc_retry <- F
    }
}
debug: res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
    url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
        bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
    time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
debug: if (inherits(res, "try-error")) {
    err <- attr(res, "condition")
    msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
    nc_n_try <- nc_n_try + 1
    if (nc_n_try > n_max_retries) {
        stop(msg)
    }
    else {
        message(msg, "\nRETRYing...")
        Sys.sleep(1)
    }
} else {
    nc_retry <- F
}
debug: nc_retry <- F
debug: (while) nc_retry
debug: i_req <- i_req + 1
debug: (while) i_req <= n_reqs
debug: ncs <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size > 
    0), nc)
debug: r <- terra::rast(ncs)
debug: stopifnot(all(class(terra::time(r)) %in% c("POSIXct", "POSIXt")))
debug: idx <- dplyr::pull(dplyr::filter(dplyr::arrange(dplyr::tibble(idx = 1:terra::nlyr(r), 
    time = terra::time(r)), time), !duplicated(time)), idx)
debug: r <- terra::subset(r, idx)
debug: stopifnot(terra::crs(r, proj = T) == wgs84)
debug: if (mask_tif) r <- terra::mask(r, sf_zones)
debug: lyrs <- glue("{var}|{terra::time(r)}")
debug: if (length(dims_other) > 0 && !all(length(dims[dims_other]) == 
    1)) stop(glue("Other dimensions not yet supported: {paste(dims_other, collapse = ',')}"))
debug: names(r) <- lyrs
debug: if (!is.null(rast_tif)) {
    if (fs::file_exists(rast_tif)) {
        r_tmp_tif <- tempfile(fileext = ".tif")
        r_tmp <- c(rast(rast_tif), r)
        r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
        terra::writeRaster(r_tmp, r_tmp_tif)
        fs::file_delete(rast_tif)
        fs::file_move(r_tmp_tif, rast_tif)
        rm(r)
        rm(r_tmp)
    }
    else {
        terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
    }
    r <- terra::rast(rast_tif)
}
debug: if (fs::file_exists(rast_tif)) {
    r_tmp_tif <- tempfile(fileext = ".tif")
    r_tmp <- c(rast(rast_tif), r)
    r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
    terra::writeRaster(r_tmp, r_tmp_tif)
    fs::file_delete(rast_tif)
    fs::file_move(r_tmp_tif, rast_tif)
    rm(r)
    rm(r_tmp)
} else {
    terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
}
debug: terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
debug: r <- terra::rast(rast_tif)
debug: d_r <- mutate(tidyr::pivot_longer(sf::st_drop_geometry(sf::st_as_sf(terra::zonal(x = r, 
    z = terra::vect(dplyr::select(sf_zones, dplyr::all_of(fld_zones))), 
    fun = zonal_fun, exact = T, na.rm = T, as.polygons = T))), 
    cols = -dplyr::any_of(fld_zones), names_to = "lyr", values_to = zonal_fun), 
    time = readr::parse_datetime(str_replace(lyr, glue("{var}\\|(.*)"), 
        "\\1")))
debug: if (!is.null(zonal_csv)) write_csv(d_r, zonal_csv)
debug: write_csv(d_r, zonal_csv)
debug: if (!keep_nc) unlink(dir_nc, recursive = T)
debug: unlink(dir_nc, recursive = T)
debug: return(d_r)
Downloading 1 requests, up to 190 time slices each
Called from: extractr::ed_extract(ed, var = v, sf_zones = ply, bbox = bb, 
    mask_tif = F, rast_tif = glue("{dir_out}/{nms}/{yr}.tif"), 
    zonal_fun = "mean", zonal_csv = glue("{dir_out}/{nms}/{yr}.csv"), 
    dir_nc = glue("{dir_out}/{nms}/{yr}_nc"), keep_nc = F, n_max_vals_per_req = 1e+05, 
    time_min = time_min, time_max = time_max, verbose = T)
debug: while (i_req <= n_reqs) {
    i_t_beg <- (i_req - 1) * n_t_per_req + 1
    i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
    t_req <- times_todo[c(i_t_beg, i_t_end)]
    t_req_str <- format_ISO8601(t_req, usetz = "Z")
    if (verbose) 
        message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
    ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
        ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
        0), nc)
    unlink(ncs0)
    nc_retry <- T
    nc_n_try <- 1
    n_max_retries
    while (nc_retry) {
        res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
            url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
                bbox[["xmax"]]), latitude = c(bbox[["ymin"]], 
                bbox[["ymax"]]), time = t_req_str, fmt = "nc", 
            store = rerddap::disk(path = dir_nc)))
        if (inherits(res, "try-error")) {
            err <- attr(res, "condition")
            msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
            nc_n_try <- nc_n_try + 1
            if (nc_n_try > n_max_retries) {
                stop(msg)
            }
            else {
                message(msg, "\nRETRYing...")
                Sys.sleep(1)
            }
        }
        else {
            nc_retry <- F
        }
    }
    i_req <- i_req + 1
}
debug: i_t_beg <- (i_req - 1) * n_t_per_req + 1
debug: i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
debug: t_req <- times_todo[c(i_t_beg, i_t_end)]
debug: t_req_str <- format_ISO8601(t_req, usetz = "Z")
debug: if (verbose) message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
debug: message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
Fetching request 1 of 1 (2022-01-01 to 2022-12-01) ~ 19:44:39 UTC
debug: ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
    0), nc)
debug: unlink(ncs0)
debug: nc_retry <- T
debug: nc_n_try <- 1
debug: n_max_retries
debug: while (nc_retry) {
    res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
        url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
            bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
        time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
    if (inherits(res, "try-error")) {
        err <- attr(res, "condition")
        msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
        nc_n_try <- nc_n_try + 1
        if (nc_n_try > n_max_retries) {
            stop(msg)
        }
        else {
            message(msg, "\nRETRYing...")
            Sys.sleep(1)
        }
    }
    else {
        nc_retry <- F
    }
}
debug: res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
    url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
        bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
    time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
debug: if (inherits(res, "try-error")) {
    err <- attr(res, "condition")
    msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
    nc_n_try <- nc_n_try + 1
    if (nc_n_try > n_max_retries) {
        stop(msg)
    }
    else {
        message(msg, "\nRETRYing...")
        Sys.sleep(1)
    }
} else {
    nc_retry <- F
}
debug: nc_retry <- F
debug: (while) nc_retry
debug: i_req <- i_req + 1
debug: (while) i_req <= n_reqs
debug: ncs <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size > 
    0), nc)
debug: r <- terra::rast(ncs)
debug: stopifnot(all(class(terra::time(r)) %in% c("POSIXct", "POSIXt")))
debug: idx <- dplyr::pull(dplyr::filter(dplyr::arrange(dplyr::tibble(idx = 1:terra::nlyr(r), 
    time = terra::time(r)), time), !duplicated(time)), idx)
debug: r <- terra::subset(r, idx)
debug: stopifnot(terra::crs(r, proj = T) == wgs84)
debug: if (mask_tif) r <- terra::mask(r, sf_zones)
debug: lyrs <- glue("{var}|{terra::time(r)}")
debug: if (length(dims_other) > 0 && !all(length(dims[dims_other]) == 
    1)) stop(glue("Other dimensions not yet supported: {paste(dims_other, collapse = ',')}"))
debug: names(r) <- lyrs
debug: if (!is.null(rast_tif)) {
    if (fs::file_exists(rast_tif)) {
        r_tmp_tif <- tempfile(fileext = ".tif")
        r_tmp <- c(rast(rast_tif), r)
        r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
        terra::writeRaster(r_tmp, r_tmp_tif)
        fs::file_delete(rast_tif)
        fs::file_move(r_tmp_tif, rast_tif)
        rm(r)
        rm(r_tmp)
    }
    else {
        terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
    }
    r <- terra::rast(rast_tif)
}
debug: if (fs::file_exists(rast_tif)) {
    r_tmp_tif <- tempfile(fileext = ".tif")
    r_tmp <- c(rast(rast_tif), r)
    r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
    terra::writeRaster(r_tmp, r_tmp_tif)
    fs::file_delete(rast_tif)
    fs::file_move(r_tmp_tif, rast_tif)
    rm(r)
    rm(r_tmp)
} else {
    terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
}
debug: terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
debug: r <- terra::rast(rast_tif)
debug: d_r <- mutate(tidyr::pivot_longer(sf::st_drop_geometry(sf::st_as_sf(terra::zonal(x = r, 
    z = terra::vect(dplyr::select(sf_zones, dplyr::all_of(fld_zones))), 
    fun = zonal_fun, exact = T, na.rm = T, as.polygons = T))), 
    cols = -dplyr::any_of(fld_zones), names_to = "lyr", values_to = zonal_fun), 
    time = readr::parse_datetime(str_replace(lyr, glue("{var}\\|(.*)"), 
        "\\1")))
debug: if (!is.null(zonal_csv)) write_csv(d_r, zonal_csv)
debug: write_csv(d_r, zonal_csv)
debug: if (!keep_nc) unlink(dir_nc, recursive = T)
debug: unlink(dir_nc, recursive = T)
debug: return(d_r)
Downloading 1 requests, up to 190 time slices each
Called from: extractr::ed_extract(ed, var = v, sf_zones = ply, bbox = bb, 
    mask_tif = F, rast_tif = glue("{dir_out}/{nms}/{yr}.tif"), 
    zonal_fun = "mean", zonal_csv = glue("{dir_out}/{nms}/{yr}.csv"), 
    dir_nc = glue("{dir_out}/{nms}/{yr}_nc"), keep_nc = F, n_max_vals_per_req = 1e+05, 
    time_min = time_min, time_max = time_max, verbose = T)
debug: while (i_req <= n_reqs) {
    i_t_beg <- (i_req - 1) * n_t_per_req + 1
    i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
    t_req <- times_todo[c(i_t_beg, i_t_end)]
    t_req_str <- format_ISO8601(t_req, usetz = "Z")
    if (verbose) 
        message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
    ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
        ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
        0), nc)
    unlink(ncs0)
    nc_retry <- T
    nc_n_try <- 1
    n_max_retries
    while (nc_retry) {
        res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
            url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
                bbox[["xmax"]]), latitude = c(bbox[["ymin"]], 
                bbox[["ymax"]]), time = t_req_str, fmt = "nc", 
            store = rerddap::disk(path = dir_nc)))
        if (inherits(res, "try-error")) {
            err <- attr(res, "condition")
            msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
            nc_n_try <- nc_n_try + 1
            if (nc_n_try > n_max_retries) {
                stop(msg)
            }
            else {
                message(msg, "\nRETRYing...")
                Sys.sleep(1)
            }
        }
        else {
            nc_retry <- F
        }
    }
    i_req <- i_req + 1
}
debug: i_t_beg <- (i_req - 1) * n_t_per_req + 1
debug: i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
debug: t_req <- times_todo[c(i_t_beg, i_t_end)]
debug: t_req_str <- format_ISO8601(t_req, usetz = "Z")
debug: if (verbose) message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
debug: message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
Fetching request 1 of 1 (2023-01-01 to 2023-12-01) ~ 19:44:41 UTC
debug: ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
    0), nc)
debug: unlink(ncs0)
debug: nc_retry <- T
debug: nc_n_try <- 1
debug: n_max_retries
debug: while (nc_retry) {
    res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
        url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
            bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
        time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
    if (inherits(res, "try-error")) {
        err <- attr(res, "condition")
        msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
        nc_n_try <- nc_n_try + 1
        if (nc_n_try > n_max_retries) {
            stop(msg)
        }
        else {
            message(msg, "\nRETRYing...")
            Sys.sleep(1)
        }
    }
    else {
        nc_retry <- F
    }
}
debug: res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
    url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
        bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
    time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
debug: if (inherits(res, "try-error")) {
    err <- attr(res, "condition")
    msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
    nc_n_try <- nc_n_try + 1
    if (nc_n_try > n_max_retries) {
        stop(msg)
    }
    else {
        message(msg, "\nRETRYing...")
        Sys.sleep(1)
    }
} else {
    nc_retry <- F
}
debug: nc_retry <- F
debug: (while) nc_retry
debug: i_req <- i_req + 1
debug: (while) i_req <= n_reqs
debug: ncs <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size > 
    0), nc)
debug: r <- terra::rast(ncs)
debug: stopifnot(all(class(terra::time(r)) %in% c("POSIXct", "POSIXt")))
debug: idx <- dplyr::pull(dplyr::filter(dplyr::arrange(dplyr::tibble(idx = 1:terra::nlyr(r), 
    time = terra::time(r)), time), !duplicated(time)), idx)
debug: r <- terra::subset(r, idx)
debug: stopifnot(terra::crs(r, proj = T) == wgs84)
debug: if (mask_tif) r <- terra::mask(r, sf_zones)
debug: lyrs <- glue("{var}|{terra::time(r)}")
debug: if (length(dims_other) > 0 && !all(length(dims[dims_other]) == 
    1)) stop(glue("Other dimensions not yet supported: {paste(dims_other, collapse = ',')}"))
debug: names(r) <- lyrs
debug: if (!is.null(rast_tif)) {
    if (fs::file_exists(rast_tif)) {
        r_tmp_tif <- tempfile(fileext = ".tif")
        r_tmp <- c(rast(rast_tif), r)
        r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
        terra::writeRaster(r_tmp, r_tmp_tif)
        fs::file_delete(rast_tif)
        fs::file_move(r_tmp_tif, rast_tif)
        rm(r)
        rm(r_tmp)
    }
    else {
        terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
    }
    r <- terra::rast(rast_tif)
}
debug: if (fs::file_exists(rast_tif)) {
    r_tmp_tif <- tempfile(fileext = ".tif")
    r_tmp <- c(rast(rast_tif), r)
    r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
    terra::writeRaster(r_tmp, r_tmp_tif)
    fs::file_delete(rast_tif)
    fs::file_move(r_tmp_tif, rast_tif)
    rm(r)
    rm(r_tmp)
} else {
    terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
}
debug: terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
debug: r <- terra::rast(rast_tif)
debug: d_r <- mutate(tidyr::pivot_longer(sf::st_drop_geometry(sf::st_as_sf(terra::zonal(x = r, 
    z = terra::vect(dplyr::select(sf_zones, dplyr::all_of(fld_zones))), 
    fun = zonal_fun, exact = T, na.rm = T, as.polygons = T))), 
    cols = -dplyr::any_of(fld_zones), names_to = "lyr", values_to = zonal_fun), 
    time = readr::parse_datetime(str_replace(lyr, glue("{var}\\|(.*)"), 
        "\\1")))
debug: if (!is.null(zonal_csv)) write_csv(d_r, zonal_csv)
debug: write_csv(d_r, zonal_csv)
debug: if (!keep_nc) unlink(dir_nc, recursive = T)
debug: unlink(dir_nc, recursive = T)
debug: return(d_r)
Downloading 1 requests, up to 190 time slices each
Called from: extractr::ed_extract(ed, var = v, sf_zones = ply, bbox = bb, 
    mask_tif = F, rast_tif = glue("{dir_out}/{nms}/{yr}.tif"), 
    zonal_fun = "mean", zonal_csv = glue("{dir_out}/{nms}/{yr}.csv"), 
    dir_nc = glue("{dir_out}/{nms}/{yr}_nc"), keep_nc = F, n_max_vals_per_req = 1e+05, 
    time_min = time_min, time_max = time_max, verbose = T)
debug: while (i_req <= n_reqs) {
    i_t_beg <- (i_req - 1) * n_t_per_req + 1
    i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
    t_req <- times_todo[c(i_t_beg, i_t_end)]
    t_req_str <- format_ISO8601(t_req, usetz = "Z")
    if (verbose) 
        message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
    ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
        ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
        0), nc)
    unlink(ncs0)
    nc_retry <- T
    nc_n_try <- 1
    n_max_retries
    while (nc_retry) {
        res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
            url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
                bbox[["xmax"]]), latitude = c(bbox[["ymin"]], 
                bbox[["ymax"]]), time = t_req_str, fmt = "nc", 
            store = rerddap::disk(path = dir_nc)))
        if (inherits(res, "try-error")) {
            err <- attr(res, "condition")
            msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
            nc_n_try <- nc_n_try + 1
            if (nc_n_try > n_max_retries) {
                stop(msg)
            }
            else {
                message(msg, "\nRETRYing...")
                Sys.sleep(1)
            }
        }
        else {
            nc_retry <- F
        }
    }
    i_req <- i_req + 1
}
debug: i_t_beg <- (i_req - 1) * n_t_per_req + 1
debug: i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
debug: t_req <- times_todo[c(i_t_beg, i_t_end)]
debug: t_req_str <- format_ISO8601(t_req, usetz = "Z")
debug: if (verbose) message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
debug: message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
Fetching request 1 of 1 (2024-01-01 to 2024-12-01) ~ 19:44:43 UTC
debug: ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
    0), nc)
debug: unlink(ncs0)
debug: nc_retry <- T
debug: nc_n_try <- 1
debug: n_max_retries
debug: while (nc_retry) {
    res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
        url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
            bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
        time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
    if (inherits(res, "try-error")) {
        err <- attr(res, "condition")
        msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
        nc_n_try <- nc_n_try + 1
        if (nc_n_try > n_max_retries) {
            stop(msg)
        }
        else {
            message(msg, "\nRETRYing...")
            Sys.sleep(1)
        }
    }
    else {
        nc_retry <- F
    }
}
debug: res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
    url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
        bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
    time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
debug: if (inherits(res, "try-error")) {
    err <- attr(res, "condition")
    msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
    nc_n_try <- nc_n_try + 1
    if (nc_n_try > n_max_retries) {
        stop(msg)
    }
    else {
        message(msg, "\nRETRYing...")
        Sys.sleep(1)
    }
} else {
    nc_retry <- F
}
debug: nc_retry <- F
debug: (while) nc_retry
debug: i_req <- i_req + 1
debug: (while) i_req <= n_reqs
debug: ncs <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size > 
    0), nc)
debug: r <- terra::rast(ncs)
debug: stopifnot(all(class(terra::time(r)) %in% c("POSIXct", "POSIXt")))
debug: idx <- dplyr::pull(dplyr::filter(dplyr::arrange(dplyr::tibble(idx = 1:terra::nlyr(r), 
    time = terra::time(r)), time), !duplicated(time)), idx)
debug: r <- terra::subset(r, idx)
debug: stopifnot(terra::crs(r, proj = T) == wgs84)
debug: if (mask_tif) r <- terra::mask(r, sf_zones)
debug: lyrs <- glue("{var}|{terra::time(r)}")
debug: if (length(dims_other) > 0 && !all(length(dims[dims_other]) == 
    1)) stop(glue("Other dimensions not yet supported: {paste(dims_other, collapse = ',')}"))
debug: names(r) <- lyrs
debug: if (!is.null(rast_tif)) {
    if (fs::file_exists(rast_tif)) {
        r_tmp_tif <- tempfile(fileext = ".tif")
        r_tmp <- c(rast(rast_tif), r)
        r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
        terra::writeRaster(r_tmp, r_tmp_tif)
        fs::file_delete(rast_tif)
        fs::file_move(r_tmp_tif, rast_tif)
        rm(r)
        rm(r_tmp)
    }
    else {
        terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
    }
    r <- terra::rast(rast_tif)
}
debug: if (fs::file_exists(rast_tif)) {
    r_tmp_tif <- tempfile(fileext = ".tif")
    r_tmp <- c(rast(rast_tif), r)
    r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
    terra::writeRaster(r_tmp, r_tmp_tif)
    fs::file_delete(rast_tif)
    fs::file_move(r_tmp_tif, rast_tif)
    rm(r)
    rm(r_tmp)
} else {
    terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
}
debug: terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
debug: r <- terra::rast(rast_tif)
debug: d_r <- mutate(tidyr::pivot_longer(sf::st_drop_geometry(sf::st_as_sf(terra::zonal(x = r, 
    z = terra::vect(dplyr::select(sf_zones, dplyr::all_of(fld_zones))), 
    fun = zonal_fun, exact = T, na.rm = T, as.polygons = T))), 
    cols = -dplyr::any_of(fld_zones), names_to = "lyr", values_to = zonal_fun), 
    time = readr::parse_datetime(str_replace(lyr, glue("{var}\\|(.*)"), 
        "\\1")))
debug: if (!is.null(zonal_csv)) write_csv(d_r, zonal_csv)
debug: write_csv(d_r, zonal_csv)
debug: if (!keep_nc) unlink(dir_nc, recursive = T)
debug: unlink(dir_nc, recursive = T)
debug: return(d_r)
Downloading 1 requests, up to 190 time slices each
Called from: extractr::ed_extract(ed, var = v, sf_zones = ply, bbox = bb, 
    mask_tif = F, rast_tif = glue("{dir_out}/{nms}/{yr}.tif"), 
    zonal_fun = "mean", zonal_csv = glue("{dir_out}/{nms}/{yr}.csv"), 
    dir_nc = glue("{dir_out}/{nms}/{yr}_nc"), keep_nc = F, n_max_vals_per_req = 1e+05, 
    time_min = time_min, time_max = time_max, verbose = T)
debug: while (i_req <= n_reqs) {
    i_t_beg <- (i_req - 1) * n_t_per_req + 1
    i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
    t_req <- times_todo[c(i_t_beg, i_t_end)]
    t_req_str <- format_ISO8601(t_req, usetz = "Z")
    if (verbose) 
        message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
    ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
        ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
        0), nc)
    unlink(ncs0)
    nc_retry <- T
    nc_n_try <- 1
    n_max_retries
    while (nc_retry) {
        res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
            url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
                bbox[["xmax"]]), latitude = c(bbox[["ymin"]], 
                bbox[["ymax"]]), time = t_req_str, fmt = "nc", 
            store = rerddap::disk(path = dir_nc)))
        if (inherits(res, "try-error")) {
            err <- attr(res, "condition")
            msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
            nc_n_try <- nc_n_try + 1
            if (nc_n_try > n_max_retries) {
                stop(msg)
            }
            else {
                message(msg, "\nRETRYing...")
                Sys.sleep(1)
            }
        }
        else {
            nc_retry <- F
        }
    }
    i_req <- i_req + 1
}
debug: i_t_beg <- (i_req - 1) * n_t_per_req + 1
debug: i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
debug: t_req <- times_todo[c(i_t_beg, i_t_end)]
debug: t_req_str <- format_ISO8601(t_req, usetz = "Z")
debug: if (verbose) message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
debug: message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
Fetching request 1 of 1 (2025-01-01 to 2025-07-01) ~ 19:44:45 UTC
debug: ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
    0), nc)
debug: unlink(ncs0)
debug: nc_retry <- T
debug: nc_n_try <- 1
debug: n_max_retries
debug: while (nc_retry) {
    res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
        url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
            bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
        time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
    if (inherits(res, "try-error")) {
        err <- attr(res, "condition")
        msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
        nc_n_try <- nc_n_try + 1
        if (nc_n_try > n_max_retries) {
            stop(msg)
        }
        else {
            message(msg, "\nRETRYing...")
            Sys.sleep(1)
        }
    }
    else {
        nc_retry <- F
    }
}
debug: res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
    url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
        bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
    time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
debug: if (inherits(res, "try-error")) {
    err <- attr(res, "condition")
    msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
    nc_n_try <- nc_n_try + 1
    if (nc_n_try > n_max_retries) {
        stop(msg)
    }
    else {
        message(msg, "\nRETRYing...")
        Sys.sleep(1)
    }
} else {
    nc_retry <- F
}
debug: nc_retry <- F
debug: (while) nc_retry
debug: i_req <- i_req + 1
debug: (while) i_req <= n_reqs
debug: ncs <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size > 
    0), nc)
debug: r <- terra::rast(ncs)
debug: stopifnot(all(class(terra::time(r)) %in% c("POSIXct", "POSIXt")))
debug: idx <- dplyr::pull(dplyr::filter(dplyr::arrange(dplyr::tibble(idx = 1:terra::nlyr(r), 
    time = terra::time(r)), time), !duplicated(time)), idx)
debug: r <- terra::subset(r, idx)
debug: stopifnot(terra::crs(r, proj = T) == wgs84)
debug: if (mask_tif) r <- terra::mask(r, sf_zones)
debug: lyrs <- glue("{var}|{terra::time(r)}")
debug: if (length(dims_other) > 0 && !all(length(dims[dims_other]) == 
    1)) stop(glue("Other dimensions not yet supported: {paste(dims_other, collapse = ',')}"))
debug: names(r) <- lyrs
debug: if (!is.null(rast_tif)) {
    if (fs::file_exists(rast_tif)) {
        r_tmp_tif <- tempfile(fileext = ".tif")
        r_tmp <- c(rast(rast_tif), r)
        r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
        terra::writeRaster(r_tmp, r_tmp_tif)
        fs::file_delete(rast_tif)
        fs::file_move(r_tmp_tif, rast_tif)
        rm(r)
        rm(r_tmp)
    }
    else {
        terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
    }
    r <- terra::rast(rast_tif)
}
debug: if (fs::file_exists(rast_tif)) {
    r_tmp_tif <- tempfile(fileext = ".tif")
    r_tmp <- c(rast(rast_tif), r)
    r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
    terra::writeRaster(r_tmp, r_tmp_tif)
    fs::file_delete(rast_tif)
    fs::file_move(r_tmp_tif, rast_tif)
    rm(r)
    rm(r_tmp)
} else {
    terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
}
debug: terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
debug: r <- terra::rast(rast_tif)
debug: d_r <- mutate(tidyr::pivot_longer(sf::st_drop_geometry(sf::st_as_sf(terra::zonal(x = r, 
    z = terra::vect(dplyr::select(sf_zones, dplyr::all_of(fld_zones))), 
    fun = zonal_fun, exact = T, na.rm = T, as.polygons = T))), 
    cols = -dplyr::any_of(fld_zones), names_to = "lyr", values_to = zonal_fun), 
    time = readr::parse_datetime(str_replace(lyr, glue("{var}\\|(.*)"), 
        "\\1")))
debug: if (!is.null(zonal_csv)) write_csv(d_r, zonal_csv)
debug: write_csv(d_r, zonal_csv)
debug: if (!keep_nc) unlink(dir_nc, recursive = T)
debug: unlink(dir_nc, recursive = T)
debug: return(d_r)
Downloading 1 requests, up to 512 time slices each
Called from: extractr::ed_extract(ed, var = v, sf_zones = ply, bbox = bb, 
    mask_tif = F, rast_tif = glue("{dir_out}/{nms}/{yr}.tif"), 
    zonal_fun = "mean", zonal_csv = glue("{dir_out}/{nms}/{yr}.csv"), 
    dir_nc = glue("{dir_out}/{nms}/{yr}_nc"), keep_nc = F, n_max_vals_per_req = 1e+05, 
    time_min = time_min, time_max = time_max, verbose = T)
debug: while (i_req <= n_reqs) {
    i_t_beg <- (i_req - 1) * n_t_per_req + 1
    i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
    t_req <- times_todo[c(i_t_beg, i_t_end)]
    t_req_str <- format_ISO8601(t_req, usetz = "Z")
    if (verbose) 
        message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
    ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
        ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
        0), nc)
    unlink(ncs0)
    nc_retry <- T
    nc_n_try <- 1
    n_max_retries
    while (nc_retry) {
        res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
            url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
                bbox[["xmax"]]), latitude = c(bbox[["ymin"]], 
                bbox[["ymax"]]), time = t_req_str, fmt = "nc", 
            store = rerddap::disk(path = dir_nc)))
        if (inherits(res, "try-error")) {
            err <- attr(res, "condition")
            msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
            nc_n_try <- nc_n_try + 1
            if (nc_n_try > n_max_retries) {
                stop(msg)
            }
            else {
                message(msg, "\nRETRYing...")
                Sys.sleep(1)
            }
        }
        else {
            nc_retry <- F
        }
    }
    i_req <- i_req + 1
}
debug: i_t_beg <- (i_req - 1) * n_t_per_req + 1
debug: i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
debug: t_req <- times_todo[c(i_t_beg, i_t_end)]
debug: t_req_str <- format_ISO8601(t_req, usetz = "Z")
debug: if (verbose) message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
debug: message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
Fetching request 1 of 1 (1998-01-01 to 1998-12-01) ~ 19:44:47 UTC
debug: ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
    0), nc)
debug: unlink(ncs0)
debug: nc_retry <- T
debug: nc_n_try <- 1
debug: n_max_retries
debug: while (nc_retry) {
    res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
        url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
            bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
        time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
    if (inherits(res, "try-error")) {
        err <- attr(res, "condition")
        msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
        nc_n_try <- nc_n_try + 1
        if (nc_n_try > n_max_retries) {
            stop(msg)
        }
        else {
            message(msg, "\nRETRYing...")
            Sys.sleep(1)
        }
    }
    else {
        nc_retry <- F
    }
}
debug: res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
    url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
        bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
    time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
debug: if (inherits(res, "try-error")) {
    err <- attr(res, "condition")
    msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
    nc_n_try <- nc_n_try + 1
    if (nc_n_try > n_max_retries) {
        stop(msg)
    }
    else {
        message(msg, "\nRETRYing...")
        Sys.sleep(1)
    }
} else {
    nc_retry <- F
}
debug: nc_retry <- F
debug: (while) nc_retry
debug: i_req <- i_req + 1
debug: (while) i_req <= n_reqs
debug: ncs <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size > 
    0), nc)
debug: r <- terra::rast(ncs)
debug: stopifnot(all(class(terra::time(r)) %in% c("POSIXct", "POSIXt")))
debug: idx <- dplyr::pull(dplyr::filter(dplyr::arrange(dplyr::tibble(idx = 1:terra::nlyr(r), 
    time = terra::time(r)), time), !duplicated(time)), idx)
debug: r <- terra::subset(r, idx)
debug: stopifnot(terra::crs(r, proj = T) == wgs84)
debug: if (mask_tif) r <- terra::mask(r, sf_zones)
debug: lyrs <- glue("{var}|{terra::time(r)}")
debug: if (length(dims_other) > 0 && !all(length(dims[dims_other]) == 
    1)) stop(glue("Other dimensions not yet supported: {paste(dims_other, collapse = ',')}"))
debug: names(r) <- lyrs
debug: if (!is.null(rast_tif)) {
    if (fs::file_exists(rast_tif)) {
        r_tmp_tif <- tempfile(fileext = ".tif")
        r_tmp <- c(rast(rast_tif), r)
        r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
        terra::writeRaster(r_tmp, r_tmp_tif)
        fs::file_delete(rast_tif)
        fs::file_move(r_tmp_tif, rast_tif)
        rm(r)
        rm(r_tmp)
    }
    else {
        terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
    }
    r <- terra::rast(rast_tif)
}
debug: if (fs::file_exists(rast_tif)) {
    r_tmp_tif <- tempfile(fileext = ".tif")
    r_tmp <- c(rast(rast_tif), r)
    r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
    terra::writeRaster(r_tmp, r_tmp_tif)
    fs::file_delete(rast_tif)
    fs::file_move(r_tmp_tif, rast_tif)
    rm(r)
    rm(r_tmp)
} else {
    terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
}
debug: terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
debug: r <- terra::rast(rast_tif)
debug: d_r <- mutate(tidyr::pivot_longer(sf::st_drop_geometry(sf::st_as_sf(terra::zonal(x = r, 
    z = terra::vect(dplyr::select(sf_zones, dplyr::all_of(fld_zones))), 
    fun = zonal_fun, exact = T, na.rm = T, as.polygons = T))), 
    cols = -dplyr::any_of(fld_zones), names_to = "lyr", values_to = zonal_fun), 
    time = readr::parse_datetime(str_replace(lyr, glue("{var}\\|(.*)"), 
        "\\1")))
debug: if (!is.null(zonal_csv)) write_csv(d_r, zonal_csv)
debug: write_csv(d_r, zonal_csv)
debug: if (!keep_nc) unlink(dir_nc, recursive = T)
debug: unlink(dir_nc, recursive = T)
debug: return(d_r)
Downloading 1 requests, up to 512 time slices each
Called from: extractr::ed_extract(ed, var = v, sf_zones = ply, bbox = bb, 
    mask_tif = F, rast_tif = glue("{dir_out}/{nms}/{yr}.tif"), 
    zonal_fun = "mean", zonal_csv = glue("{dir_out}/{nms}/{yr}.csv"), 
    dir_nc = glue("{dir_out}/{nms}/{yr}_nc"), keep_nc = F, n_max_vals_per_req = 1e+05, 
    time_min = time_min, time_max = time_max, verbose = T)
debug: while (i_req <= n_reqs) {
    i_t_beg <- (i_req - 1) * n_t_per_req + 1
    i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
    t_req <- times_todo[c(i_t_beg, i_t_end)]
    t_req_str <- format_ISO8601(t_req, usetz = "Z")
    if (verbose) 
        message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
    ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
        ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
        0), nc)
    unlink(ncs0)
    nc_retry <- T
    nc_n_try <- 1
    n_max_retries
    while (nc_retry) {
        res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
            url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
                bbox[["xmax"]]), latitude = c(bbox[["ymin"]], 
                bbox[["ymax"]]), time = t_req_str, fmt = "nc", 
            store = rerddap::disk(path = dir_nc)))
        if (inherits(res, "try-error")) {
            err <- attr(res, "condition")
            msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
            nc_n_try <- nc_n_try + 1
            if (nc_n_try > n_max_retries) {
                stop(msg)
            }
            else {
                message(msg, "\nRETRYing...")
                Sys.sleep(1)
            }
        }
        else {
            nc_retry <- F
        }
    }
    i_req <- i_req + 1
}
debug: i_t_beg <- (i_req - 1) * n_t_per_req + 1
debug: i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
debug: t_req <- times_todo[c(i_t_beg, i_t_end)]
debug: t_req_str <- format_ISO8601(t_req, usetz = "Z")
debug: if (verbose) message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
debug: message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
Fetching request 1 of 1 (1999-01-01 to 1999-12-01) ~ 19:44:48 UTC
debug: ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
    0), nc)
debug: unlink(ncs0)
debug: nc_retry <- T
debug: nc_n_try <- 1
debug: n_max_retries
debug: while (nc_retry) {
    res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
        url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
            bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
        time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
    if (inherits(res, "try-error")) {
        err <- attr(res, "condition")
        msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
        nc_n_try <- nc_n_try + 1
        if (nc_n_try > n_max_retries) {
            stop(msg)
        }
        else {
            message(msg, "\nRETRYing...")
            Sys.sleep(1)
        }
    }
    else {
        nc_retry <- F
    }
}
debug: res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
    url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
        bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
    time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
debug: if (inherits(res, "try-error")) {
    err <- attr(res, "condition")
    msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
    nc_n_try <- nc_n_try + 1
    if (nc_n_try > n_max_retries) {
        stop(msg)
    }
    else {
        message(msg, "\nRETRYing...")
        Sys.sleep(1)
    }
} else {
    nc_retry <- F
}
debug: nc_retry <- F
debug: (while) nc_retry
debug: i_req <- i_req + 1
debug: (while) i_req <= n_reqs
debug: ncs <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size > 
    0), nc)
debug: r <- terra::rast(ncs)
debug: stopifnot(all(class(terra::time(r)) %in% c("POSIXct", "POSIXt")))
debug: idx <- dplyr::pull(dplyr::filter(dplyr::arrange(dplyr::tibble(idx = 1:terra::nlyr(r), 
    time = terra::time(r)), time), !duplicated(time)), idx)
debug: r <- terra::subset(r, idx)
debug: stopifnot(terra::crs(r, proj = T) == wgs84)
debug: if (mask_tif) r <- terra::mask(r, sf_zones)
debug: lyrs <- glue("{var}|{terra::time(r)}")
debug: if (length(dims_other) > 0 && !all(length(dims[dims_other]) == 
    1)) stop(glue("Other dimensions not yet supported: {paste(dims_other, collapse = ',')}"))
debug: names(r) <- lyrs
debug: if (!is.null(rast_tif)) {
    if (fs::file_exists(rast_tif)) {
        r_tmp_tif <- tempfile(fileext = ".tif")
        r_tmp <- c(rast(rast_tif), r)
        r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
        terra::writeRaster(r_tmp, r_tmp_tif)
        fs::file_delete(rast_tif)
        fs::file_move(r_tmp_tif, rast_tif)
        rm(r)
        rm(r_tmp)
    }
    else {
        terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
    }
    r <- terra::rast(rast_tif)
}
debug: if (fs::file_exists(rast_tif)) {
    r_tmp_tif <- tempfile(fileext = ".tif")
    r_tmp <- c(rast(rast_tif), r)
    r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
    terra::writeRaster(r_tmp, r_tmp_tif)
    fs::file_delete(rast_tif)
    fs::file_move(r_tmp_tif, rast_tif)
    rm(r)
    rm(r_tmp)
} else {
    terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
}
debug: terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
debug: r <- terra::rast(rast_tif)
debug: d_r <- mutate(tidyr::pivot_longer(sf::st_drop_geometry(sf::st_as_sf(terra::zonal(x = r, 
    z = terra::vect(dplyr::select(sf_zones, dplyr::all_of(fld_zones))), 
    fun = zonal_fun, exact = T, na.rm = T, as.polygons = T))), 
    cols = -dplyr::any_of(fld_zones), names_to = "lyr", values_to = zonal_fun), 
    time = readr::parse_datetime(str_replace(lyr, glue("{var}\\|(.*)"), 
        "\\1")))
debug: if (!is.null(zonal_csv)) write_csv(d_r, zonal_csv)
debug: write_csv(d_r, zonal_csv)
debug: if (!keep_nc) unlink(dir_nc, recursive = T)
debug: unlink(dir_nc, recursive = T)
debug: return(d_r)
Downloading 1 requests, up to 512 time slices each
Called from: extractr::ed_extract(ed, var = v, sf_zones = ply, bbox = bb, 
    mask_tif = F, rast_tif = glue("{dir_out}/{nms}/{yr}.tif"), 
    zonal_fun = "mean", zonal_csv = glue("{dir_out}/{nms}/{yr}.csv"), 
    dir_nc = glue("{dir_out}/{nms}/{yr}_nc"), keep_nc = F, n_max_vals_per_req = 1e+05, 
    time_min = time_min, time_max = time_max, verbose = T)
debug: while (i_req <= n_reqs) {
    i_t_beg <- (i_req - 1) * n_t_per_req + 1
    i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
    t_req <- times_todo[c(i_t_beg, i_t_end)]
    t_req_str <- format_ISO8601(t_req, usetz = "Z")
    if (verbose) 
        message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
    ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
        ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
        0), nc)
    unlink(ncs0)
    nc_retry <- T
    nc_n_try <- 1
    n_max_retries
    while (nc_retry) {
        res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
            url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
                bbox[["xmax"]]), latitude = c(bbox[["ymin"]], 
                bbox[["ymax"]]), time = t_req_str, fmt = "nc", 
            store = rerddap::disk(path = dir_nc)))
        if (inherits(res, "try-error")) {
            err <- attr(res, "condition")
            msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
            nc_n_try <- nc_n_try + 1
            if (nc_n_try > n_max_retries) {
                stop(msg)
            }
            else {
                message(msg, "\nRETRYing...")
                Sys.sleep(1)
            }
        }
        else {
            nc_retry <- F
        }
    }
    i_req <- i_req + 1
}
debug: i_t_beg <- (i_req - 1) * n_t_per_req + 1
debug: i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
debug: t_req <- times_todo[c(i_t_beg, i_t_end)]
debug: t_req_str <- format_ISO8601(t_req, usetz = "Z")
debug: if (verbose) message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
debug: message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
Fetching request 1 of 1 (2000-01-01 to 2000-12-01) ~ 19:44:50 UTC
debug: ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
    0), nc)
debug: unlink(ncs0)
debug: nc_retry <- T
debug: nc_n_try <- 1
debug: n_max_retries
debug: while (nc_retry) {
    res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
        url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
            bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
        time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
    if (inherits(res, "try-error")) {
        err <- attr(res, "condition")
        msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
        nc_n_try <- nc_n_try + 1
        if (nc_n_try > n_max_retries) {
            stop(msg)
        }
        else {
            message(msg, "\nRETRYing...")
            Sys.sleep(1)
        }
    }
    else {
        nc_retry <- F
    }
}
debug: res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
    url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
        bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
    time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
debug: if (inherits(res, "try-error")) {
    err <- attr(res, "condition")
    msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
    nc_n_try <- nc_n_try + 1
    if (nc_n_try > n_max_retries) {
        stop(msg)
    }
    else {
        message(msg, "\nRETRYing...")
        Sys.sleep(1)
    }
} else {
    nc_retry <- F
}
debug: nc_retry <- F
debug: (while) nc_retry
debug: i_req <- i_req + 1
debug: (while) i_req <= n_reqs
debug: ncs <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size > 
    0), nc)
debug: r <- terra::rast(ncs)
debug: stopifnot(all(class(terra::time(r)) %in% c("POSIXct", "POSIXt")))
debug: idx <- dplyr::pull(dplyr::filter(dplyr::arrange(dplyr::tibble(idx = 1:terra::nlyr(r), 
    time = terra::time(r)), time), !duplicated(time)), idx)
debug: r <- terra::subset(r, idx)
debug: stopifnot(terra::crs(r, proj = T) == wgs84)
debug: if (mask_tif) r <- terra::mask(r, sf_zones)
debug: lyrs <- glue("{var}|{terra::time(r)}")
debug: if (length(dims_other) > 0 && !all(length(dims[dims_other]) == 
    1)) stop(glue("Other dimensions not yet supported: {paste(dims_other, collapse = ',')}"))
debug: names(r) <- lyrs
debug: if (!is.null(rast_tif)) {
    if (fs::file_exists(rast_tif)) {
        r_tmp_tif <- tempfile(fileext = ".tif")
        r_tmp <- c(rast(rast_tif), r)
        r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
        terra::writeRaster(r_tmp, r_tmp_tif)
        fs::file_delete(rast_tif)
        fs::file_move(r_tmp_tif, rast_tif)
        rm(r)
        rm(r_tmp)
    }
    else {
        terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
    }
    r <- terra::rast(rast_tif)
}
debug: if (fs::file_exists(rast_tif)) {
    r_tmp_tif <- tempfile(fileext = ".tif")
    r_tmp <- c(rast(rast_tif), r)
    r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
    terra::writeRaster(r_tmp, r_tmp_tif)
    fs::file_delete(rast_tif)
    fs::file_move(r_tmp_tif, rast_tif)
    rm(r)
    rm(r_tmp)
} else {
    terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
}
debug: terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
debug: r <- terra::rast(rast_tif)
debug: d_r <- mutate(tidyr::pivot_longer(sf::st_drop_geometry(sf::st_as_sf(terra::zonal(x = r, 
    z = terra::vect(dplyr::select(sf_zones, dplyr::all_of(fld_zones))), 
    fun = zonal_fun, exact = T, na.rm = T, as.polygons = T))), 
    cols = -dplyr::any_of(fld_zones), names_to = "lyr", values_to = zonal_fun), 
    time = readr::parse_datetime(str_replace(lyr, glue("{var}\\|(.*)"), 
        "\\1")))
debug: if (!is.null(zonal_csv)) write_csv(d_r, zonal_csv)
debug: write_csv(d_r, zonal_csv)
debug: if (!keep_nc) unlink(dir_nc, recursive = T)
debug: unlink(dir_nc, recursive = T)
debug: return(d_r)
Downloading 1 requests, up to 512 time slices each
Called from: extractr::ed_extract(ed, var = v, sf_zones = ply, bbox = bb, 
    mask_tif = F, rast_tif = glue("{dir_out}/{nms}/{yr}.tif"), 
    zonal_fun = "mean", zonal_csv = glue("{dir_out}/{nms}/{yr}.csv"), 
    dir_nc = glue("{dir_out}/{nms}/{yr}_nc"), keep_nc = F, n_max_vals_per_req = 1e+05, 
    time_min = time_min, time_max = time_max, verbose = T)
debug: while (i_req <= n_reqs) {
    i_t_beg <- (i_req - 1) * n_t_per_req + 1
    i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
    t_req <- times_todo[c(i_t_beg, i_t_end)]
    t_req_str <- format_ISO8601(t_req, usetz = "Z")
    if (verbose) 
        message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
    ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
        ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
        0), nc)
    unlink(ncs0)
    nc_retry <- T
    nc_n_try <- 1
    n_max_retries
    while (nc_retry) {
        res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
            url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
                bbox[["xmax"]]), latitude = c(bbox[["ymin"]], 
                bbox[["ymax"]]), time = t_req_str, fmt = "nc", 
            store = rerddap::disk(path = dir_nc)))
        if (inherits(res, "try-error")) {
            err <- attr(res, "condition")
            msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
            nc_n_try <- nc_n_try + 1
            if (nc_n_try > n_max_retries) {
                stop(msg)
            }
            else {
                message(msg, "\nRETRYing...")
                Sys.sleep(1)
            }
        }
        else {
            nc_retry <- F
        }
    }
    i_req <- i_req + 1
}
debug: i_t_beg <- (i_req - 1) * n_t_per_req + 1
debug: i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
debug: t_req <- times_todo[c(i_t_beg, i_t_end)]
debug: t_req_str <- format_ISO8601(t_req, usetz = "Z")
debug: if (verbose) message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
debug: message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
Fetching request 1 of 1 (2001-01-01 to 2001-12-01) ~ 19:44:52 UTC
debug: ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
    0), nc)
debug: unlink(ncs0)
debug: nc_retry <- T
debug: nc_n_try <- 1
debug: n_max_retries
debug: while (nc_retry) {
    res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
        url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
            bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
        time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
    if (inherits(res, "try-error")) {
        err <- attr(res, "condition")
        msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
        nc_n_try <- nc_n_try + 1
        if (nc_n_try > n_max_retries) {
            stop(msg)
        }
        else {
            message(msg, "\nRETRYing...")
            Sys.sleep(1)
        }
    }
    else {
        nc_retry <- F
    }
}
debug: res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
    url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
        bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
    time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
debug: if (inherits(res, "try-error")) {
    err <- attr(res, "condition")
    msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
    nc_n_try <- nc_n_try + 1
    if (nc_n_try > n_max_retries) {
        stop(msg)
    }
    else {
        message(msg, "\nRETRYing...")
        Sys.sleep(1)
    }
} else {
    nc_retry <- F
}
debug: nc_retry <- F
debug: (while) nc_retry
debug: i_req <- i_req + 1
debug: (while) i_req <= n_reqs
debug: ncs <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size > 
    0), nc)
debug: r <- terra::rast(ncs)
debug: stopifnot(all(class(terra::time(r)) %in% c("POSIXct", "POSIXt")))
debug: idx <- dplyr::pull(dplyr::filter(dplyr::arrange(dplyr::tibble(idx = 1:terra::nlyr(r), 
    time = terra::time(r)), time), !duplicated(time)), idx)
debug: r <- terra::subset(r, idx)
debug: stopifnot(terra::crs(r, proj = T) == wgs84)
debug: if (mask_tif) r <- terra::mask(r, sf_zones)
debug: lyrs <- glue("{var}|{terra::time(r)}")
debug: if (length(dims_other) > 0 && !all(length(dims[dims_other]) == 
    1)) stop(glue("Other dimensions not yet supported: {paste(dims_other, collapse = ',')}"))
debug: names(r) <- lyrs
debug: if (!is.null(rast_tif)) {
    if (fs::file_exists(rast_tif)) {
        r_tmp_tif <- tempfile(fileext = ".tif")
        r_tmp <- c(rast(rast_tif), r)
        r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
        terra::writeRaster(r_tmp, r_tmp_tif)
        fs::file_delete(rast_tif)
        fs::file_move(r_tmp_tif, rast_tif)
        rm(r)
        rm(r_tmp)
    }
    else {
        terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
    }
    r <- terra::rast(rast_tif)
}
debug: if (fs::file_exists(rast_tif)) {
    r_tmp_tif <- tempfile(fileext = ".tif")
    r_tmp <- c(rast(rast_tif), r)
    r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
    terra::writeRaster(r_tmp, r_tmp_tif)
    fs::file_delete(rast_tif)
    fs::file_move(r_tmp_tif, rast_tif)
    rm(r)
    rm(r_tmp)
} else {
    terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
}
debug: terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
debug: r <- terra::rast(rast_tif)
debug: d_r <- mutate(tidyr::pivot_longer(sf::st_drop_geometry(sf::st_as_sf(terra::zonal(x = r, 
    z = terra::vect(dplyr::select(sf_zones, dplyr::all_of(fld_zones))), 
    fun = zonal_fun, exact = T, na.rm = T, as.polygons = T))), 
    cols = -dplyr::any_of(fld_zones), names_to = "lyr", values_to = zonal_fun), 
    time = readr::parse_datetime(str_replace(lyr, glue("{var}\\|(.*)"), 
        "\\1")))
debug: if (!is.null(zonal_csv)) write_csv(d_r, zonal_csv)
debug: write_csv(d_r, zonal_csv)
debug: if (!keep_nc) unlink(dir_nc, recursive = T)
debug: unlink(dir_nc, recursive = T)
debug: return(d_r)
Downloading 1 requests, up to 512 time slices each
Called from: extractr::ed_extract(ed, var = v, sf_zones = ply, bbox = bb, 
    mask_tif = F, rast_tif = glue("{dir_out}/{nms}/{yr}.tif"), 
    zonal_fun = "mean", zonal_csv = glue("{dir_out}/{nms}/{yr}.csv"), 
    dir_nc = glue("{dir_out}/{nms}/{yr}_nc"), keep_nc = F, n_max_vals_per_req = 1e+05, 
    time_min = time_min, time_max = time_max, verbose = T)
debug: while (i_req <= n_reqs) {
    i_t_beg <- (i_req - 1) * n_t_per_req + 1
    i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
    t_req <- times_todo[c(i_t_beg, i_t_end)]
    t_req_str <- format_ISO8601(t_req, usetz = "Z")
    if (verbose) 
        message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
    ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
        ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
        0), nc)
    unlink(ncs0)
    nc_retry <- T
    nc_n_try <- 1
    n_max_retries
    while (nc_retry) {
        res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
            url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
                bbox[["xmax"]]), latitude = c(bbox[["ymin"]], 
                bbox[["ymax"]]), time = t_req_str, fmt = "nc", 
            store = rerddap::disk(path = dir_nc)))
        if (inherits(res, "try-error")) {
            err <- attr(res, "condition")
            msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
            nc_n_try <- nc_n_try + 1
            if (nc_n_try > n_max_retries) {
                stop(msg)
            }
            else {
                message(msg, "\nRETRYing...")
                Sys.sleep(1)
            }
        }
        else {
            nc_retry <- F
        }
    }
    i_req <- i_req + 1
}
debug: i_t_beg <- (i_req - 1) * n_t_per_req + 1
debug: i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
debug: t_req <- times_todo[c(i_t_beg, i_t_end)]
debug: t_req_str <- format_ISO8601(t_req, usetz = "Z")
debug: if (verbose) message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
debug: message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
Fetching request 1 of 1 (2002-01-01 to 2002-12-01) ~ 19:44:53 UTC
debug: ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
    0), nc)
debug: unlink(ncs0)
debug: nc_retry <- T
debug: nc_n_try <- 1
debug: n_max_retries
debug: while (nc_retry) {
    res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
        url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
            bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
        time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
    if (inherits(res, "try-error")) {
        err <- attr(res, "condition")
        msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
        nc_n_try <- nc_n_try + 1
        if (nc_n_try > n_max_retries) {
            stop(msg)
        }
        else {
            message(msg, "\nRETRYing...")
            Sys.sleep(1)
        }
    }
    else {
        nc_retry <- F
    }
}
debug: res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
    url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
        bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
    time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
debug: if (inherits(res, "try-error")) {
    err <- attr(res, "condition")
    msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
    nc_n_try <- nc_n_try + 1
    if (nc_n_try > n_max_retries) {
        stop(msg)
    }
    else {
        message(msg, "\nRETRYing...")
        Sys.sleep(1)
    }
} else {
    nc_retry <- F
}
debug: nc_retry <- F
debug: (while) nc_retry
debug: i_req <- i_req + 1
debug: (while) i_req <= n_reqs
debug: ncs <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size > 
    0), nc)
debug: r <- terra::rast(ncs)
debug: stopifnot(all(class(terra::time(r)) %in% c("POSIXct", "POSIXt")))
debug: idx <- dplyr::pull(dplyr::filter(dplyr::arrange(dplyr::tibble(idx = 1:terra::nlyr(r), 
    time = terra::time(r)), time), !duplicated(time)), idx)
debug: r <- terra::subset(r, idx)
debug: stopifnot(terra::crs(r, proj = T) == wgs84)
debug: if (mask_tif) r <- terra::mask(r, sf_zones)
debug: lyrs <- glue("{var}|{terra::time(r)}")
debug: if (length(dims_other) > 0 && !all(length(dims[dims_other]) == 
    1)) stop(glue("Other dimensions not yet supported: {paste(dims_other, collapse = ',')}"))
debug: names(r) <- lyrs
debug: if (!is.null(rast_tif)) {
    if (fs::file_exists(rast_tif)) {
        r_tmp_tif <- tempfile(fileext = ".tif")
        r_tmp <- c(rast(rast_tif), r)
        r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
        terra::writeRaster(r_tmp, r_tmp_tif)
        fs::file_delete(rast_tif)
        fs::file_move(r_tmp_tif, rast_tif)
        rm(r)
        rm(r_tmp)
    }
    else {
        terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
    }
    r <- terra::rast(rast_tif)
}
debug: if (fs::file_exists(rast_tif)) {
    r_tmp_tif <- tempfile(fileext = ".tif")
    r_tmp <- c(rast(rast_tif), r)
    r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
    terra::writeRaster(r_tmp, r_tmp_tif)
    fs::file_delete(rast_tif)
    fs::file_move(r_tmp_tif, rast_tif)
    rm(r)
    rm(r_tmp)
} else {
    terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
}
debug: terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
debug: r <- terra::rast(rast_tif)
debug: d_r <- mutate(tidyr::pivot_longer(sf::st_drop_geometry(sf::st_as_sf(terra::zonal(x = r, 
    z = terra::vect(dplyr::select(sf_zones, dplyr::all_of(fld_zones))), 
    fun = zonal_fun, exact = T, na.rm = T, as.polygons = T))), 
    cols = -dplyr::any_of(fld_zones), names_to = "lyr", values_to = zonal_fun), 
    time = readr::parse_datetime(str_replace(lyr, glue("{var}\\|(.*)"), 
        "\\1")))
debug: if (!is.null(zonal_csv)) write_csv(d_r, zonal_csv)
debug: write_csv(d_r, zonal_csv)
debug: if (!keep_nc) unlink(dir_nc, recursive = T)
debug: unlink(dir_nc, recursive = T)
debug: return(d_r)
Downloading 1 requests, up to 512 time slices each
Called from: extractr::ed_extract(ed, var = v, sf_zones = ply, bbox = bb, 
    mask_tif = F, rast_tif = glue("{dir_out}/{nms}/{yr}.tif"), 
    zonal_fun = "mean", zonal_csv = glue("{dir_out}/{nms}/{yr}.csv"), 
    dir_nc = glue("{dir_out}/{nms}/{yr}_nc"), keep_nc = F, n_max_vals_per_req = 1e+05, 
    time_min = time_min, time_max = time_max, verbose = T)
debug: while (i_req <= n_reqs) {
    i_t_beg <- (i_req - 1) * n_t_per_req + 1
    i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
    t_req <- times_todo[c(i_t_beg, i_t_end)]
    t_req_str <- format_ISO8601(t_req, usetz = "Z")
    if (verbose) 
        message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
    ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
        ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
        0), nc)
    unlink(ncs0)
    nc_retry <- T
    nc_n_try <- 1
    n_max_retries
    while (nc_retry) {
        res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
            url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
                bbox[["xmax"]]), latitude = c(bbox[["ymin"]], 
                bbox[["ymax"]]), time = t_req_str, fmt = "nc", 
            store = rerddap::disk(path = dir_nc)))
        if (inherits(res, "try-error")) {
            err <- attr(res, "condition")
            msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
            nc_n_try <- nc_n_try + 1
            if (nc_n_try > n_max_retries) {
                stop(msg)
            }
            else {
                message(msg, "\nRETRYing...")
                Sys.sleep(1)
            }
        }
        else {
            nc_retry <- F
        }
    }
    i_req <- i_req + 1
}
debug: i_t_beg <- (i_req - 1) * n_t_per_req + 1
debug: i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
debug: t_req <- times_todo[c(i_t_beg, i_t_end)]
debug: t_req_str <- format_ISO8601(t_req, usetz = "Z")
debug: if (verbose) message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
debug: message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
Fetching request 1 of 1 (2003-01-01 to 2003-12-01) ~ 19:44:55 UTC
debug: ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
    0), nc)
debug: unlink(ncs0)
debug: nc_retry <- T
debug: nc_n_try <- 1
debug: n_max_retries
debug: while (nc_retry) {
    res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
        url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
            bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
        time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
    if (inherits(res, "try-error")) {
        err <- attr(res, "condition")
        msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
        nc_n_try <- nc_n_try + 1
        if (nc_n_try > n_max_retries) {
            stop(msg)
        }
        else {
            message(msg, "\nRETRYing...")
            Sys.sleep(1)
        }
    }
    else {
        nc_retry <- F
    }
}
debug: res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
    url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
        bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
    time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
debug: if (inherits(res, "try-error")) {
    err <- attr(res, "condition")
    msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
    nc_n_try <- nc_n_try + 1
    if (nc_n_try > n_max_retries) {
        stop(msg)
    }
    else {
        message(msg, "\nRETRYing...")
        Sys.sleep(1)
    }
} else {
    nc_retry <- F
}
debug: nc_retry <- F
debug: (while) nc_retry
debug: i_req <- i_req + 1
debug: (while) i_req <= n_reqs
debug: ncs <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size > 
    0), nc)
debug: r <- terra::rast(ncs)
debug: stopifnot(all(class(terra::time(r)) %in% c("POSIXct", "POSIXt")))
debug: idx <- dplyr::pull(dplyr::filter(dplyr::arrange(dplyr::tibble(idx = 1:terra::nlyr(r), 
    time = terra::time(r)), time), !duplicated(time)), idx)
debug: r <- terra::subset(r, idx)
debug: stopifnot(terra::crs(r, proj = T) == wgs84)
debug: if (mask_tif) r <- terra::mask(r, sf_zones)
debug: lyrs <- glue("{var}|{terra::time(r)}")
debug: if (length(dims_other) > 0 && !all(length(dims[dims_other]) == 
    1)) stop(glue("Other dimensions not yet supported: {paste(dims_other, collapse = ',')}"))
debug: names(r) <- lyrs
debug: if (!is.null(rast_tif)) {
    if (fs::file_exists(rast_tif)) {
        r_tmp_tif <- tempfile(fileext = ".tif")
        r_tmp <- c(rast(rast_tif), r)
        r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
        terra::writeRaster(r_tmp, r_tmp_tif)
        fs::file_delete(rast_tif)
        fs::file_move(r_tmp_tif, rast_tif)
        rm(r)
        rm(r_tmp)
    }
    else {
        terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
    }
    r <- terra::rast(rast_tif)
}
debug: if (fs::file_exists(rast_tif)) {
    r_tmp_tif <- tempfile(fileext = ".tif")
    r_tmp <- c(rast(rast_tif), r)
    r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
    terra::writeRaster(r_tmp, r_tmp_tif)
    fs::file_delete(rast_tif)
    fs::file_move(r_tmp_tif, rast_tif)
    rm(r)
    rm(r_tmp)
} else {
    terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
}
debug: terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
debug: r <- terra::rast(rast_tif)
debug: d_r <- mutate(tidyr::pivot_longer(sf::st_drop_geometry(sf::st_as_sf(terra::zonal(x = r, 
    z = terra::vect(dplyr::select(sf_zones, dplyr::all_of(fld_zones))), 
    fun = zonal_fun, exact = T, na.rm = T, as.polygons = T))), 
    cols = -dplyr::any_of(fld_zones), names_to = "lyr", values_to = zonal_fun), 
    time = readr::parse_datetime(str_replace(lyr, glue("{var}\\|(.*)"), 
        "\\1")))
debug: if (!is.null(zonal_csv)) write_csv(d_r, zonal_csv)
debug: write_csv(d_r, zonal_csv)
debug: if (!keep_nc) unlink(dir_nc, recursive = T)
debug: unlink(dir_nc, recursive = T)
debug: return(d_r)
Downloading 1 requests, up to 512 time slices each
Called from: extractr::ed_extract(ed, var = v, sf_zones = ply, bbox = bb, 
    mask_tif = F, rast_tif = glue("{dir_out}/{nms}/{yr}.tif"), 
    zonal_fun = "mean", zonal_csv = glue("{dir_out}/{nms}/{yr}.csv"), 
    dir_nc = glue("{dir_out}/{nms}/{yr}_nc"), keep_nc = F, n_max_vals_per_req = 1e+05, 
    time_min = time_min, time_max = time_max, verbose = T)
debug: while (i_req <= n_reqs) {
    i_t_beg <- (i_req - 1) * n_t_per_req + 1
    i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
    t_req <- times_todo[c(i_t_beg, i_t_end)]
    t_req_str <- format_ISO8601(t_req, usetz = "Z")
    if (verbose) 
        message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
    ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
        ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
        0), nc)
    unlink(ncs0)
    nc_retry <- T
    nc_n_try <- 1
    n_max_retries
    while (nc_retry) {
        res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
            url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
                bbox[["xmax"]]), latitude = c(bbox[["ymin"]], 
                bbox[["ymax"]]), time = t_req_str, fmt = "nc", 
            store = rerddap::disk(path = dir_nc)))
        if (inherits(res, "try-error")) {
            err <- attr(res, "condition")
            msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
            nc_n_try <- nc_n_try + 1
            if (nc_n_try > n_max_retries) {
                stop(msg)
            }
            else {
                message(msg, "\nRETRYing...")
                Sys.sleep(1)
            }
        }
        else {
            nc_retry <- F
        }
    }
    i_req <- i_req + 1
}
debug: i_t_beg <- (i_req - 1) * n_t_per_req + 1
debug: i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
debug: t_req <- times_todo[c(i_t_beg, i_t_end)]
debug: t_req_str <- format_ISO8601(t_req, usetz = "Z")
debug: if (verbose) message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
debug: message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
Fetching request 1 of 1 (2004-01-01 to 2004-12-01) ~ 19:44:57 UTC
debug: ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
    0), nc)
debug: unlink(ncs0)
debug: nc_retry <- T
debug: nc_n_try <- 1
debug: n_max_retries
debug: while (nc_retry) {
    res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
        url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
            bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
        time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
    if (inherits(res, "try-error")) {
        err <- attr(res, "condition")
        msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
        nc_n_try <- nc_n_try + 1
        if (nc_n_try > n_max_retries) {
            stop(msg)
        }
        else {
            message(msg, "\nRETRYing...")
            Sys.sleep(1)
        }
    }
    else {
        nc_retry <- F
    }
}
debug: res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
    url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
        bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
    time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
debug: if (inherits(res, "try-error")) {
    err <- attr(res, "condition")
    msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
    nc_n_try <- nc_n_try + 1
    if (nc_n_try > n_max_retries) {
        stop(msg)
    }
    else {
        message(msg, "\nRETRYing...")
        Sys.sleep(1)
    }
} else {
    nc_retry <- F
}
debug: nc_retry <- F
debug: (while) nc_retry
debug: i_req <- i_req + 1
debug: (while) i_req <= n_reqs
debug: ncs <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size > 
    0), nc)
debug: r <- terra::rast(ncs)
debug: stopifnot(all(class(terra::time(r)) %in% c("POSIXct", "POSIXt")))
debug: idx <- dplyr::pull(dplyr::filter(dplyr::arrange(dplyr::tibble(idx = 1:terra::nlyr(r), 
    time = terra::time(r)), time), !duplicated(time)), idx)
debug: r <- terra::subset(r, idx)
debug: stopifnot(terra::crs(r, proj = T) == wgs84)
debug: if (mask_tif) r <- terra::mask(r, sf_zones)
debug: lyrs <- glue("{var}|{terra::time(r)}")
debug: if (length(dims_other) > 0 && !all(length(dims[dims_other]) == 
    1)) stop(glue("Other dimensions not yet supported: {paste(dims_other, collapse = ',')}"))
debug: names(r) <- lyrs
debug: if (!is.null(rast_tif)) {
    if (fs::file_exists(rast_tif)) {
        r_tmp_tif <- tempfile(fileext = ".tif")
        r_tmp <- c(rast(rast_tif), r)
        r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
        terra::writeRaster(r_tmp, r_tmp_tif)
        fs::file_delete(rast_tif)
        fs::file_move(r_tmp_tif, rast_tif)
        rm(r)
        rm(r_tmp)
    }
    else {
        terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
    }
    r <- terra::rast(rast_tif)
}
debug: if (fs::file_exists(rast_tif)) {
    r_tmp_tif <- tempfile(fileext = ".tif")
    r_tmp <- c(rast(rast_tif), r)
    r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
    terra::writeRaster(r_tmp, r_tmp_tif)
    fs::file_delete(rast_tif)
    fs::file_move(r_tmp_tif, rast_tif)
    rm(r)
    rm(r_tmp)
} else {
    terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
}
debug: terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
debug: r <- terra::rast(rast_tif)
debug: d_r <- mutate(tidyr::pivot_longer(sf::st_drop_geometry(sf::st_as_sf(terra::zonal(x = r, 
    z = terra::vect(dplyr::select(sf_zones, dplyr::all_of(fld_zones))), 
    fun = zonal_fun, exact = T, na.rm = T, as.polygons = T))), 
    cols = -dplyr::any_of(fld_zones), names_to = "lyr", values_to = zonal_fun), 
    time = readr::parse_datetime(str_replace(lyr, glue("{var}\\|(.*)"), 
        "\\1")))
debug: if (!is.null(zonal_csv)) write_csv(d_r, zonal_csv)
debug: write_csv(d_r, zonal_csv)
debug: if (!keep_nc) unlink(dir_nc, recursive = T)
debug: unlink(dir_nc, recursive = T)
debug: return(d_r)
Downloading 1 requests, up to 512 time slices each
Called from: extractr::ed_extract(ed, var = v, sf_zones = ply, bbox = bb, 
    mask_tif = F, rast_tif = glue("{dir_out}/{nms}/{yr}.tif"), 
    zonal_fun = "mean", zonal_csv = glue("{dir_out}/{nms}/{yr}.csv"), 
    dir_nc = glue("{dir_out}/{nms}/{yr}_nc"), keep_nc = F, n_max_vals_per_req = 1e+05, 
    time_min = time_min, time_max = time_max, verbose = T)
debug: while (i_req <= n_reqs) {
    i_t_beg <- (i_req - 1) * n_t_per_req + 1
    i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
    t_req <- times_todo[c(i_t_beg, i_t_end)]
    t_req_str <- format_ISO8601(t_req, usetz = "Z")
    if (verbose) 
        message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
    ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
        ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
        0), nc)
    unlink(ncs0)
    nc_retry <- T
    nc_n_try <- 1
    n_max_retries
    while (nc_retry) {
        res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
            url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
                bbox[["xmax"]]), latitude = c(bbox[["ymin"]], 
                bbox[["ymax"]]), time = t_req_str, fmt = "nc", 
            store = rerddap::disk(path = dir_nc)))
        if (inherits(res, "try-error")) {
            err <- attr(res, "condition")
            msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
            nc_n_try <- nc_n_try + 1
            if (nc_n_try > n_max_retries) {
                stop(msg)
            }
            else {
                message(msg, "\nRETRYing...")
                Sys.sleep(1)
            }
        }
        else {
            nc_retry <- F
        }
    }
    i_req <- i_req + 1
}
debug: i_t_beg <- (i_req - 1) * n_t_per_req + 1
debug: i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
debug: t_req <- times_todo[c(i_t_beg, i_t_end)]
debug: t_req_str <- format_ISO8601(t_req, usetz = "Z")
debug: if (verbose) message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
debug: message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
Fetching request 1 of 1 (2005-01-01 to 2005-12-01) ~ 19:44:59 UTC
debug: ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
    0), nc)
debug: unlink(ncs0)
debug: nc_retry <- T
debug: nc_n_try <- 1
debug: n_max_retries
debug: while (nc_retry) {
    res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
        url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
            bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
        time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
    if (inherits(res, "try-error")) {
        err <- attr(res, "condition")
        msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
        nc_n_try <- nc_n_try + 1
        if (nc_n_try > n_max_retries) {
            stop(msg)
        }
        else {
            message(msg, "\nRETRYing...")
            Sys.sleep(1)
        }
    }
    else {
        nc_retry <- F
    }
}
debug: res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
    url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
        bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
    time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
debug: if (inherits(res, "try-error")) {
    err <- attr(res, "condition")
    msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
    nc_n_try <- nc_n_try + 1
    if (nc_n_try > n_max_retries) {
        stop(msg)
    }
    else {
        message(msg, "\nRETRYing...")
        Sys.sleep(1)
    }
} else {
    nc_retry <- F
}
debug: nc_retry <- F
debug: (while) nc_retry
debug: i_req <- i_req + 1
debug: (while) i_req <= n_reqs
debug: ncs <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size > 
    0), nc)
debug: r <- terra::rast(ncs)
debug: stopifnot(all(class(terra::time(r)) %in% c("POSIXct", "POSIXt")))
debug: idx <- dplyr::pull(dplyr::filter(dplyr::arrange(dplyr::tibble(idx = 1:terra::nlyr(r), 
    time = terra::time(r)), time), !duplicated(time)), idx)
debug: r <- terra::subset(r, idx)
debug: stopifnot(terra::crs(r, proj = T) == wgs84)
debug: if (mask_tif) r <- terra::mask(r, sf_zones)
debug: lyrs <- glue("{var}|{terra::time(r)}")
debug: if (length(dims_other) > 0 && !all(length(dims[dims_other]) == 
    1)) stop(glue("Other dimensions not yet supported: {paste(dims_other, collapse = ',')}"))
debug: names(r) <- lyrs
debug: if (!is.null(rast_tif)) {
    if (fs::file_exists(rast_tif)) {
        r_tmp_tif <- tempfile(fileext = ".tif")
        r_tmp <- c(rast(rast_tif), r)
        r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
        terra::writeRaster(r_tmp, r_tmp_tif)
        fs::file_delete(rast_tif)
        fs::file_move(r_tmp_tif, rast_tif)
        rm(r)
        rm(r_tmp)
    }
    else {
        terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
    }
    r <- terra::rast(rast_tif)
}
debug: if (fs::file_exists(rast_tif)) {
    r_tmp_tif <- tempfile(fileext = ".tif")
    r_tmp <- c(rast(rast_tif), r)
    r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
    terra::writeRaster(r_tmp, r_tmp_tif)
    fs::file_delete(rast_tif)
    fs::file_move(r_tmp_tif, rast_tif)
    rm(r)
    rm(r_tmp)
} else {
    terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
}
debug: terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
debug: r <- terra::rast(rast_tif)
debug: d_r <- mutate(tidyr::pivot_longer(sf::st_drop_geometry(sf::st_as_sf(terra::zonal(x = r, 
    z = terra::vect(dplyr::select(sf_zones, dplyr::all_of(fld_zones))), 
    fun = zonal_fun, exact = T, na.rm = T, as.polygons = T))), 
    cols = -dplyr::any_of(fld_zones), names_to = "lyr", values_to = zonal_fun), 
    time = readr::parse_datetime(str_replace(lyr, glue("{var}\\|(.*)"), 
        "\\1")))
debug: if (!is.null(zonal_csv)) write_csv(d_r, zonal_csv)
debug: write_csv(d_r, zonal_csv)
debug: if (!keep_nc) unlink(dir_nc, recursive = T)
debug: unlink(dir_nc, recursive = T)
debug: return(d_r)
Downloading 1 requests, up to 512 time slices each
Called from: extractr::ed_extract(ed, var = v, sf_zones = ply, bbox = bb, 
    mask_tif = F, rast_tif = glue("{dir_out}/{nms}/{yr}.tif"), 
    zonal_fun = "mean", zonal_csv = glue("{dir_out}/{nms}/{yr}.csv"), 
    dir_nc = glue("{dir_out}/{nms}/{yr}_nc"), keep_nc = F, n_max_vals_per_req = 1e+05, 
    time_min = time_min, time_max = time_max, verbose = T)
debug: while (i_req <= n_reqs) {
    i_t_beg <- (i_req - 1) * n_t_per_req + 1
    i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
    t_req <- times_todo[c(i_t_beg, i_t_end)]
    t_req_str <- format_ISO8601(t_req, usetz = "Z")
    if (verbose) 
        message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
    ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
        ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
        0), nc)
    unlink(ncs0)
    nc_retry <- T
    nc_n_try <- 1
    n_max_retries
    while (nc_retry) {
        res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
            url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
                bbox[["xmax"]]), latitude = c(bbox[["ymin"]], 
                bbox[["ymax"]]), time = t_req_str, fmt = "nc", 
            store = rerddap::disk(path = dir_nc)))
        if (inherits(res, "try-error")) {
            err <- attr(res, "condition")
            msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
            nc_n_try <- nc_n_try + 1
            if (nc_n_try > n_max_retries) {
                stop(msg)
            }
            else {
                message(msg, "\nRETRYing...")
                Sys.sleep(1)
            }
        }
        else {
            nc_retry <- F
        }
    }
    i_req <- i_req + 1
}
debug: i_t_beg <- (i_req - 1) * n_t_per_req + 1
debug: i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
debug: t_req <- times_todo[c(i_t_beg, i_t_end)]
debug: t_req_str <- format_ISO8601(t_req, usetz = "Z")
debug: if (verbose) message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
debug: message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
Fetching request 1 of 1 (2006-01-01 to 2006-12-01) ~ 19:45:00 UTC
debug: ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
    0), nc)
debug: unlink(ncs0)
debug: nc_retry <- T
debug: nc_n_try <- 1
debug: n_max_retries
debug: while (nc_retry) {
    res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
        url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
            bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
        time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
    if (inherits(res, "try-error")) {
        err <- attr(res, "condition")
        msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
        nc_n_try <- nc_n_try + 1
        if (nc_n_try > n_max_retries) {
            stop(msg)
        }
        else {
            message(msg, "\nRETRYing...")
            Sys.sleep(1)
        }
    }
    else {
        nc_retry <- F
    }
}
debug: res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
    url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
        bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
    time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
debug: if (inherits(res, "try-error")) {
    err <- attr(res, "condition")
    msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
    nc_n_try <- nc_n_try + 1
    if (nc_n_try > n_max_retries) {
        stop(msg)
    }
    else {
        message(msg, "\nRETRYing...")
        Sys.sleep(1)
    }
} else {
    nc_retry <- F
}
debug: nc_retry <- F
debug: (while) nc_retry
debug: i_req <- i_req + 1
debug: (while) i_req <= n_reqs
debug: ncs <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size > 
    0), nc)
debug: r <- terra::rast(ncs)
debug: stopifnot(all(class(terra::time(r)) %in% c("POSIXct", "POSIXt")))
debug: idx <- dplyr::pull(dplyr::filter(dplyr::arrange(dplyr::tibble(idx = 1:terra::nlyr(r), 
    time = terra::time(r)), time), !duplicated(time)), idx)
debug: r <- terra::subset(r, idx)
debug: stopifnot(terra::crs(r, proj = T) == wgs84)
debug: if (mask_tif) r <- terra::mask(r, sf_zones)
debug: lyrs <- glue("{var}|{terra::time(r)}")
debug: if (length(dims_other) > 0 && !all(length(dims[dims_other]) == 
    1)) stop(glue("Other dimensions not yet supported: {paste(dims_other, collapse = ',')}"))
debug: names(r) <- lyrs
debug: if (!is.null(rast_tif)) {
    if (fs::file_exists(rast_tif)) {
        r_tmp_tif <- tempfile(fileext = ".tif")
        r_tmp <- c(rast(rast_tif), r)
        r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
        terra::writeRaster(r_tmp, r_tmp_tif)
        fs::file_delete(rast_tif)
        fs::file_move(r_tmp_tif, rast_tif)
        rm(r)
        rm(r_tmp)
    }
    else {
        terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
    }
    r <- terra::rast(rast_tif)
}
debug: if (fs::file_exists(rast_tif)) {
    r_tmp_tif <- tempfile(fileext = ".tif")
    r_tmp <- c(rast(rast_tif), r)
    r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
    terra::writeRaster(r_tmp, r_tmp_tif)
    fs::file_delete(rast_tif)
    fs::file_move(r_tmp_tif, rast_tif)
    rm(r)
    rm(r_tmp)
} else {
    terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
}
debug: terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
debug: r <- terra::rast(rast_tif)
debug: d_r <- mutate(tidyr::pivot_longer(sf::st_drop_geometry(sf::st_as_sf(terra::zonal(x = r, 
    z = terra::vect(dplyr::select(sf_zones, dplyr::all_of(fld_zones))), 
    fun = zonal_fun, exact = T, na.rm = T, as.polygons = T))), 
    cols = -dplyr::any_of(fld_zones), names_to = "lyr", values_to = zonal_fun), 
    time = readr::parse_datetime(str_replace(lyr, glue("{var}\\|(.*)"), 
        "\\1")))
debug: if (!is.null(zonal_csv)) write_csv(d_r, zonal_csv)
debug: write_csv(d_r, zonal_csv)
debug: if (!keep_nc) unlink(dir_nc, recursive = T)
debug: unlink(dir_nc, recursive = T)
debug: return(d_r)
Downloading 1 requests, up to 512 time slices each
Called from: extractr::ed_extract(ed, var = v, sf_zones = ply, bbox = bb, 
    mask_tif = F, rast_tif = glue("{dir_out}/{nms}/{yr}.tif"), 
    zonal_fun = "mean", zonal_csv = glue("{dir_out}/{nms}/{yr}.csv"), 
    dir_nc = glue("{dir_out}/{nms}/{yr}_nc"), keep_nc = F, n_max_vals_per_req = 1e+05, 
    time_min = time_min, time_max = time_max, verbose = T)
debug: while (i_req <= n_reqs) {
    i_t_beg <- (i_req - 1) * n_t_per_req + 1
    i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
    t_req <- times_todo[c(i_t_beg, i_t_end)]
    t_req_str <- format_ISO8601(t_req, usetz = "Z")
    if (verbose) 
        message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
    ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
        ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
        0), nc)
    unlink(ncs0)
    nc_retry <- T
    nc_n_try <- 1
    n_max_retries
    while (nc_retry) {
        res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
            url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
                bbox[["xmax"]]), latitude = c(bbox[["ymin"]], 
                bbox[["ymax"]]), time = t_req_str, fmt = "nc", 
            store = rerddap::disk(path = dir_nc)))
        if (inherits(res, "try-error")) {
            err <- attr(res, "condition")
            msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
            nc_n_try <- nc_n_try + 1
            if (nc_n_try > n_max_retries) {
                stop(msg)
            }
            else {
                message(msg, "\nRETRYing...")
                Sys.sleep(1)
            }
        }
        else {
            nc_retry <- F
        }
    }
    i_req <- i_req + 1
}
debug: i_t_beg <- (i_req - 1) * n_t_per_req + 1
debug: i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
debug: t_req <- times_todo[c(i_t_beg, i_t_end)]
debug: t_req_str <- format_ISO8601(t_req, usetz = "Z")
debug: if (verbose) message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
debug: message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
Fetching request 1 of 1 (2007-01-01 to 2007-12-01) ~ 19:45:02 UTC
debug: ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
    0), nc)
debug: unlink(ncs0)
debug: nc_retry <- T
debug: nc_n_try <- 1
debug: n_max_retries
debug: while (nc_retry) {
    res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
        url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
            bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
        time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
    if (inherits(res, "try-error")) {
        err <- attr(res, "condition")
        msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
        nc_n_try <- nc_n_try + 1
        if (nc_n_try > n_max_retries) {
            stop(msg)
        }
        else {
            message(msg, "\nRETRYing...")
            Sys.sleep(1)
        }
    }
    else {
        nc_retry <- F
    }
}
debug: res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
    url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
        bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
    time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
debug: if (inherits(res, "try-error")) {
    err <- attr(res, "condition")
    msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
    nc_n_try <- nc_n_try + 1
    if (nc_n_try > n_max_retries) {
        stop(msg)
    }
    else {
        message(msg, "\nRETRYing...")
        Sys.sleep(1)
    }
} else {
    nc_retry <- F
}
debug: nc_retry <- F
debug: (while) nc_retry
debug: i_req <- i_req + 1
debug: (while) i_req <= n_reqs
debug: ncs <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size > 
    0), nc)
debug: r <- terra::rast(ncs)
debug: stopifnot(all(class(terra::time(r)) %in% c("POSIXct", "POSIXt")))
debug: idx <- dplyr::pull(dplyr::filter(dplyr::arrange(dplyr::tibble(idx = 1:terra::nlyr(r), 
    time = terra::time(r)), time), !duplicated(time)), idx)
debug: r <- terra::subset(r, idx)
debug: stopifnot(terra::crs(r, proj = T) == wgs84)
debug: if (mask_tif) r <- terra::mask(r, sf_zones)
debug: lyrs <- glue("{var}|{terra::time(r)}")
debug: if (length(dims_other) > 0 && !all(length(dims[dims_other]) == 
    1)) stop(glue("Other dimensions not yet supported: {paste(dims_other, collapse = ',')}"))
debug: names(r) <- lyrs
debug: if (!is.null(rast_tif)) {
    if (fs::file_exists(rast_tif)) {
        r_tmp_tif <- tempfile(fileext = ".tif")
        r_tmp <- c(rast(rast_tif), r)
        r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
        terra::writeRaster(r_tmp, r_tmp_tif)
        fs::file_delete(rast_tif)
        fs::file_move(r_tmp_tif, rast_tif)
        rm(r)
        rm(r_tmp)
    }
    else {
        terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
    }
    r <- terra::rast(rast_tif)
}
debug: if (fs::file_exists(rast_tif)) {
    r_tmp_tif <- tempfile(fileext = ".tif")
    r_tmp <- c(rast(rast_tif), r)
    r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
    terra::writeRaster(r_tmp, r_tmp_tif)
    fs::file_delete(rast_tif)
    fs::file_move(r_tmp_tif, rast_tif)
    rm(r)
    rm(r_tmp)
} else {
    terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
}
debug: terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
debug: r <- terra::rast(rast_tif)
debug: d_r <- mutate(tidyr::pivot_longer(sf::st_drop_geometry(sf::st_as_sf(terra::zonal(x = r, 
    z = terra::vect(dplyr::select(sf_zones, dplyr::all_of(fld_zones))), 
    fun = zonal_fun, exact = T, na.rm = T, as.polygons = T))), 
    cols = -dplyr::any_of(fld_zones), names_to = "lyr", values_to = zonal_fun), 
    time = readr::parse_datetime(str_replace(lyr, glue("{var}\\|(.*)"), 
        "\\1")))
debug: if (!is.null(zonal_csv)) write_csv(d_r, zonal_csv)
debug: write_csv(d_r, zonal_csv)
debug: if (!keep_nc) unlink(dir_nc, recursive = T)
debug: unlink(dir_nc, recursive = T)
debug: return(d_r)
Downloading 1 requests, up to 512 time slices each
Called from: extractr::ed_extract(ed, var = v, sf_zones = ply, bbox = bb, 
    mask_tif = F, rast_tif = glue("{dir_out}/{nms}/{yr}.tif"), 
    zonal_fun = "mean", zonal_csv = glue("{dir_out}/{nms}/{yr}.csv"), 
    dir_nc = glue("{dir_out}/{nms}/{yr}_nc"), keep_nc = F, n_max_vals_per_req = 1e+05, 
    time_min = time_min, time_max = time_max, verbose = T)
debug: while (i_req <= n_reqs) {
    i_t_beg <- (i_req - 1) * n_t_per_req + 1
    i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
    t_req <- times_todo[c(i_t_beg, i_t_end)]
    t_req_str <- format_ISO8601(t_req, usetz = "Z")
    if (verbose) 
        message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
    ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
        ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
        0), nc)
    unlink(ncs0)
    nc_retry <- T
    nc_n_try <- 1
    n_max_retries
    while (nc_retry) {
        res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
            url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
                bbox[["xmax"]]), latitude = c(bbox[["ymin"]], 
                bbox[["ymax"]]), time = t_req_str, fmt = "nc", 
            store = rerddap::disk(path = dir_nc)))
        if (inherits(res, "try-error")) {
            err <- attr(res, "condition")
            msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
            nc_n_try <- nc_n_try + 1
            if (nc_n_try > n_max_retries) {
                stop(msg)
            }
            else {
                message(msg, "\nRETRYing...")
                Sys.sleep(1)
            }
        }
        else {
            nc_retry <- F
        }
    }
    i_req <- i_req + 1
}
debug: i_t_beg <- (i_req - 1) * n_t_per_req + 1
debug: i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
debug: t_req <- times_todo[c(i_t_beg, i_t_end)]
debug: t_req_str <- format_ISO8601(t_req, usetz = "Z")
debug: if (verbose) message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
debug: message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
Fetching request 1 of 1 (2008-01-01 to 2008-12-01) ~ 19:45:04 UTC
debug: ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
    0), nc)
debug: unlink(ncs0)
debug: nc_retry <- T
debug: nc_n_try <- 1
debug: n_max_retries
debug: while (nc_retry) {
    res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
        url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
            bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
        time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
    if (inherits(res, "try-error")) {
        err <- attr(res, "condition")
        msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
        nc_n_try <- nc_n_try + 1
        if (nc_n_try > n_max_retries) {
            stop(msg)
        }
        else {
            message(msg, "\nRETRYing...")
            Sys.sleep(1)
        }
    }
    else {
        nc_retry <- F
    }
}
debug: res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
    url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
        bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
    time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
debug: if (inherits(res, "try-error")) {
    err <- attr(res, "condition")
    msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
    nc_n_try <- nc_n_try + 1
    if (nc_n_try > n_max_retries) {
        stop(msg)
    }
    else {
        message(msg, "\nRETRYing...")
        Sys.sleep(1)
    }
} else {
    nc_retry <- F
}
debug: nc_retry <- F
debug: (while) nc_retry
debug: i_req <- i_req + 1
debug: (while) i_req <= n_reqs
debug: ncs <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size > 
    0), nc)
debug: r <- terra::rast(ncs)
debug: stopifnot(all(class(terra::time(r)) %in% c("POSIXct", "POSIXt")))
debug: idx <- dplyr::pull(dplyr::filter(dplyr::arrange(dplyr::tibble(idx = 1:terra::nlyr(r), 
    time = terra::time(r)), time), !duplicated(time)), idx)
debug: r <- terra::subset(r, idx)
debug: stopifnot(terra::crs(r, proj = T) == wgs84)
debug: if (mask_tif) r <- terra::mask(r, sf_zones)
debug: lyrs <- glue("{var}|{terra::time(r)}")
debug: if (length(dims_other) > 0 && !all(length(dims[dims_other]) == 
    1)) stop(glue("Other dimensions not yet supported: {paste(dims_other, collapse = ',')}"))
debug: names(r) <- lyrs
debug: if (!is.null(rast_tif)) {
    if (fs::file_exists(rast_tif)) {
        r_tmp_tif <- tempfile(fileext = ".tif")
        r_tmp <- c(rast(rast_tif), r)
        r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
        terra::writeRaster(r_tmp, r_tmp_tif)
        fs::file_delete(rast_tif)
        fs::file_move(r_tmp_tif, rast_tif)
        rm(r)
        rm(r_tmp)
    }
    else {
        terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
    }
    r <- terra::rast(rast_tif)
}
debug: if (fs::file_exists(rast_tif)) {
    r_tmp_tif <- tempfile(fileext = ".tif")
    r_tmp <- c(rast(rast_tif), r)
    r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
    terra::writeRaster(r_tmp, r_tmp_tif)
    fs::file_delete(rast_tif)
    fs::file_move(r_tmp_tif, rast_tif)
    rm(r)
    rm(r_tmp)
} else {
    terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
}
debug: terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
debug: r <- terra::rast(rast_tif)
debug: d_r <- mutate(tidyr::pivot_longer(sf::st_drop_geometry(sf::st_as_sf(terra::zonal(x = r, 
    z = terra::vect(dplyr::select(sf_zones, dplyr::all_of(fld_zones))), 
    fun = zonal_fun, exact = T, na.rm = T, as.polygons = T))), 
    cols = -dplyr::any_of(fld_zones), names_to = "lyr", values_to = zonal_fun), 
    time = readr::parse_datetime(str_replace(lyr, glue("{var}\\|(.*)"), 
        "\\1")))
debug: if (!is.null(zonal_csv)) write_csv(d_r, zonal_csv)
debug: write_csv(d_r, zonal_csv)
debug: if (!keep_nc) unlink(dir_nc, recursive = T)
debug: unlink(dir_nc, recursive = T)
debug: return(d_r)
Downloading 1 requests, up to 512 time slices each
Called from: extractr::ed_extract(ed, var = v, sf_zones = ply, bbox = bb, 
    mask_tif = F, rast_tif = glue("{dir_out}/{nms}/{yr}.tif"), 
    zonal_fun = "mean", zonal_csv = glue("{dir_out}/{nms}/{yr}.csv"), 
    dir_nc = glue("{dir_out}/{nms}/{yr}_nc"), keep_nc = F, n_max_vals_per_req = 1e+05, 
    time_min = time_min, time_max = time_max, verbose = T)
debug: while (i_req <= n_reqs) {
    i_t_beg <- (i_req - 1) * n_t_per_req + 1
    i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
    t_req <- times_todo[c(i_t_beg, i_t_end)]
    t_req_str <- format_ISO8601(t_req, usetz = "Z")
    if (verbose) 
        message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
    ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
        ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
        0), nc)
    unlink(ncs0)
    nc_retry <- T
    nc_n_try <- 1
    n_max_retries
    while (nc_retry) {
        res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
            url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
                bbox[["xmax"]]), latitude = c(bbox[["ymin"]], 
                bbox[["ymax"]]), time = t_req_str, fmt = "nc", 
            store = rerddap::disk(path = dir_nc)))
        if (inherits(res, "try-error")) {
            err <- attr(res, "condition")
            msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
            nc_n_try <- nc_n_try + 1
            if (nc_n_try > n_max_retries) {
                stop(msg)
            }
            else {
                message(msg, "\nRETRYing...")
                Sys.sleep(1)
            }
        }
        else {
            nc_retry <- F
        }
    }
    i_req <- i_req + 1
}
debug: i_t_beg <- (i_req - 1) * n_t_per_req + 1
debug: i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
debug: t_req <- times_todo[c(i_t_beg, i_t_end)]
debug: t_req_str <- format_ISO8601(t_req, usetz = "Z")
debug: if (verbose) message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
debug: message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
Fetching request 1 of 1 (2009-01-01 to 2009-12-01) ~ 19:45:06 UTC
debug: ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
    0), nc)
debug: unlink(ncs0)
debug: nc_retry <- T
debug: nc_n_try <- 1
debug: n_max_retries
debug: while (nc_retry) {
    res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
        url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
            bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
        time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
    if (inherits(res, "try-error")) {
        err <- attr(res, "condition")
        msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
        nc_n_try <- nc_n_try + 1
        if (nc_n_try > n_max_retries) {
            stop(msg)
        }
        else {
            message(msg, "\nRETRYing...")
            Sys.sleep(1)
        }
    }
    else {
        nc_retry <- F
    }
}
debug: res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
    url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
        bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
    time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
debug: if (inherits(res, "try-error")) {
    err <- attr(res, "condition")
    msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
    nc_n_try <- nc_n_try + 1
    if (nc_n_try > n_max_retries) {
        stop(msg)
    }
    else {
        message(msg, "\nRETRYing...")
        Sys.sleep(1)
    }
} else {
    nc_retry <- F
}
debug: nc_retry <- F
debug: (while) nc_retry
debug: i_req <- i_req + 1
debug: (while) i_req <= n_reqs
debug: ncs <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size > 
    0), nc)
debug: r <- terra::rast(ncs)
debug: stopifnot(all(class(terra::time(r)) %in% c("POSIXct", "POSIXt")))
debug: idx <- dplyr::pull(dplyr::filter(dplyr::arrange(dplyr::tibble(idx = 1:terra::nlyr(r), 
    time = terra::time(r)), time), !duplicated(time)), idx)
debug: r <- terra::subset(r, idx)
debug: stopifnot(terra::crs(r, proj = T) == wgs84)
debug: if (mask_tif) r <- terra::mask(r, sf_zones)
debug: lyrs <- glue("{var}|{terra::time(r)}")
debug: if (length(dims_other) > 0 && !all(length(dims[dims_other]) == 
    1)) stop(glue("Other dimensions not yet supported: {paste(dims_other, collapse = ',')}"))
debug: names(r) <- lyrs
debug: if (!is.null(rast_tif)) {
    if (fs::file_exists(rast_tif)) {
        r_tmp_tif <- tempfile(fileext = ".tif")
        r_tmp <- c(rast(rast_tif), r)
        r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
        terra::writeRaster(r_tmp, r_tmp_tif)
        fs::file_delete(rast_tif)
        fs::file_move(r_tmp_tif, rast_tif)
        rm(r)
        rm(r_tmp)
    }
    else {
        terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
    }
    r <- terra::rast(rast_tif)
}
debug: if (fs::file_exists(rast_tif)) {
    r_tmp_tif <- tempfile(fileext = ".tif")
    r_tmp <- c(rast(rast_tif), r)
    r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
    terra::writeRaster(r_tmp, r_tmp_tif)
    fs::file_delete(rast_tif)
    fs::file_move(r_tmp_tif, rast_tif)
    rm(r)
    rm(r_tmp)
} else {
    terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
}
debug: terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
debug: r <- terra::rast(rast_tif)
debug: d_r <- mutate(tidyr::pivot_longer(sf::st_drop_geometry(sf::st_as_sf(terra::zonal(x = r, 
    z = terra::vect(dplyr::select(sf_zones, dplyr::all_of(fld_zones))), 
    fun = zonal_fun, exact = T, na.rm = T, as.polygons = T))), 
    cols = -dplyr::any_of(fld_zones), names_to = "lyr", values_to = zonal_fun), 
    time = readr::parse_datetime(str_replace(lyr, glue("{var}\\|(.*)"), 
        "\\1")))
debug: if (!is.null(zonal_csv)) write_csv(d_r, zonal_csv)
debug: write_csv(d_r, zonal_csv)
debug: if (!keep_nc) unlink(dir_nc, recursive = T)
debug: unlink(dir_nc, recursive = T)
debug: return(d_r)
Downloading 1 requests, up to 512 time slices each
Called from: extractr::ed_extract(ed, var = v, sf_zones = ply, bbox = bb, 
    mask_tif = F, rast_tif = glue("{dir_out}/{nms}/{yr}.tif"), 
    zonal_fun = "mean", zonal_csv = glue("{dir_out}/{nms}/{yr}.csv"), 
    dir_nc = glue("{dir_out}/{nms}/{yr}_nc"), keep_nc = F, n_max_vals_per_req = 1e+05, 
    time_min = time_min, time_max = time_max, verbose = T)
debug: while (i_req <= n_reqs) {
    i_t_beg <- (i_req - 1) * n_t_per_req + 1
    i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
    t_req <- times_todo[c(i_t_beg, i_t_end)]
    t_req_str <- format_ISO8601(t_req, usetz = "Z")
    if (verbose) 
        message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
    ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
        ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
        0), nc)
    unlink(ncs0)
    nc_retry <- T
    nc_n_try <- 1
    n_max_retries
    while (nc_retry) {
        res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
            url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
                bbox[["xmax"]]), latitude = c(bbox[["ymin"]], 
                bbox[["ymax"]]), time = t_req_str, fmt = "nc", 
            store = rerddap::disk(path = dir_nc)))
        if (inherits(res, "try-error")) {
            err <- attr(res, "condition")
            msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
            nc_n_try <- nc_n_try + 1
            if (nc_n_try > n_max_retries) {
                stop(msg)
            }
            else {
                message(msg, "\nRETRYing...")
                Sys.sleep(1)
            }
        }
        else {
            nc_retry <- F
        }
    }
    i_req <- i_req + 1
}
debug: i_t_beg <- (i_req - 1) * n_t_per_req + 1
debug: i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
debug: t_req <- times_todo[c(i_t_beg, i_t_end)]
debug: t_req_str <- format_ISO8601(t_req, usetz = "Z")
debug: if (verbose) message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
debug: message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
Fetching request 1 of 1 (2010-01-01 to 2010-12-01) ~ 19:45:08 UTC
debug: ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
    0), nc)
debug: unlink(ncs0)
debug: nc_retry <- T
debug: nc_n_try <- 1
debug: n_max_retries
debug: while (nc_retry) {
    res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
        url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
            bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
        time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
    if (inherits(res, "try-error")) {
        err <- attr(res, "condition")
        msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
        nc_n_try <- nc_n_try + 1
        if (nc_n_try > n_max_retries) {
            stop(msg)
        }
        else {
            message(msg, "\nRETRYing...")
            Sys.sleep(1)
        }
    }
    else {
        nc_retry <- F
    }
}
debug: res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
    url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
        bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
    time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
debug: if (inherits(res, "try-error")) {
    err <- attr(res, "condition")
    msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
    nc_n_try <- nc_n_try + 1
    if (nc_n_try > n_max_retries) {
        stop(msg)
    }
    else {
        message(msg, "\nRETRYing...")
        Sys.sleep(1)
    }
} else {
    nc_retry <- F
}
debug: nc_retry <- F
debug: (while) nc_retry
debug: i_req <- i_req + 1
debug: (while) i_req <= n_reqs
debug: ncs <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size > 
    0), nc)
debug: r <- terra::rast(ncs)
debug: stopifnot(all(class(terra::time(r)) %in% c("POSIXct", "POSIXt")))
debug: idx <- dplyr::pull(dplyr::filter(dplyr::arrange(dplyr::tibble(idx = 1:terra::nlyr(r), 
    time = terra::time(r)), time), !duplicated(time)), idx)
debug: r <- terra::subset(r, idx)
debug: stopifnot(terra::crs(r, proj = T) == wgs84)
debug: if (mask_tif) r <- terra::mask(r, sf_zones)
debug: lyrs <- glue("{var}|{terra::time(r)}")
debug: if (length(dims_other) > 0 && !all(length(dims[dims_other]) == 
    1)) stop(glue("Other dimensions not yet supported: {paste(dims_other, collapse = ',')}"))
debug: names(r) <- lyrs
debug: if (!is.null(rast_tif)) {
    if (fs::file_exists(rast_tif)) {
        r_tmp_tif <- tempfile(fileext = ".tif")
        r_tmp <- c(rast(rast_tif), r)
        r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
        terra::writeRaster(r_tmp, r_tmp_tif)
        fs::file_delete(rast_tif)
        fs::file_move(r_tmp_tif, rast_tif)
        rm(r)
        rm(r_tmp)
    }
    else {
        terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
    }
    r <- terra::rast(rast_tif)
}
debug: if (fs::file_exists(rast_tif)) {
    r_tmp_tif <- tempfile(fileext = ".tif")
    r_tmp <- c(rast(rast_tif), r)
    r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
    terra::writeRaster(r_tmp, r_tmp_tif)
    fs::file_delete(rast_tif)
    fs::file_move(r_tmp_tif, rast_tif)
    rm(r)
    rm(r_tmp)
} else {
    terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
}
debug: terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
debug: r <- terra::rast(rast_tif)
debug: d_r <- mutate(tidyr::pivot_longer(sf::st_drop_geometry(sf::st_as_sf(terra::zonal(x = r, 
    z = terra::vect(dplyr::select(sf_zones, dplyr::all_of(fld_zones))), 
    fun = zonal_fun, exact = T, na.rm = T, as.polygons = T))), 
    cols = -dplyr::any_of(fld_zones), names_to = "lyr", values_to = zonal_fun), 
    time = readr::parse_datetime(str_replace(lyr, glue("{var}\\|(.*)"), 
        "\\1")))
debug: if (!is.null(zonal_csv)) write_csv(d_r, zonal_csv)
debug: write_csv(d_r, zonal_csv)
debug: if (!keep_nc) unlink(dir_nc, recursive = T)
debug: unlink(dir_nc, recursive = T)
debug: return(d_r)
Downloading 1 requests, up to 512 time slices each
Called from: extractr::ed_extract(ed, var = v, sf_zones = ply, bbox = bb, 
    mask_tif = F, rast_tif = glue("{dir_out}/{nms}/{yr}.tif"), 
    zonal_fun = "mean", zonal_csv = glue("{dir_out}/{nms}/{yr}.csv"), 
    dir_nc = glue("{dir_out}/{nms}/{yr}_nc"), keep_nc = F, n_max_vals_per_req = 1e+05, 
    time_min = time_min, time_max = time_max, verbose = T)
debug: while (i_req <= n_reqs) {
    i_t_beg <- (i_req - 1) * n_t_per_req + 1
    i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
    t_req <- times_todo[c(i_t_beg, i_t_end)]
    t_req_str <- format_ISO8601(t_req, usetz = "Z")
    if (verbose) 
        message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
    ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
        ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
        0), nc)
    unlink(ncs0)
    nc_retry <- T
    nc_n_try <- 1
    n_max_retries
    while (nc_retry) {
        res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
            url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
                bbox[["xmax"]]), latitude = c(bbox[["ymin"]], 
                bbox[["ymax"]]), time = t_req_str, fmt = "nc", 
            store = rerddap::disk(path = dir_nc)))
        if (inherits(res, "try-error")) {
            err <- attr(res, "condition")
            msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
            nc_n_try <- nc_n_try + 1
            if (nc_n_try > n_max_retries) {
                stop(msg)
            }
            else {
                message(msg, "\nRETRYing...")
                Sys.sleep(1)
            }
        }
        else {
            nc_retry <- F
        }
    }
    i_req <- i_req + 1
}
debug: i_t_beg <- (i_req - 1) * n_t_per_req + 1
debug: i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
debug: t_req <- times_todo[c(i_t_beg, i_t_end)]
debug: t_req_str <- format_ISO8601(t_req, usetz = "Z")
debug: if (verbose) message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
debug: message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
Fetching request 1 of 1 (2011-01-01 to 2011-12-01) ~ 19:45:10 UTC
debug: ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
    0), nc)
debug: unlink(ncs0)
debug: nc_retry <- T
debug: nc_n_try <- 1
debug: n_max_retries
debug: while (nc_retry) {
    res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
        url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
            bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
        time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
    if (inherits(res, "try-error")) {
        err <- attr(res, "condition")
        msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
        nc_n_try <- nc_n_try + 1
        if (nc_n_try > n_max_retries) {
            stop(msg)
        }
        else {
            message(msg, "\nRETRYing...")
            Sys.sleep(1)
        }
    }
    else {
        nc_retry <- F
    }
}
debug: res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
    url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
        bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
    time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
debug: if (inherits(res, "try-error")) {
    err <- attr(res, "condition")
    msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
    nc_n_try <- nc_n_try + 1
    if (nc_n_try > n_max_retries) {
        stop(msg)
    }
    else {
        message(msg, "\nRETRYing...")
        Sys.sleep(1)
    }
} else {
    nc_retry <- F
}
debug: nc_retry <- F
debug: (while) nc_retry
debug: i_req <- i_req + 1
debug: (while) i_req <= n_reqs
debug: ncs <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size > 
    0), nc)
debug: r <- terra::rast(ncs)
debug: stopifnot(all(class(terra::time(r)) %in% c("POSIXct", "POSIXt")))
debug: idx <- dplyr::pull(dplyr::filter(dplyr::arrange(dplyr::tibble(idx = 1:terra::nlyr(r), 
    time = terra::time(r)), time), !duplicated(time)), idx)
debug: r <- terra::subset(r, idx)
debug: stopifnot(terra::crs(r, proj = T) == wgs84)
debug: if (mask_tif) r <- terra::mask(r, sf_zones)
debug: lyrs <- glue("{var}|{terra::time(r)}")
debug: if (length(dims_other) > 0 && !all(length(dims[dims_other]) == 
    1)) stop(glue("Other dimensions not yet supported: {paste(dims_other, collapse = ',')}"))
debug: names(r) <- lyrs
debug: if (!is.null(rast_tif)) {
    if (fs::file_exists(rast_tif)) {
        r_tmp_tif <- tempfile(fileext = ".tif")
        r_tmp <- c(rast(rast_tif), r)
        r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
        terra::writeRaster(r_tmp, r_tmp_tif)
        fs::file_delete(rast_tif)
        fs::file_move(r_tmp_tif, rast_tif)
        rm(r)
        rm(r_tmp)
    }
    else {
        terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
    }
    r <- terra::rast(rast_tif)
}
debug: if (fs::file_exists(rast_tif)) {
    r_tmp_tif <- tempfile(fileext = ".tif")
    r_tmp <- c(rast(rast_tif), r)
    r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
    terra::writeRaster(r_tmp, r_tmp_tif)
    fs::file_delete(rast_tif)
    fs::file_move(r_tmp_tif, rast_tif)
    rm(r)
    rm(r_tmp)
} else {
    terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
}
debug: terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
debug: r <- terra::rast(rast_tif)
debug: d_r <- mutate(tidyr::pivot_longer(sf::st_drop_geometry(sf::st_as_sf(terra::zonal(x = r, 
    z = terra::vect(dplyr::select(sf_zones, dplyr::all_of(fld_zones))), 
    fun = zonal_fun, exact = T, na.rm = T, as.polygons = T))), 
    cols = -dplyr::any_of(fld_zones), names_to = "lyr", values_to = zonal_fun), 
    time = readr::parse_datetime(str_replace(lyr, glue("{var}\\|(.*)"), 
        "\\1")))
debug: if (!is.null(zonal_csv)) write_csv(d_r, zonal_csv)
debug: write_csv(d_r, zonal_csv)
debug: if (!keep_nc) unlink(dir_nc, recursive = T)
debug: unlink(dir_nc, recursive = T)
debug: return(d_r)
Downloading 1 requests, up to 512 time slices each
Called from: extractr::ed_extract(ed, var = v, sf_zones = ply, bbox = bb, 
    mask_tif = F, rast_tif = glue("{dir_out}/{nms}/{yr}.tif"), 
    zonal_fun = "mean", zonal_csv = glue("{dir_out}/{nms}/{yr}.csv"), 
    dir_nc = glue("{dir_out}/{nms}/{yr}_nc"), keep_nc = F, n_max_vals_per_req = 1e+05, 
    time_min = time_min, time_max = time_max, verbose = T)
debug: while (i_req <= n_reqs) {
    i_t_beg <- (i_req - 1) * n_t_per_req + 1
    i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
    t_req <- times_todo[c(i_t_beg, i_t_end)]
    t_req_str <- format_ISO8601(t_req, usetz = "Z")
    if (verbose) 
        message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
    ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
        ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
        0), nc)
    unlink(ncs0)
    nc_retry <- T
    nc_n_try <- 1
    n_max_retries
    while (nc_retry) {
        res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
            url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
                bbox[["xmax"]]), latitude = c(bbox[["ymin"]], 
                bbox[["ymax"]]), time = t_req_str, fmt = "nc", 
            store = rerddap::disk(path = dir_nc)))
        if (inherits(res, "try-error")) {
            err <- attr(res, "condition")
            msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
            nc_n_try <- nc_n_try + 1
            if (nc_n_try > n_max_retries) {
                stop(msg)
            }
            else {
                message(msg, "\nRETRYing...")
                Sys.sleep(1)
            }
        }
        else {
            nc_retry <- F
        }
    }
    i_req <- i_req + 1
}
debug: i_t_beg <- (i_req - 1) * n_t_per_req + 1
debug: i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
debug: t_req <- times_todo[c(i_t_beg, i_t_end)]
debug: t_req_str <- format_ISO8601(t_req, usetz = "Z")
debug: if (verbose) message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
debug: message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
Fetching request 1 of 1 (2012-01-01 to 2012-12-01) ~ 19:45:11 UTC
debug: ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
    0), nc)
debug: unlink(ncs0)
debug: nc_retry <- T
debug: nc_n_try <- 1
debug: n_max_retries
debug: while (nc_retry) {
    res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
        url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
            bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
        time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
    if (inherits(res, "try-error")) {
        err <- attr(res, "condition")
        msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
        nc_n_try <- nc_n_try + 1
        if (nc_n_try > n_max_retries) {
            stop(msg)
        }
        else {
            message(msg, "\nRETRYing...")
            Sys.sleep(1)
        }
    }
    else {
        nc_retry <- F
    }
}
debug: res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
    url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
        bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
    time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
debug: if (inherits(res, "try-error")) {
    err <- attr(res, "condition")
    msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
    nc_n_try <- nc_n_try + 1
    if (nc_n_try > n_max_retries) {
        stop(msg)
    }
    else {
        message(msg, "\nRETRYing...")
        Sys.sleep(1)
    }
} else {
    nc_retry <- F
}
debug: nc_retry <- F
debug: (while) nc_retry
debug: i_req <- i_req + 1
debug: (while) i_req <= n_reqs
debug: ncs <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size > 
    0), nc)
debug: r <- terra::rast(ncs)
debug: stopifnot(all(class(terra::time(r)) %in% c("POSIXct", "POSIXt")))
debug: idx <- dplyr::pull(dplyr::filter(dplyr::arrange(dplyr::tibble(idx = 1:terra::nlyr(r), 
    time = terra::time(r)), time), !duplicated(time)), idx)
debug: r <- terra::subset(r, idx)
debug: stopifnot(terra::crs(r, proj = T) == wgs84)
debug: if (mask_tif) r <- terra::mask(r, sf_zones)
debug: lyrs <- glue("{var}|{terra::time(r)}")
debug: if (length(dims_other) > 0 && !all(length(dims[dims_other]) == 
    1)) stop(glue("Other dimensions not yet supported: {paste(dims_other, collapse = ',')}"))
debug: names(r) <- lyrs
debug: if (!is.null(rast_tif)) {
    if (fs::file_exists(rast_tif)) {
        r_tmp_tif <- tempfile(fileext = ".tif")
        r_tmp <- c(rast(rast_tif), r)
        r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
        terra::writeRaster(r_tmp, r_tmp_tif)
        fs::file_delete(rast_tif)
        fs::file_move(r_tmp_tif, rast_tif)
        rm(r)
        rm(r_tmp)
    }
    else {
        terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
    }
    r <- terra::rast(rast_tif)
}
debug: if (fs::file_exists(rast_tif)) {
    r_tmp_tif <- tempfile(fileext = ".tif")
    r_tmp <- c(rast(rast_tif), r)
    r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
    terra::writeRaster(r_tmp, r_tmp_tif)
    fs::file_delete(rast_tif)
    fs::file_move(r_tmp_tif, rast_tif)
    rm(r)
    rm(r_tmp)
} else {
    terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
}
debug: terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
debug: r <- terra::rast(rast_tif)
debug: d_r <- mutate(tidyr::pivot_longer(sf::st_drop_geometry(sf::st_as_sf(terra::zonal(x = r, 
    z = terra::vect(dplyr::select(sf_zones, dplyr::all_of(fld_zones))), 
    fun = zonal_fun, exact = T, na.rm = T, as.polygons = T))), 
    cols = -dplyr::any_of(fld_zones), names_to = "lyr", values_to = zonal_fun), 
    time = readr::parse_datetime(str_replace(lyr, glue("{var}\\|(.*)"), 
        "\\1")))
debug: if (!is.null(zonal_csv)) write_csv(d_r, zonal_csv)
debug: write_csv(d_r, zonal_csv)
debug: if (!keep_nc) unlink(dir_nc, recursive = T)
debug: unlink(dir_nc, recursive = T)
debug: return(d_r)
Downloading 1 requests, up to 512 time slices each
Called from: extractr::ed_extract(ed, var = v, sf_zones = ply, bbox = bb, 
    mask_tif = F, rast_tif = glue("{dir_out}/{nms}/{yr}.tif"), 
    zonal_fun = "mean", zonal_csv = glue("{dir_out}/{nms}/{yr}.csv"), 
    dir_nc = glue("{dir_out}/{nms}/{yr}_nc"), keep_nc = F, n_max_vals_per_req = 1e+05, 
    time_min = time_min, time_max = time_max, verbose = T)
debug: while (i_req <= n_reqs) {
    i_t_beg <- (i_req - 1) * n_t_per_req + 1
    i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
    t_req <- times_todo[c(i_t_beg, i_t_end)]
    t_req_str <- format_ISO8601(t_req, usetz = "Z")
    if (verbose) 
        message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
    ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
        ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
        0), nc)
    unlink(ncs0)
    nc_retry <- T
    nc_n_try <- 1
    n_max_retries
    while (nc_retry) {
        res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
            url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
                bbox[["xmax"]]), latitude = c(bbox[["ymin"]], 
                bbox[["ymax"]]), time = t_req_str, fmt = "nc", 
            store = rerddap::disk(path = dir_nc)))
        if (inherits(res, "try-error")) {
            err <- attr(res, "condition")
            msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
            nc_n_try <- nc_n_try + 1
            if (nc_n_try > n_max_retries) {
                stop(msg)
            }
            else {
                message(msg, "\nRETRYing...")
                Sys.sleep(1)
            }
        }
        else {
            nc_retry <- F
        }
    }
    i_req <- i_req + 1
}
debug: i_t_beg <- (i_req - 1) * n_t_per_req + 1
debug: i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
debug: t_req <- times_todo[c(i_t_beg, i_t_end)]
debug: t_req_str <- format_ISO8601(t_req, usetz = "Z")
debug: if (verbose) message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
debug: message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
Fetching request 1 of 1 (2013-01-01 to 2013-12-01) ~ 19:45:13 UTC
debug: ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
    0), nc)
debug: unlink(ncs0)
debug: nc_retry <- T
debug: nc_n_try <- 1
debug: n_max_retries
debug: while (nc_retry) {
    res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
        url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
            bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
        time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
    if (inherits(res, "try-error")) {
        err <- attr(res, "condition")
        msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
        nc_n_try <- nc_n_try + 1
        if (nc_n_try > n_max_retries) {
            stop(msg)
        }
        else {
            message(msg, "\nRETRYing...")
            Sys.sleep(1)
        }
    }
    else {
        nc_retry <- F
    }
}
debug: res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
    url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
        bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
    time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
debug: if (inherits(res, "try-error")) {
    err <- attr(res, "condition")
    msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
    nc_n_try <- nc_n_try + 1
    if (nc_n_try > n_max_retries) {
        stop(msg)
    }
    else {
        message(msg, "\nRETRYing...")
        Sys.sleep(1)
    }
} else {
    nc_retry <- F
}
debug: nc_retry <- F
debug: (while) nc_retry
debug: i_req <- i_req + 1
debug: (while) i_req <= n_reqs
debug: ncs <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size > 
    0), nc)
debug: r <- terra::rast(ncs)
debug: stopifnot(all(class(terra::time(r)) %in% c("POSIXct", "POSIXt")))
debug: idx <- dplyr::pull(dplyr::filter(dplyr::arrange(dplyr::tibble(idx = 1:terra::nlyr(r), 
    time = terra::time(r)), time), !duplicated(time)), idx)
debug: r <- terra::subset(r, idx)
debug: stopifnot(terra::crs(r, proj = T) == wgs84)
debug: if (mask_tif) r <- terra::mask(r, sf_zones)
debug: lyrs <- glue("{var}|{terra::time(r)}")
debug: if (length(dims_other) > 0 && !all(length(dims[dims_other]) == 
    1)) stop(glue("Other dimensions not yet supported: {paste(dims_other, collapse = ',')}"))
debug: names(r) <- lyrs
debug: if (!is.null(rast_tif)) {
    if (fs::file_exists(rast_tif)) {
        r_tmp_tif <- tempfile(fileext = ".tif")
        r_tmp <- c(rast(rast_tif), r)
        r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
        terra::writeRaster(r_tmp, r_tmp_tif)
        fs::file_delete(rast_tif)
        fs::file_move(r_tmp_tif, rast_tif)
        rm(r)
        rm(r_tmp)
    }
    else {
        terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
    }
    r <- terra::rast(rast_tif)
}
debug: if (fs::file_exists(rast_tif)) {
    r_tmp_tif <- tempfile(fileext = ".tif")
    r_tmp <- c(rast(rast_tif), r)
    r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
    terra::writeRaster(r_tmp, r_tmp_tif)
    fs::file_delete(rast_tif)
    fs::file_move(r_tmp_tif, rast_tif)
    rm(r)
    rm(r_tmp)
} else {
    terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
}
debug: terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
debug: r <- terra::rast(rast_tif)
debug: d_r <- mutate(tidyr::pivot_longer(sf::st_drop_geometry(sf::st_as_sf(terra::zonal(x = r, 
    z = terra::vect(dplyr::select(sf_zones, dplyr::all_of(fld_zones))), 
    fun = zonal_fun, exact = T, na.rm = T, as.polygons = T))), 
    cols = -dplyr::any_of(fld_zones), names_to = "lyr", values_to = zonal_fun), 
    time = readr::parse_datetime(str_replace(lyr, glue("{var}\\|(.*)"), 
        "\\1")))
debug: if (!is.null(zonal_csv)) write_csv(d_r, zonal_csv)
debug: write_csv(d_r, zonal_csv)
debug: if (!keep_nc) unlink(dir_nc, recursive = T)
debug: unlink(dir_nc, recursive = T)
debug: return(d_r)
Downloading 1 requests, up to 512 time slices each
Called from: extractr::ed_extract(ed, var = v, sf_zones = ply, bbox = bb, 
    mask_tif = F, rast_tif = glue("{dir_out}/{nms}/{yr}.tif"), 
    zonal_fun = "mean", zonal_csv = glue("{dir_out}/{nms}/{yr}.csv"), 
    dir_nc = glue("{dir_out}/{nms}/{yr}_nc"), keep_nc = F, n_max_vals_per_req = 1e+05, 
    time_min = time_min, time_max = time_max, verbose = T)
debug: while (i_req <= n_reqs) {
    i_t_beg <- (i_req - 1) * n_t_per_req + 1
    i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
    t_req <- times_todo[c(i_t_beg, i_t_end)]
    t_req_str <- format_ISO8601(t_req, usetz = "Z")
    if (verbose) 
        message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
    ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
        ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
        0), nc)
    unlink(ncs0)
    nc_retry <- T
    nc_n_try <- 1
    n_max_retries
    while (nc_retry) {
        res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
            url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
                bbox[["xmax"]]), latitude = c(bbox[["ymin"]], 
                bbox[["ymax"]]), time = t_req_str, fmt = "nc", 
            store = rerddap::disk(path = dir_nc)))
        if (inherits(res, "try-error")) {
            err <- attr(res, "condition")
            msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
            nc_n_try <- nc_n_try + 1
            if (nc_n_try > n_max_retries) {
                stop(msg)
            }
            else {
                message(msg, "\nRETRYing...")
                Sys.sleep(1)
            }
        }
        else {
            nc_retry <- F
        }
    }
    i_req <- i_req + 1
}
debug: i_t_beg <- (i_req - 1) * n_t_per_req + 1
debug: i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
debug: t_req <- times_todo[c(i_t_beg, i_t_end)]
debug: t_req_str <- format_ISO8601(t_req, usetz = "Z")
debug: if (verbose) message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
debug: message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
Fetching request 1 of 1 (2014-01-01 to 2014-12-01) ~ 19:45:15 UTC
debug: ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
    0), nc)
debug: unlink(ncs0)
debug: nc_retry <- T
debug: nc_n_try <- 1
debug: n_max_retries
debug: while (nc_retry) {
    res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
        url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
            bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
        time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
    if (inherits(res, "try-error")) {
        err <- attr(res, "condition")
        msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
        nc_n_try <- nc_n_try + 1
        if (nc_n_try > n_max_retries) {
            stop(msg)
        }
        else {
            message(msg, "\nRETRYing...")
            Sys.sleep(1)
        }
    }
    else {
        nc_retry <- F
    }
}
debug: res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
    url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
        bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
    time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
debug: if (inherits(res, "try-error")) {
    err <- attr(res, "condition")
    msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
    nc_n_try <- nc_n_try + 1
    if (nc_n_try > n_max_retries) {
        stop(msg)
    }
    else {
        message(msg, "\nRETRYing...")
        Sys.sleep(1)
    }
} else {
    nc_retry <- F
}
debug: nc_retry <- F
debug: (while) nc_retry
debug: i_req <- i_req + 1
debug: (while) i_req <= n_reqs
debug: ncs <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size > 
    0), nc)
debug: r <- terra::rast(ncs)
debug: stopifnot(all(class(terra::time(r)) %in% c("POSIXct", "POSIXt")))
debug: idx <- dplyr::pull(dplyr::filter(dplyr::arrange(dplyr::tibble(idx = 1:terra::nlyr(r), 
    time = terra::time(r)), time), !duplicated(time)), idx)
debug: r <- terra::subset(r, idx)
debug: stopifnot(terra::crs(r, proj = T) == wgs84)
debug: if (mask_tif) r <- terra::mask(r, sf_zones)
debug: lyrs <- glue("{var}|{terra::time(r)}")
debug: if (length(dims_other) > 0 && !all(length(dims[dims_other]) == 
    1)) stop(glue("Other dimensions not yet supported: {paste(dims_other, collapse = ',')}"))
debug: names(r) <- lyrs
debug: if (!is.null(rast_tif)) {
    if (fs::file_exists(rast_tif)) {
        r_tmp_tif <- tempfile(fileext = ".tif")
        r_tmp <- c(rast(rast_tif), r)
        r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
        terra::writeRaster(r_tmp, r_tmp_tif)
        fs::file_delete(rast_tif)
        fs::file_move(r_tmp_tif, rast_tif)
        rm(r)
        rm(r_tmp)
    }
    else {
        terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
    }
    r <- terra::rast(rast_tif)
}
debug: if (fs::file_exists(rast_tif)) {
    r_tmp_tif <- tempfile(fileext = ".tif")
    r_tmp <- c(rast(rast_tif), r)
    r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
    terra::writeRaster(r_tmp, r_tmp_tif)
    fs::file_delete(rast_tif)
    fs::file_move(r_tmp_tif, rast_tif)
    rm(r)
    rm(r_tmp)
} else {
    terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
}
debug: terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
debug: r <- terra::rast(rast_tif)
debug: d_r <- mutate(tidyr::pivot_longer(sf::st_drop_geometry(sf::st_as_sf(terra::zonal(x = r, 
    z = terra::vect(dplyr::select(sf_zones, dplyr::all_of(fld_zones))), 
    fun = zonal_fun, exact = T, na.rm = T, as.polygons = T))), 
    cols = -dplyr::any_of(fld_zones), names_to = "lyr", values_to = zonal_fun), 
    time = readr::parse_datetime(str_replace(lyr, glue("{var}\\|(.*)"), 
        "\\1")))
debug: if (!is.null(zonal_csv)) write_csv(d_r, zonal_csv)
debug: write_csv(d_r, zonal_csv)
debug: if (!keep_nc) unlink(dir_nc, recursive = T)
debug: unlink(dir_nc, recursive = T)
debug: return(d_r)
Downloading 1 requests, up to 512 time slices each
Called from: extractr::ed_extract(ed, var = v, sf_zones = ply, bbox = bb, 
    mask_tif = F, rast_tif = glue("{dir_out}/{nms}/{yr}.tif"), 
    zonal_fun = "mean", zonal_csv = glue("{dir_out}/{nms}/{yr}.csv"), 
    dir_nc = glue("{dir_out}/{nms}/{yr}_nc"), keep_nc = F, n_max_vals_per_req = 1e+05, 
    time_min = time_min, time_max = time_max, verbose = T)
debug: while (i_req <= n_reqs) {
    i_t_beg <- (i_req - 1) * n_t_per_req + 1
    i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
    t_req <- times_todo[c(i_t_beg, i_t_end)]
    t_req_str <- format_ISO8601(t_req, usetz = "Z")
    if (verbose) 
        message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
    ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
        ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
        0), nc)
    unlink(ncs0)
    nc_retry <- T
    nc_n_try <- 1
    n_max_retries
    while (nc_retry) {
        res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
            url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
                bbox[["xmax"]]), latitude = c(bbox[["ymin"]], 
                bbox[["ymax"]]), time = t_req_str, fmt = "nc", 
            store = rerddap::disk(path = dir_nc)))
        if (inherits(res, "try-error")) {
            err <- attr(res, "condition")
            msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
            nc_n_try <- nc_n_try + 1
            if (nc_n_try > n_max_retries) {
                stop(msg)
            }
            else {
                message(msg, "\nRETRYing...")
                Sys.sleep(1)
            }
        }
        else {
            nc_retry <- F
        }
    }
    i_req <- i_req + 1
}
debug: i_t_beg <- (i_req - 1) * n_t_per_req + 1
debug: i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
debug: t_req <- times_todo[c(i_t_beg, i_t_end)]
debug: t_req_str <- format_ISO8601(t_req, usetz = "Z")
debug: if (verbose) message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
debug: message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
Fetching request 1 of 1 (2015-01-01 to 2015-12-01) ~ 19:45:17 UTC
debug: ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
    0), nc)
debug: unlink(ncs0)
debug: nc_retry <- T
debug: nc_n_try <- 1
debug: n_max_retries
debug: while (nc_retry) {
    res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
        url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
            bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
        time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
    if (inherits(res, "try-error")) {
        err <- attr(res, "condition")
        msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
        nc_n_try <- nc_n_try + 1
        if (nc_n_try > n_max_retries) {
            stop(msg)
        }
        else {
            message(msg, "\nRETRYing...")
            Sys.sleep(1)
        }
    }
    else {
        nc_retry <- F
    }
}
debug: res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
    url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
        bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
    time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
debug: if (inherits(res, "try-error")) {
    err <- attr(res, "condition")
    msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
    nc_n_try <- nc_n_try + 1
    if (nc_n_try > n_max_retries) {
        stop(msg)
    }
    else {
        message(msg, "\nRETRYing...")
        Sys.sleep(1)
    }
} else {
    nc_retry <- F
}
debug: nc_retry <- F
debug: (while) nc_retry
debug: i_req <- i_req + 1
debug: (while) i_req <= n_reqs
debug: ncs <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size > 
    0), nc)
debug: r <- terra::rast(ncs)
debug: stopifnot(all(class(terra::time(r)) %in% c("POSIXct", "POSIXt")))
debug: idx <- dplyr::pull(dplyr::filter(dplyr::arrange(dplyr::tibble(idx = 1:terra::nlyr(r), 
    time = terra::time(r)), time), !duplicated(time)), idx)
debug: r <- terra::subset(r, idx)
debug: stopifnot(terra::crs(r, proj = T) == wgs84)
debug: if (mask_tif) r <- terra::mask(r, sf_zones)
debug: lyrs <- glue("{var}|{terra::time(r)}")
debug: if (length(dims_other) > 0 && !all(length(dims[dims_other]) == 
    1)) stop(glue("Other dimensions not yet supported: {paste(dims_other, collapse = ',')}"))
debug: names(r) <- lyrs
debug: if (!is.null(rast_tif)) {
    if (fs::file_exists(rast_tif)) {
        r_tmp_tif <- tempfile(fileext = ".tif")
        r_tmp <- c(rast(rast_tif), r)
        r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
        terra::writeRaster(r_tmp, r_tmp_tif)
        fs::file_delete(rast_tif)
        fs::file_move(r_tmp_tif, rast_tif)
        rm(r)
        rm(r_tmp)
    }
    else {
        terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
    }
    r <- terra::rast(rast_tif)
}
debug: if (fs::file_exists(rast_tif)) {
    r_tmp_tif <- tempfile(fileext = ".tif")
    r_tmp <- c(rast(rast_tif), r)
    r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
    terra::writeRaster(r_tmp, r_tmp_tif)
    fs::file_delete(rast_tif)
    fs::file_move(r_tmp_tif, rast_tif)
    rm(r)
    rm(r_tmp)
} else {
    terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
}
debug: terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
debug: r <- terra::rast(rast_tif)
debug: d_r <- mutate(tidyr::pivot_longer(sf::st_drop_geometry(sf::st_as_sf(terra::zonal(x = r, 
    z = terra::vect(dplyr::select(sf_zones, dplyr::all_of(fld_zones))), 
    fun = zonal_fun, exact = T, na.rm = T, as.polygons = T))), 
    cols = -dplyr::any_of(fld_zones), names_to = "lyr", values_to = zonal_fun), 
    time = readr::parse_datetime(str_replace(lyr, glue("{var}\\|(.*)"), 
        "\\1")))
debug: if (!is.null(zonal_csv)) write_csv(d_r, zonal_csv)
debug: write_csv(d_r, zonal_csv)
debug: if (!keep_nc) unlink(dir_nc, recursive = T)
debug: unlink(dir_nc, recursive = T)
debug: return(d_r)
Downloading 1 requests, up to 512 time slices each
Called from: extractr::ed_extract(ed, var = v, sf_zones = ply, bbox = bb, 
    mask_tif = F, rast_tif = glue("{dir_out}/{nms}/{yr}.tif"), 
    zonal_fun = "mean", zonal_csv = glue("{dir_out}/{nms}/{yr}.csv"), 
    dir_nc = glue("{dir_out}/{nms}/{yr}_nc"), keep_nc = F, n_max_vals_per_req = 1e+05, 
    time_min = time_min, time_max = time_max, verbose = T)
debug: while (i_req <= n_reqs) {
    i_t_beg <- (i_req - 1) * n_t_per_req + 1
    i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
    t_req <- times_todo[c(i_t_beg, i_t_end)]
    t_req_str <- format_ISO8601(t_req, usetz = "Z")
    if (verbose) 
        message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
    ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
        ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
        0), nc)
    unlink(ncs0)
    nc_retry <- T
    nc_n_try <- 1
    n_max_retries
    while (nc_retry) {
        res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
            url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
                bbox[["xmax"]]), latitude = c(bbox[["ymin"]], 
                bbox[["ymax"]]), time = t_req_str, fmt = "nc", 
            store = rerddap::disk(path = dir_nc)))
        if (inherits(res, "try-error")) {
            err <- attr(res, "condition")
            msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
            nc_n_try <- nc_n_try + 1
            if (nc_n_try > n_max_retries) {
                stop(msg)
            }
            else {
                message(msg, "\nRETRYing...")
                Sys.sleep(1)
            }
        }
        else {
            nc_retry <- F
        }
    }
    i_req <- i_req + 1
}
debug: i_t_beg <- (i_req - 1) * n_t_per_req + 1
debug: i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
debug: t_req <- times_todo[c(i_t_beg, i_t_end)]
debug: t_req_str <- format_ISO8601(t_req, usetz = "Z")
debug: if (verbose) message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
debug: message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
Fetching request 1 of 1 (2016-01-01 to 2016-12-01) ~ 19:45:18 UTC
debug: ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
    0), nc)
debug: unlink(ncs0)
debug: nc_retry <- T
debug: nc_n_try <- 1
debug: n_max_retries
debug: while (nc_retry) {
    res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
        url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
            bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
        time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
    if (inherits(res, "try-error")) {
        err <- attr(res, "condition")
        msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
        nc_n_try <- nc_n_try + 1
        if (nc_n_try > n_max_retries) {
            stop(msg)
        }
        else {
            message(msg, "\nRETRYing...")
            Sys.sleep(1)
        }
    }
    else {
        nc_retry <- F
    }
}
debug: res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
    url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
        bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
    time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
debug: if (inherits(res, "try-error")) {
    err <- attr(res, "condition")
    msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
    nc_n_try <- nc_n_try + 1
    if (nc_n_try > n_max_retries) {
        stop(msg)
    }
    else {
        message(msg, "\nRETRYing...")
        Sys.sleep(1)
    }
} else {
    nc_retry <- F
}
debug: nc_retry <- F
debug: (while) nc_retry
debug: i_req <- i_req + 1
debug: (while) i_req <= n_reqs
debug: ncs <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size > 
    0), nc)
debug: r <- terra::rast(ncs)
debug: stopifnot(all(class(terra::time(r)) %in% c("POSIXct", "POSIXt")))
debug: idx <- dplyr::pull(dplyr::filter(dplyr::arrange(dplyr::tibble(idx = 1:terra::nlyr(r), 
    time = terra::time(r)), time), !duplicated(time)), idx)
debug: r <- terra::subset(r, idx)
debug: stopifnot(terra::crs(r, proj = T) == wgs84)
debug: if (mask_tif) r <- terra::mask(r, sf_zones)
debug: lyrs <- glue("{var}|{terra::time(r)}")
debug: if (length(dims_other) > 0 && !all(length(dims[dims_other]) == 
    1)) stop(glue("Other dimensions not yet supported: {paste(dims_other, collapse = ',')}"))
debug: names(r) <- lyrs
debug: if (!is.null(rast_tif)) {
    if (fs::file_exists(rast_tif)) {
        r_tmp_tif <- tempfile(fileext = ".tif")
        r_tmp <- c(rast(rast_tif), r)
        r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
        terra::writeRaster(r_tmp, r_tmp_tif)
        fs::file_delete(rast_tif)
        fs::file_move(r_tmp_tif, rast_tif)
        rm(r)
        rm(r_tmp)
    }
    else {
        terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
    }
    r <- terra::rast(rast_tif)
}
debug: if (fs::file_exists(rast_tif)) {
    r_tmp_tif <- tempfile(fileext = ".tif")
    r_tmp <- c(rast(rast_tif), r)
    r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
    terra::writeRaster(r_tmp, r_tmp_tif)
    fs::file_delete(rast_tif)
    fs::file_move(r_tmp_tif, rast_tif)
    rm(r)
    rm(r_tmp)
} else {
    terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
}
debug: terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
debug: r <- terra::rast(rast_tif)
debug: d_r <- mutate(tidyr::pivot_longer(sf::st_drop_geometry(sf::st_as_sf(terra::zonal(x = r, 
    z = terra::vect(dplyr::select(sf_zones, dplyr::all_of(fld_zones))), 
    fun = zonal_fun, exact = T, na.rm = T, as.polygons = T))), 
    cols = -dplyr::any_of(fld_zones), names_to = "lyr", values_to = zonal_fun), 
    time = readr::parse_datetime(str_replace(lyr, glue("{var}\\|(.*)"), 
        "\\1")))
debug: if (!is.null(zonal_csv)) write_csv(d_r, zonal_csv)
debug: write_csv(d_r, zonal_csv)
debug: if (!keep_nc) unlink(dir_nc, recursive = T)
debug: unlink(dir_nc, recursive = T)
debug: return(d_r)
Downloading 1 requests, up to 512 time slices each
Called from: extractr::ed_extract(ed, var = v, sf_zones = ply, bbox = bb, 
    mask_tif = F, rast_tif = glue("{dir_out}/{nms}/{yr}.tif"), 
    zonal_fun = "mean", zonal_csv = glue("{dir_out}/{nms}/{yr}.csv"), 
    dir_nc = glue("{dir_out}/{nms}/{yr}_nc"), keep_nc = F, n_max_vals_per_req = 1e+05, 
    time_min = time_min, time_max = time_max, verbose = T)
debug: while (i_req <= n_reqs) {
    i_t_beg <- (i_req - 1) * n_t_per_req + 1
    i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
    t_req <- times_todo[c(i_t_beg, i_t_end)]
    t_req_str <- format_ISO8601(t_req, usetz = "Z")
    if (verbose) 
        message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
    ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
        ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
        0), nc)
    unlink(ncs0)
    nc_retry <- T
    nc_n_try <- 1
    n_max_retries
    while (nc_retry) {
        res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
            url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
                bbox[["xmax"]]), latitude = c(bbox[["ymin"]], 
                bbox[["ymax"]]), time = t_req_str, fmt = "nc", 
            store = rerddap::disk(path = dir_nc)))
        if (inherits(res, "try-error")) {
            err <- attr(res, "condition")
            msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
            nc_n_try <- nc_n_try + 1
            if (nc_n_try > n_max_retries) {
                stop(msg)
            }
            else {
                message(msg, "\nRETRYing...")
                Sys.sleep(1)
            }
        }
        else {
            nc_retry <- F
        }
    }
    i_req <- i_req + 1
}
debug: i_t_beg <- (i_req - 1) * n_t_per_req + 1
debug: i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
debug: t_req <- times_todo[c(i_t_beg, i_t_end)]
debug: t_req_str <- format_ISO8601(t_req, usetz = "Z")
debug: if (verbose) message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
debug: message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
Fetching request 1 of 1 (2017-01-01 to 2017-12-01) ~ 19:45:20 UTC
debug: ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
    0), nc)
debug: unlink(ncs0)
debug: nc_retry <- T
debug: nc_n_try <- 1
debug: n_max_retries
debug: while (nc_retry) {
    res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
        url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
            bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
        time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
    if (inherits(res, "try-error")) {
        err <- attr(res, "condition")
        msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
        nc_n_try <- nc_n_try + 1
        if (nc_n_try > n_max_retries) {
            stop(msg)
        }
        else {
            message(msg, "\nRETRYing...")
            Sys.sleep(1)
        }
    }
    else {
        nc_retry <- F
    }
}
debug: res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
    url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
        bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
    time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
debug: if (inherits(res, "try-error")) {
    err <- attr(res, "condition")
    msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
    nc_n_try <- nc_n_try + 1
    if (nc_n_try > n_max_retries) {
        stop(msg)
    }
    else {
        message(msg, "\nRETRYing...")
        Sys.sleep(1)
    }
} else {
    nc_retry <- F
}
debug: nc_retry <- F
debug: (while) nc_retry
debug: i_req <- i_req + 1
debug: (while) i_req <= n_reqs
debug: ncs <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size > 
    0), nc)
debug: r <- terra::rast(ncs)
debug: stopifnot(all(class(terra::time(r)) %in% c("POSIXct", "POSIXt")))
debug: idx <- dplyr::pull(dplyr::filter(dplyr::arrange(dplyr::tibble(idx = 1:terra::nlyr(r), 
    time = terra::time(r)), time), !duplicated(time)), idx)
debug: r <- terra::subset(r, idx)
debug: stopifnot(terra::crs(r, proj = T) == wgs84)
debug: if (mask_tif) r <- terra::mask(r, sf_zones)
debug: lyrs <- glue("{var}|{terra::time(r)}")
debug: if (length(dims_other) > 0 && !all(length(dims[dims_other]) == 
    1)) stop(glue("Other dimensions not yet supported: {paste(dims_other, collapse = ',')}"))
debug: names(r) <- lyrs
debug: if (!is.null(rast_tif)) {
    if (fs::file_exists(rast_tif)) {
        r_tmp_tif <- tempfile(fileext = ".tif")
        r_tmp <- c(rast(rast_tif), r)
        r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
        terra::writeRaster(r_tmp, r_tmp_tif)
        fs::file_delete(rast_tif)
        fs::file_move(r_tmp_tif, rast_tif)
        rm(r)
        rm(r_tmp)
    }
    else {
        terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
    }
    r <- terra::rast(rast_tif)
}
debug: if (fs::file_exists(rast_tif)) {
    r_tmp_tif <- tempfile(fileext = ".tif")
    r_tmp <- c(rast(rast_tif), r)
    r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
    terra::writeRaster(r_tmp, r_tmp_tif)
    fs::file_delete(rast_tif)
    fs::file_move(r_tmp_tif, rast_tif)
    rm(r)
    rm(r_tmp)
} else {
    terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
}
debug: terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
debug: r <- terra::rast(rast_tif)
debug: d_r <- mutate(tidyr::pivot_longer(sf::st_drop_geometry(sf::st_as_sf(terra::zonal(x = r, 
    z = terra::vect(dplyr::select(sf_zones, dplyr::all_of(fld_zones))), 
    fun = zonal_fun, exact = T, na.rm = T, as.polygons = T))), 
    cols = -dplyr::any_of(fld_zones), names_to = "lyr", values_to = zonal_fun), 
    time = readr::parse_datetime(str_replace(lyr, glue("{var}\\|(.*)"), 
        "\\1")))
debug: if (!is.null(zonal_csv)) write_csv(d_r, zonal_csv)
debug: write_csv(d_r, zonal_csv)
debug: if (!keep_nc) unlink(dir_nc, recursive = T)
debug: unlink(dir_nc, recursive = T)
debug: return(d_r)
Downloading 1 requests, up to 512 time slices each
Called from: extractr::ed_extract(ed, var = v, sf_zones = ply, bbox = bb, 
    mask_tif = F, rast_tif = glue("{dir_out}/{nms}/{yr}.tif"), 
    zonal_fun = "mean", zonal_csv = glue("{dir_out}/{nms}/{yr}.csv"), 
    dir_nc = glue("{dir_out}/{nms}/{yr}_nc"), keep_nc = F, n_max_vals_per_req = 1e+05, 
    time_min = time_min, time_max = time_max, verbose = T)
debug: while (i_req <= n_reqs) {
    i_t_beg <- (i_req - 1) * n_t_per_req + 1
    i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
    t_req <- times_todo[c(i_t_beg, i_t_end)]
    t_req_str <- format_ISO8601(t_req, usetz = "Z")
    if (verbose) 
        message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
    ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
        ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
        0), nc)
    unlink(ncs0)
    nc_retry <- T
    nc_n_try <- 1
    n_max_retries
    while (nc_retry) {
        res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
            url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
                bbox[["xmax"]]), latitude = c(bbox[["ymin"]], 
                bbox[["ymax"]]), time = t_req_str, fmt = "nc", 
            store = rerddap::disk(path = dir_nc)))
        if (inherits(res, "try-error")) {
            err <- attr(res, "condition")
            msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
            nc_n_try <- nc_n_try + 1
            if (nc_n_try > n_max_retries) {
                stop(msg)
            }
            else {
                message(msg, "\nRETRYing...")
                Sys.sleep(1)
            }
        }
        else {
            nc_retry <- F
        }
    }
    i_req <- i_req + 1
}
debug: i_t_beg <- (i_req - 1) * n_t_per_req + 1
debug: i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
debug: t_req <- times_todo[c(i_t_beg, i_t_end)]
debug: t_req_str <- format_ISO8601(t_req, usetz = "Z")
debug: if (verbose) message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
debug: message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
Fetching request 1 of 1 (2018-01-01 to 2018-12-01) ~ 19:45:22 UTC
debug: ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
    0), nc)
debug: unlink(ncs0)
debug: nc_retry <- T
debug: nc_n_try <- 1
debug: n_max_retries
debug: while (nc_retry) {
    res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
        url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
            bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
        time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
    if (inherits(res, "try-error")) {
        err <- attr(res, "condition")
        msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
        nc_n_try <- nc_n_try + 1
        if (nc_n_try > n_max_retries) {
            stop(msg)
        }
        else {
            message(msg, "\nRETRYing...")
            Sys.sleep(1)
        }
    }
    else {
        nc_retry <- F
    }
}
debug: res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
    url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
        bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
    time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
debug: if (inherits(res, "try-error")) {
    err <- attr(res, "condition")
    msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
    nc_n_try <- nc_n_try + 1
    if (nc_n_try > n_max_retries) {
        stop(msg)
    }
    else {
        message(msg, "\nRETRYing...")
        Sys.sleep(1)
    }
} else {
    nc_retry <- F
}
debug: nc_retry <- F
debug: (while) nc_retry
debug: i_req <- i_req + 1
debug: (while) i_req <= n_reqs
debug: ncs <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size > 
    0), nc)
debug: r <- terra::rast(ncs)
debug: stopifnot(all(class(terra::time(r)) %in% c("POSIXct", "POSIXt")))
debug: idx <- dplyr::pull(dplyr::filter(dplyr::arrange(dplyr::tibble(idx = 1:terra::nlyr(r), 
    time = terra::time(r)), time), !duplicated(time)), idx)
debug: r <- terra::subset(r, idx)
debug: stopifnot(terra::crs(r, proj = T) == wgs84)
debug: if (mask_tif) r <- terra::mask(r, sf_zones)
debug: lyrs <- glue("{var}|{terra::time(r)}")
debug: if (length(dims_other) > 0 && !all(length(dims[dims_other]) == 
    1)) stop(glue("Other dimensions not yet supported: {paste(dims_other, collapse = ',')}"))
debug: names(r) <- lyrs
debug: if (!is.null(rast_tif)) {
    if (fs::file_exists(rast_tif)) {
        r_tmp_tif <- tempfile(fileext = ".tif")
        r_tmp <- c(rast(rast_tif), r)
        r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
        terra::writeRaster(r_tmp, r_tmp_tif)
        fs::file_delete(rast_tif)
        fs::file_move(r_tmp_tif, rast_tif)
        rm(r)
        rm(r_tmp)
    }
    else {
        terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
    }
    r <- terra::rast(rast_tif)
}
debug: if (fs::file_exists(rast_tif)) {
    r_tmp_tif <- tempfile(fileext = ".tif")
    r_tmp <- c(rast(rast_tif), r)
    r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
    terra::writeRaster(r_tmp, r_tmp_tif)
    fs::file_delete(rast_tif)
    fs::file_move(r_tmp_tif, rast_tif)
    rm(r)
    rm(r_tmp)
} else {
    terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
}
debug: terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
debug: r <- terra::rast(rast_tif)
debug: d_r <- mutate(tidyr::pivot_longer(sf::st_drop_geometry(sf::st_as_sf(terra::zonal(x = r, 
    z = terra::vect(dplyr::select(sf_zones, dplyr::all_of(fld_zones))), 
    fun = zonal_fun, exact = T, na.rm = T, as.polygons = T))), 
    cols = -dplyr::any_of(fld_zones), names_to = "lyr", values_to = zonal_fun), 
    time = readr::parse_datetime(str_replace(lyr, glue("{var}\\|(.*)"), 
        "\\1")))
debug: if (!is.null(zonal_csv)) write_csv(d_r, zonal_csv)
debug: write_csv(d_r, zonal_csv)
debug: if (!keep_nc) unlink(dir_nc, recursive = T)
debug: unlink(dir_nc, recursive = T)
debug: return(d_r)
Downloading 1 requests, up to 512 time slices each
Called from: extractr::ed_extract(ed, var = v, sf_zones = ply, bbox = bb, 
    mask_tif = F, rast_tif = glue("{dir_out}/{nms}/{yr}.tif"), 
    zonal_fun = "mean", zonal_csv = glue("{dir_out}/{nms}/{yr}.csv"), 
    dir_nc = glue("{dir_out}/{nms}/{yr}_nc"), keep_nc = F, n_max_vals_per_req = 1e+05, 
    time_min = time_min, time_max = time_max, verbose = T)
debug: while (i_req <= n_reqs) {
    i_t_beg <- (i_req - 1) * n_t_per_req + 1
    i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
    t_req <- times_todo[c(i_t_beg, i_t_end)]
    t_req_str <- format_ISO8601(t_req, usetz = "Z")
    if (verbose) 
        message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
    ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
        ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
        0), nc)
    unlink(ncs0)
    nc_retry <- T
    nc_n_try <- 1
    n_max_retries
    while (nc_retry) {
        res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
            url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
                bbox[["xmax"]]), latitude = c(bbox[["ymin"]], 
                bbox[["ymax"]]), time = t_req_str, fmt = "nc", 
            store = rerddap::disk(path = dir_nc)))
        if (inherits(res, "try-error")) {
            err <- attr(res, "condition")
            msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
            nc_n_try <- nc_n_try + 1
            if (nc_n_try > n_max_retries) {
                stop(msg)
            }
            else {
                message(msg, "\nRETRYing...")
                Sys.sleep(1)
            }
        }
        else {
            nc_retry <- F
        }
    }
    i_req <- i_req + 1
}
debug: i_t_beg <- (i_req - 1) * n_t_per_req + 1
debug: i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
debug: t_req <- times_todo[c(i_t_beg, i_t_end)]
debug: t_req_str <- format_ISO8601(t_req, usetz = "Z")
debug: if (verbose) message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
debug: message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
Fetching request 1 of 1 (2019-01-01 to 2019-12-01) ~ 19:45:24 UTC
debug: ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
    0), nc)
debug: unlink(ncs0)
debug: nc_retry <- T
debug: nc_n_try <- 1
debug: n_max_retries
debug: while (nc_retry) {
    res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
        url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
            bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
        time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
    if (inherits(res, "try-error")) {
        err <- attr(res, "condition")
        msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
        nc_n_try <- nc_n_try + 1
        if (nc_n_try > n_max_retries) {
            stop(msg)
        }
        else {
            message(msg, "\nRETRYing...")
            Sys.sleep(1)
        }
    }
    else {
        nc_retry <- F
    }
}
debug: res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
    url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
        bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
    time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
debug: if (inherits(res, "try-error")) {
    err <- attr(res, "condition")
    msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
    nc_n_try <- nc_n_try + 1
    if (nc_n_try > n_max_retries) {
        stop(msg)
    }
    else {
        message(msg, "\nRETRYing...")
        Sys.sleep(1)
    }
} else {
    nc_retry <- F
}
debug: nc_retry <- F
debug: (while) nc_retry
debug: i_req <- i_req + 1
debug: (while) i_req <= n_reqs
debug: ncs <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size > 
    0), nc)
debug: r <- terra::rast(ncs)
debug: stopifnot(all(class(terra::time(r)) %in% c("POSIXct", "POSIXt")))
debug: idx <- dplyr::pull(dplyr::filter(dplyr::arrange(dplyr::tibble(idx = 1:terra::nlyr(r), 
    time = terra::time(r)), time), !duplicated(time)), idx)
debug: r <- terra::subset(r, idx)
debug: stopifnot(terra::crs(r, proj = T) == wgs84)
debug: if (mask_tif) r <- terra::mask(r, sf_zones)
debug: lyrs <- glue("{var}|{terra::time(r)}")
debug: if (length(dims_other) > 0 && !all(length(dims[dims_other]) == 
    1)) stop(glue("Other dimensions not yet supported: {paste(dims_other, collapse = ',')}"))
debug: names(r) <- lyrs
debug: if (!is.null(rast_tif)) {
    if (fs::file_exists(rast_tif)) {
        r_tmp_tif <- tempfile(fileext = ".tif")
        r_tmp <- c(rast(rast_tif), r)
        r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
        terra::writeRaster(r_tmp, r_tmp_tif)
        fs::file_delete(rast_tif)
        fs::file_move(r_tmp_tif, rast_tif)
        rm(r)
        rm(r_tmp)
    }
    else {
        terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
    }
    r <- terra::rast(rast_tif)
}
debug: if (fs::file_exists(rast_tif)) {
    r_tmp_tif <- tempfile(fileext = ".tif")
    r_tmp <- c(rast(rast_tif), r)
    r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
    terra::writeRaster(r_tmp, r_tmp_tif)
    fs::file_delete(rast_tif)
    fs::file_move(r_tmp_tif, rast_tif)
    rm(r)
    rm(r_tmp)
} else {
    terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
}
debug: terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
debug: r <- terra::rast(rast_tif)
debug: d_r <- mutate(tidyr::pivot_longer(sf::st_drop_geometry(sf::st_as_sf(terra::zonal(x = r, 
    z = terra::vect(dplyr::select(sf_zones, dplyr::all_of(fld_zones))), 
    fun = zonal_fun, exact = T, na.rm = T, as.polygons = T))), 
    cols = -dplyr::any_of(fld_zones), names_to = "lyr", values_to = zonal_fun), 
    time = readr::parse_datetime(str_replace(lyr, glue("{var}\\|(.*)"), 
        "\\1")))
debug: if (!is.null(zonal_csv)) write_csv(d_r, zonal_csv)
debug: write_csv(d_r, zonal_csv)
debug: if (!keep_nc) unlink(dir_nc, recursive = T)
debug: unlink(dir_nc, recursive = T)
debug: return(d_r)
Downloading 1 requests, up to 512 time slices each
Called from: extractr::ed_extract(ed, var = v, sf_zones = ply, bbox = bb, 
    mask_tif = F, rast_tif = glue("{dir_out}/{nms}/{yr}.tif"), 
    zonal_fun = "mean", zonal_csv = glue("{dir_out}/{nms}/{yr}.csv"), 
    dir_nc = glue("{dir_out}/{nms}/{yr}_nc"), keep_nc = F, n_max_vals_per_req = 1e+05, 
    time_min = time_min, time_max = time_max, verbose = T)
debug: while (i_req <= n_reqs) {
    i_t_beg <- (i_req - 1) * n_t_per_req + 1
    i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
    t_req <- times_todo[c(i_t_beg, i_t_end)]
    t_req_str <- format_ISO8601(t_req, usetz = "Z")
    if (verbose) 
        message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
    ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
        ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
        0), nc)
    unlink(ncs0)
    nc_retry <- T
    nc_n_try <- 1
    n_max_retries
    while (nc_retry) {
        res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
            url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
                bbox[["xmax"]]), latitude = c(bbox[["ymin"]], 
                bbox[["ymax"]]), time = t_req_str, fmt = "nc", 
            store = rerddap::disk(path = dir_nc)))
        if (inherits(res, "try-error")) {
            err <- attr(res, "condition")
            msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
            nc_n_try <- nc_n_try + 1
            if (nc_n_try > n_max_retries) {
                stop(msg)
            }
            else {
                message(msg, "\nRETRYing...")
                Sys.sleep(1)
            }
        }
        else {
            nc_retry <- F
        }
    }
    i_req <- i_req + 1
}
debug: i_t_beg <- (i_req - 1) * n_t_per_req + 1
debug: i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
debug: t_req <- times_todo[c(i_t_beg, i_t_end)]
debug: t_req_str <- format_ISO8601(t_req, usetz = "Z")
debug: if (verbose) message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
debug: message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
Fetching request 1 of 1 (2020-01-01 to 2020-12-01) ~ 19:45:25 UTC
debug: ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
    0), nc)
debug: unlink(ncs0)
debug: nc_retry <- T
debug: nc_n_try <- 1
debug: n_max_retries
debug: while (nc_retry) {
    res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
        url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
            bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
        time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
    if (inherits(res, "try-error")) {
        err <- attr(res, "condition")
        msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
        nc_n_try <- nc_n_try + 1
        if (nc_n_try > n_max_retries) {
            stop(msg)
        }
        else {
            message(msg, "\nRETRYing...")
            Sys.sleep(1)
        }
    }
    else {
        nc_retry <- F
    }
}
debug: res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
    url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
        bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
    time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
debug: if (inherits(res, "try-error")) {
    err <- attr(res, "condition")
    msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
    nc_n_try <- nc_n_try + 1
    if (nc_n_try > n_max_retries) {
        stop(msg)
    }
    else {
        message(msg, "\nRETRYing...")
        Sys.sleep(1)
    }
} else {
    nc_retry <- F
}
debug: nc_retry <- F
debug: (while) nc_retry
debug: i_req <- i_req + 1
debug: (while) i_req <= n_reqs
debug: ncs <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size > 
    0), nc)
debug: r <- terra::rast(ncs)
debug: stopifnot(all(class(terra::time(r)) %in% c("POSIXct", "POSIXt")))
debug: idx <- dplyr::pull(dplyr::filter(dplyr::arrange(dplyr::tibble(idx = 1:terra::nlyr(r), 
    time = terra::time(r)), time), !duplicated(time)), idx)
debug: r <- terra::subset(r, idx)
debug: stopifnot(terra::crs(r, proj = T) == wgs84)
debug: if (mask_tif) r <- terra::mask(r, sf_zones)
debug: lyrs <- glue("{var}|{terra::time(r)}")
debug: if (length(dims_other) > 0 && !all(length(dims[dims_other]) == 
    1)) stop(glue("Other dimensions not yet supported: {paste(dims_other, collapse = ',')}"))
debug: names(r) <- lyrs
debug: if (!is.null(rast_tif)) {
    if (fs::file_exists(rast_tif)) {
        r_tmp_tif <- tempfile(fileext = ".tif")
        r_tmp <- c(rast(rast_tif), r)
        r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
        terra::writeRaster(r_tmp, r_tmp_tif)
        fs::file_delete(rast_tif)
        fs::file_move(r_tmp_tif, rast_tif)
        rm(r)
        rm(r_tmp)
    }
    else {
        terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
    }
    r <- terra::rast(rast_tif)
}
debug: if (fs::file_exists(rast_tif)) {
    r_tmp_tif <- tempfile(fileext = ".tif")
    r_tmp <- c(rast(rast_tif), r)
    r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
    terra::writeRaster(r_tmp, r_tmp_tif)
    fs::file_delete(rast_tif)
    fs::file_move(r_tmp_tif, rast_tif)
    rm(r)
    rm(r_tmp)
} else {
    terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
}
debug: terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
debug: r <- terra::rast(rast_tif)
debug: d_r <- mutate(tidyr::pivot_longer(sf::st_drop_geometry(sf::st_as_sf(terra::zonal(x = r, 
    z = terra::vect(dplyr::select(sf_zones, dplyr::all_of(fld_zones))), 
    fun = zonal_fun, exact = T, na.rm = T, as.polygons = T))), 
    cols = -dplyr::any_of(fld_zones), names_to = "lyr", values_to = zonal_fun), 
    time = readr::parse_datetime(str_replace(lyr, glue("{var}\\|(.*)"), 
        "\\1")))
debug: if (!is.null(zonal_csv)) write_csv(d_r, zonal_csv)
debug: write_csv(d_r, zonal_csv)
debug: if (!keep_nc) unlink(dir_nc, recursive = T)
debug: unlink(dir_nc, recursive = T)
debug: return(d_r)
Downloading 1 requests, up to 512 time slices each
Called from: extractr::ed_extract(ed, var = v, sf_zones = ply, bbox = bb, 
    mask_tif = F, rast_tif = glue("{dir_out}/{nms}/{yr}.tif"), 
    zonal_fun = "mean", zonal_csv = glue("{dir_out}/{nms}/{yr}.csv"), 
    dir_nc = glue("{dir_out}/{nms}/{yr}_nc"), keep_nc = F, n_max_vals_per_req = 1e+05, 
    time_min = time_min, time_max = time_max, verbose = T)
debug: while (i_req <= n_reqs) {
    i_t_beg <- (i_req - 1) * n_t_per_req + 1
    i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
    t_req <- times_todo[c(i_t_beg, i_t_end)]
    t_req_str <- format_ISO8601(t_req, usetz = "Z")
    if (verbose) 
        message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
    ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
        ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
        0), nc)
    unlink(ncs0)
    nc_retry <- T
    nc_n_try <- 1
    n_max_retries
    while (nc_retry) {
        res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
            url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
                bbox[["xmax"]]), latitude = c(bbox[["ymin"]], 
                bbox[["ymax"]]), time = t_req_str, fmt = "nc", 
            store = rerddap::disk(path = dir_nc)))
        if (inherits(res, "try-error")) {
            err <- attr(res, "condition")
            msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
            nc_n_try <- nc_n_try + 1
            if (nc_n_try > n_max_retries) {
                stop(msg)
            }
            else {
                message(msg, "\nRETRYing...")
                Sys.sleep(1)
            }
        }
        else {
            nc_retry <- F
        }
    }
    i_req <- i_req + 1
}
debug: i_t_beg <- (i_req - 1) * n_t_per_req + 1
debug: i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
debug: t_req <- times_todo[c(i_t_beg, i_t_end)]
debug: t_req_str <- format_ISO8601(t_req, usetz = "Z")
debug: if (verbose) message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
debug: message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
Fetching request 1 of 1 (2021-01-01 to 2021-12-01) ~ 19:45:27 UTC
debug: ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
    0), nc)
debug: unlink(ncs0)
debug: nc_retry <- T
debug: nc_n_try <- 1
debug: n_max_retries
debug: while (nc_retry) {
    res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
        url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
            bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
        time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
    if (inherits(res, "try-error")) {
        err <- attr(res, "condition")
        msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
        nc_n_try <- nc_n_try + 1
        if (nc_n_try > n_max_retries) {
            stop(msg)
        }
        else {
            message(msg, "\nRETRYing...")
            Sys.sleep(1)
        }
    }
    else {
        nc_retry <- F
    }
}
debug: res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
    url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
        bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
    time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
debug: if (inherits(res, "try-error")) {
    err <- attr(res, "condition")
    msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
    nc_n_try <- nc_n_try + 1
    if (nc_n_try > n_max_retries) {
        stop(msg)
    }
    else {
        message(msg, "\nRETRYing...")
        Sys.sleep(1)
    }
} else {
    nc_retry <- F
}
debug: nc_retry <- F
debug: (while) nc_retry
debug: i_req <- i_req + 1
debug: (while) i_req <= n_reqs
debug: ncs <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size > 
    0), nc)
debug: r <- terra::rast(ncs)
debug: stopifnot(all(class(terra::time(r)) %in% c("POSIXct", "POSIXt")))
debug: idx <- dplyr::pull(dplyr::filter(dplyr::arrange(dplyr::tibble(idx = 1:terra::nlyr(r), 
    time = terra::time(r)), time), !duplicated(time)), idx)
debug: r <- terra::subset(r, idx)
debug: stopifnot(terra::crs(r, proj = T) == wgs84)
debug: if (mask_tif) r <- terra::mask(r, sf_zones)
debug: lyrs <- glue("{var}|{terra::time(r)}")
debug: if (length(dims_other) > 0 && !all(length(dims[dims_other]) == 
    1)) stop(glue("Other dimensions not yet supported: {paste(dims_other, collapse = ',')}"))
debug: names(r) <- lyrs
debug: if (!is.null(rast_tif)) {
    if (fs::file_exists(rast_tif)) {
        r_tmp_tif <- tempfile(fileext = ".tif")
        r_tmp <- c(rast(rast_tif), r)
        r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
        terra::writeRaster(r_tmp, r_tmp_tif)
        fs::file_delete(rast_tif)
        fs::file_move(r_tmp_tif, rast_tif)
        rm(r)
        rm(r_tmp)
    }
    else {
        terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
    }
    r <- terra::rast(rast_tif)
}
debug: if (fs::file_exists(rast_tif)) {
    r_tmp_tif <- tempfile(fileext = ".tif")
    r_tmp <- c(rast(rast_tif), r)
    r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
    terra::writeRaster(r_tmp, r_tmp_tif)
    fs::file_delete(rast_tif)
    fs::file_move(r_tmp_tif, rast_tif)
    rm(r)
    rm(r_tmp)
} else {
    terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
}
debug: terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
debug: r <- terra::rast(rast_tif)
debug: d_r <- mutate(tidyr::pivot_longer(sf::st_drop_geometry(sf::st_as_sf(terra::zonal(x = r, 
    z = terra::vect(dplyr::select(sf_zones, dplyr::all_of(fld_zones))), 
    fun = zonal_fun, exact = T, na.rm = T, as.polygons = T))), 
    cols = -dplyr::any_of(fld_zones), names_to = "lyr", values_to = zonal_fun), 
    time = readr::parse_datetime(str_replace(lyr, glue("{var}\\|(.*)"), 
        "\\1")))
debug: if (!is.null(zonal_csv)) write_csv(d_r, zonal_csv)
debug: write_csv(d_r, zonal_csv)
debug: if (!keep_nc) unlink(dir_nc, recursive = T)
debug: unlink(dir_nc, recursive = T)
debug: return(d_r)
Downloading 1 requests, up to 512 time slices each
Called from: extractr::ed_extract(ed, var = v, sf_zones = ply, bbox = bb, 
    mask_tif = F, rast_tif = glue("{dir_out}/{nms}/{yr}.tif"), 
    zonal_fun = "mean", zonal_csv = glue("{dir_out}/{nms}/{yr}.csv"), 
    dir_nc = glue("{dir_out}/{nms}/{yr}_nc"), keep_nc = F, n_max_vals_per_req = 1e+05, 
    time_min = time_min, time_max = time_max, verbose = T)
debug: while (i_req <= n_reqs) {
    i_t_beg <- (i_req - 1) * n_t_per_req + 1
    i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
    t_req <- times_todo[c(i_t_beg, i_t_end)]
    t_req_str <- format_ISO8601(t_req, usetz = "Z")
    if (verbose) 
        message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
    ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
        ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
        0), nc)
    unlink(ncs0)
    nc_retry <- T
    nc_n_try <- 1
    n_max_retries
    while (nc_retry) {
        res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
            url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
                bbox[["xmax"]]), latitude = c(bbox[["ymin"]], 
                bbox[["ymax"]]), time = t_req_str, fmt = "nc", 
            store = rerddap::disk(path = dir_nc)))
        if (inherits(res, "try-error")) {
            err <- attr(res, "condition")
            msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
            nc_n_try <- nc_n_try + 1
            if (nc_n_try > n_max_retries) {
                stop(msg)
            }
            else {
                message(msg, "\nRETRYing...")
                Sys.sleep(1)
            }
        }
        else {
            nc_retry <- F
        }
    }
    i_req <- i_req + 1
}
debug: i_t_beg <- (i_req - 1) * n_t_per_req + 1
debug: i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
debug: t_req <- times_todo[c(i_t_beg, i_t_end)]
debug: t_req_str <- format_ISO8601(t_req, usetz = "Z")
debug: if (verbose) message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
debug: message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
Fetching request 1 of 1 (2022-01-01 to 2022-12-01) ~ 19:45:29 UTC
debug: ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
    0), nc)
debug: unlink(ncs0)
debug: nc_retry <- T
debug: nc_n_try <- 1
debug: n_max_retries
debug: while (nc_retry) {
    res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
        url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
            bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
        time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
    if (inherits(res, "try-error")) {
        err <- attr(res, "condition")
        msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
        nc_n_try <- nc_n_try + 1
        if (nc_n_try > n_max_retries) {
            stop(msg)
        }
        else {
            message(msg, "\nRETRYing...")
            Sys.sleep(1)
        }
    }
    else {
        nc_retry <- F
    }
}
debug: res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
    url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
        bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
    time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
debug: if (inherits(res, "try-error")) {
    err <- attr(res, "condition")
    msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
    nc_n_try <- nc_n_try + 1
    if (nc_n_try > n_max_retries) {
        stop(msg)
    }
    else {
        message(msg, "\nRETRYing...")
        Sys.sleep(1)
    }
} else {
    nc_retry <- F
}
debug: nc_retry <- F
debug: (while) nc_retry
debug: i_req <- i_req + 1
debug: (while) i_req <= n_reqs
debug: ncs <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size > 
    0), nc)
debug: r <- terra::rast(ncs)
debug: stopifnot(all(class(terra::time(r)) %in% c("POSIXct", "POSIXt")))
debug: idx <- dplyr::pull(dplyr::filter(dplyr::arrange(dplyr::tibble(idx = 1:terra::nlyr(r), 
    time = terra::time(r)), time), !duplicated(time)), idx)
debug: r <- terra::subset(r, idx)
debug: stopifnot(terra::crs(r, proj = T) == wgs84)
debug: if (mask_tif) r <- terra::mask(r, sf_zones)
debug: lyrs <- glue("{var}|{terra::time(r)}")
debug: if (length(dims_other) > 0 && !all(length(dims[dims_other]) == 
    1)) stop(glue("Other dimensions not yet supported: {paste(dims_other, collapse = ',')}"))
debug: names(r) <- lyrs
debug: if (!is.null(rast_tif)) {
    if (fs::file_exists(rast_tif)) {
        r_tmp_tif <- tempfile(fileext = ".tif")
        r_tmp <- c(rast(rast_tif), r)
        r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
        terra::writeRaster(r_tmp, r_tmp_tif)
        fs::file_delete(rast_tif)
        fs::file_move(r_tmp_tif, rast_tif)
        rm(r)
        rm(r_tmp)
    }
    else {
        terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
    }
    r <- terra::rast(rast_tif)
}
debug: if (fs::file_exists(rast_tif)) {
    r_tmp_tif <- tempfile(fileext = ".tif")
    r_tmp <- c(rast(rast_tif), r)
    r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
    terra::writeRaster(r_tmp, r_tmp_tif)
    fs::file_delete(rast_tif)
    fs::file_move(r_tmp_tif, rast_tif)
    rm(r)
    rm(r_tmp)
} else {
    terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
}
debug: terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
debug: r <- terra::rast(rast_tif)
debug: d_r <- mutate(tidyr::pivot_longer(sf::st_drop_geometry(sf::st_as_sf(terra::zonal(x = r, 
    z = terra::vect(dplyr::select(sf_zones, dplyr::all_of(fld_zones))), 
    fun = zonal_fun, exact = T, na.rm = T, as.polygons = T))), 
    cols = -dplyr::any_of(fld_zones), names_to = "lyr", values_to = zonal_fun), 
    time = readr::parse_datetime(str_replace(lyr, glue("{var}\\|(.*)"), 
        "\\1")))
debug: if (!is.null(zonal_csv)) write_csv(d_r, zonal_csv)
debug: write_csv(d_r, zonal_csv)
debug: if (!keep_nc) unlink(dir_nc, recursive = T)
debug: unlink(dir_nc, recursive = T)
debug: return(d_r)
Downloading 1 requests, up to 512 time slices each
Called from: extractr::ed_extract(ed, var = v, sf_zones = ply, bbox = bb, 
    mask_tif = F, rast_tif = glue("{dir_out}/{nms}/{yr}.tif"), 
    zonal_fun = "mean", zonal_csv = glue("{dir_out}/{nms}/{yr}.csv"), 
    dir_nc = glue("{dir_out}/{nms}/{yr}_nc"), keep_nc = F, n_max_vals_per_req = 1e+05, 
    time_min = time_min, time_max = time_max, verbose = T)
debug: while (i_req <= n_reqs) {
    i_t_beg <- (i_req - 1) * n_t_per_req + 1
    i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
    t_req <- times_todo[c(i_t_beg, i_t_end)]
    t_req_str <- format_ISO8601(t_req, usetz = "Z")
    if (verbose) 
        message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
    ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
        ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
        0), nc)
    unlink(ncs0)
    nc_retry <- T
    nc_n_try <- 1
    n_max_retries
    while (nc_retry) {
        res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
            url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
                bbox[["xmax"]]), latitude = c(bbox[["ymin"]], 
                bbox[["ymax"]]), time = t_req_str, fmt = "nc", 
            store = rerddap::disk(path = dir_nc)))
        if (inherits(res, "try-error")) {
            err <- attr(res, "condition")
            msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
            nc_n_try <- nc_n_try + 1
            if (nc_n_try > n_max_retries) {
                stop(msg)
            }
            else {
                message(msg, "\nRETRYing...")
                Sys.sleep(1)
            }
        }
        else {
            nc_retry <- F
        }
    }
    i_req <- i_req + 1
}
debug: i_t_beg <- (i_req - 1) * n_t_per_req + 1
debug: i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
debug: t_req <- times_todo[c(i_t_beg, i_t_end)]
debug: t_req_str <- format_ISO8601(t_req, usetz = "Z")
debug: if (verbose) message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
debug: message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
Fetching request 1 of 1 (2023-01-01 to 2023-12-01) ~ 19:45:30 UTC
debug: ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
    0), nc)
debug: unlink(ncs0)
debug: nc_retry <- T
debug: nc_n_try <- 1
debug: n_max_retries
debug: while (nc_retry) {
    res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
        url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
            bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
        time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
    if (inherits(res, "try-error")) {
        err <- attr(res, "condition")
        msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
        nc_n_try <- nc_n_try + 1
        if (nc_n_try > n_max_retries) {
            stop(msg)
        }
        else {
            message(msg, "\nRETRYing...")
            Sys.sleep(1)
        }
    }
    else {
        nc_retry <- F
    }
}
debug: res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
    url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
        bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
    time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
debug: if (inherits(res, "try-error")) {
    err <- attr(res, "condition")
    msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
    nc_n_try <- nc_n_try + 1
    if (nc_n_try > n_max_retries) {
        stop(msg)
    }
    else {
        message(msg, "\nRETRYing...")
        Sys.sleep(1)
    }
} else {
    nc_retry <- F
}
debug: nc_retry <- F
debug: (while) nc_retry
debug: i_req <- i_req + 1
debug: (while) i_req <= n_reqs
debug: ncs <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size > 
    0), nc)
debug: r <- terra::rast(ncs)
debug: stopifnot(all(class(terra::time(r)) %in% c("POSIXct", "POSIXt")))
debug: idx <- dplyr::pull(dplyr::filter(dplyr::arrange(dplyr::tibble(idx = 1:terra::nlyr(r), 
    time = terra::time(r)), time), !duplicated(time)), idx)
debug: r <- terra::subset(r, idx)
debug: stopifnot(terra::crs(r, proj = T) == wgs84)
debug: if (mask_tif) r <- terra::mask(r, sf_zones)
debug: lyrs <- glue("{var}|{terra::time(r)}")
debug: if (length(dims_other) > 0 && !all(length(dims[dims_other]) == 
    1)) stop(glue("Other dimensions not yet supported: {paste(dims_other, collapse = ',')}"))
debug: names(r) <- lyrs
debug: if (!is.null(rast_tif)) {
    if (fs::file_exists(rast_tif)) {
        r_tmp_tif <- tempfile(fileext = ".tif")
        r_tmp <- c(rast(rast_tif), r)
        r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
        terra::writeRaster(r_tmp, r_tmp_tif)
        fs::file_delete(rast_tif)
        fs::file_move(r_tmp_tif, rast_tif)
        rm(r)
        rm(r_tmp)
    }
    else {
        terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
    }
    r <- terra::rast(rast_tif)
}
debug: if (fs::file_exists(rast_tif)) {
    r_tmp_tif <- tempfile(fileext = ".tif")
    r_tmp <- c(rast(rast_tif), r)
    r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
    terra::writeRaster(r_tmp, r_tmp_tif)
    fs::file_delete(rast_tif)
    fs::file_move(r_tmp_tif, rast_tif)
    rm(r)
    rm(r_tmp)
} else {
    terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
}
debug: terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
debug: r <- terra::rast(rast_tif)
debug: d_r <- mutate(tidyr::pivot_longer(sf::st_drop_geometry(sf::st_as_sf(terra::zonal(x = r, 
    z = terra::vect(dplyr::select(sf_zones, dplyr::all_of(fld_zones))), 
    fun = zonal_fun, exact = T, na.rm = T, as.polygons = T))), 
    cols = -dplyr::any_of(fld_zones), names_to = "lyr", values_to = zonal_fun), 
    time = readr::parse_datetime(str_replace(lyr, glue("{var}\\|(.*)"), 
        "\\1")))
debug: if (!is.null(zonal_csv)) write_csv(d_r, zonal_csv)
debug: write_csv(d_r, zonal_csv)
debug: if (!keep_nc) unlink(dir_nc, recursive = T)
debug: unlink(dir_nc, recursive = T)
debug: return(d_r)
Downloading 1 requests, up to 512 time slices each
Called from: extractr::ed_extract(ed, var = v, sf_zones = ply, bbox = bb, 
    mask_tif = F, rast_tif = glue("{dir_out}/{nms}/{yr}.tif"), 
    zonal_fun = "mean", zonal_csv = glue("{dir_out}/{nms}/{yr}.csv"), 
    dir_nc = glue("{dir_out}/{nms}/{yr}_nc"), keep_nc = F, n_max_vals_per_req = 1e+05, 
    time_min = time_min, time_max = time_max, verbose = T)
debug: while (i_req <= n_reqs) {
    i_t_beg <- (i_req - 1) * n_t_per_req + 1
    i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
    t_req <- times_todo[c(i_t_beg, i_t_end)]
    t_req_str <- format_ISO8601(t_req, usetz = "Z")
    if (verbose) 
        message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
    ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
        ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
        0), nc)
    unlink(ncs0)
    nc_retry <- T
    nc_n_try <- 1
    n_max_retries
    while (nc_retry) {
        res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
            url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
                bbox[["xmax"]]), latitude = c(bbox[["ymin"]], 
                bbox[["ymax"]]), time = t_req_str, fmt = "nc", 
            store = rerddap::disk(path = dir_nc)))
        if (inherits(res, "try-error")) {
            err <- attr(res, "condition")
            msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
            nc_n_try <- nc_n_try + 1
            if (nc_n_try > n_max_retries) {
                stop(msg)
            }
            else {
                message(msg, "\nRETRYing...")
                Sys.sleep(1)
            }
        }
        else {
            nc_retry <- F
        }
    }
    i_req <- i_req + 1
}
debug: i_t_beg <- (i_req - 1) * n_t_per_req + 1
debug: i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
debug: t_req <- times_todo[c(i_t_beg, i_t_end)]
debug: t_req_str <- format_ISO8601(t_req, usetz = "Z")
debug: if (verbose) message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
debug: message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
Fetching request 1 of 1 (2024-01-01 to 2024-12-01) ~ 19:45:32 UTC
debug: ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
    0), nc)
debug: unlink(ncs0)
debug: nc_retry <- T
debug: nc_n_try <- 1
debug: n_max_retries
debug: while (nc_retry) {
    res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
        url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
            bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
        time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
    if (inherits(res, "try-error")) {
        err <- attr(res, "condition")
        msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
        nc_n_try <- nc_n_try + 1
        if (nc_n_try > n_max_retries) {
            stop(msg)
        }
        else {
            message(msg, "\nRETRYing...")
            Sys.sleep(1)
        }
    }
    else {
        nc_retry <- F
    }
}
debug: res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
    url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
        bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
    time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
debug: if (inherits(res, "try-error")) {
    err <- attr(res, "condition")
    msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
    nc_n_try <- nc_n_try + 1
    if (nc_n_try > n_max_retries) {
        stop(msg)
    }
    else {
        message(msg, "\nRETRYing...")
        Sys.sleep(1)
    }
} else {
    nc_retry <- F
}
debug: nc_retry <- F
debug: (while) nc_retry
debug: i_req <- i_req + 1
debug: (while) i_req <= n_reqs
debug: ncs <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size > 
    0), nc)
debug: r <- terra::rast(ncs)
debug: stopifnot(all(class(terra::time(r)) %in% c("POSIXct", "POSIXt")))
debug: idx <- dplyr::pull(dplyr::filter(dplyr::arrange(dplyr::tibble(idx = 1:terra::nlyr(r), 
    time = terra::time(r)), time), !duplicated(time)), idx)
debug: r <- terra::subset(r, idx)
debug: stopifnot(terra::crs(r, proj = T) == wgs84)
debug: if (mask_tif) r <- terra::mask(r, sf_zones)
debug: lyrs <- glue("{var}|{terra::time(r)}")
debug: if (length(dims_other) > 0 && !all(length(dims[dims_other]) == 
    1)) stop(glue("Other dimensions not yet supported: {paste(dims_other, collapse = ',')}"))
debug: names(r) <- lyrs
debug: if (!is.null(rast_tif)) {
    if (fs::file_exists(rast_tif)) {
        r_tmp_tif <- tempfile(fileext = ".tif")
        r_tmp <- c(rast(rast_tif), r)
        r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
        terra::writeRaster(r_tmp, r_tmp_tif)
        fs::file_delete(rast_tif)
        fs::file_move(r_tmp_tif, rast_tif)
        rm(r)
        rm(r_tmp)
    }
    else {
        terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
    }
    r <- terra::rast(rast_tif)
}
debug: if (fs::file_exists(rast_tif)) {
    r_tmp_tif <- tempfile(fileext = ".tif")
    r_tmp <- c(rast(rast_tif), r)
    r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
    terra::writeRaster(r_tmp, r_tmp_tif)
    fs::file_delete(rast_tif)
    fs::file_move(r_tmp_tif, rast_tif)
    rm(r)
    rm(r_tmp)
} else {
    terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
}
debug: terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
debug: r <- terra::rast(rast_tif)
debug: d_r <- mutate(tidyr::pivot_longer(sf::st_drop_geometry(sf::st_as_sf(terra::zonal(x = r, 
    z = terra::vect(dplyr::select(sf_zones, dplyr::all_of(fld_zones))), 
    fun = zonal_fun, exact = T, na.rm = T, as.polygons = T))), 
    cols = -dplyr::any_of(fld_zones), names_to = "lyr", values_to = zonal_fun), 
    time = readr::parse_datetime(str_replace(lyr, glue("{var}\\|(.*)"), 
        "\\1")))
debug: if (!is.null(zonal_csv)) write_csv(d_r, zonal_csv)
debug: write_csv(d_r, zonal_csv)
debug: if (!keep_nc) unlink(dir_nc, recursive = T)
debug: unlink(dir_nc, recursive = T)
debug: return(d_r)
Downloading 1 requests, up to 512 time slices each
Called from: extractr::ed_extract(ed, var = v, sf_zones = ply, bbox = bb, 
    mask_tif = F, rast_tif = glue("{dir_out}/{nms}/{yr}.tif"), 
    zonal_fun = "mean", zonal_csv = glue("{dir_out}/{nms}/{yr}.csv"), 
    dir_nc = glue("{dir_out}/{nms}/{yr}_nc"), keep_nc = F, n_max_vals_per_req = 1e+05, 
    time_min = time_min, time_max = time_max, verbose = T)
debug: while (i_req <= n_reqs) {
    i_t_beg <- (i_req - 1) * n_t_per_req + 1
    i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
    t_req <- times_todo[c(i_t_beg, i_t_end)]
    t_req_str <- format_ISO8601(t_req, usetz = "Z")
    if (verbose) 
        message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
    ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
        ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
        0), nc)
    unlink(ncs0)
    nc_retry <- T
    nc_n_try <- 1
    n_max_retries
    while (nc_retry) {
        res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
            url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
                bbox[["xmax"]]), latitude = c(bbox[["ymin"]], 
                bbox[["ymax"]]), time = t_req_str, fmt = "nc", 
            store = rerddap::disk(path = dir_nc)))
        if (inherits(res, "try-error")) {
            err <- attr(res, "condition")
            msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
            nc_n_try <- nc_n_try + 1
            if (nc_n_try > n_max_retries) {
                stop(msg)
            }
            else {
                message(msg, "\nRETRYing...")
                Sys.sleep(1)
            }
        }
        else {
            nc_retry <- F
        }
    }
    i_req <- i_req + 1
}
debug: i_t_beg <- (i_req - 1) * n_t_per_req + 1
debug: i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
debug: t_req <- times_todo[c(i_t_beg, i_t_end)]
debug: t_req_str <- format_ISO8601(t_req, usetz = "Z")
debug: if (verbose) message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
debug: message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
Fetching request 1 of 1 (2025-01-01 to 2025-07-01) ~ 19:45:34 UTC
debug: ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
    0), nc)
debug: unlink(ncs0)
debug: nc_retry <- T
debug: nc_n_try <- 1
debug: n_max_retries
debug: while (nc_retry) {
    res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
        url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
            bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
        time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
    if (inherits(res, "try-error")) {
        err <- attr(res, "condition")
        msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
        nc_n_try <- nc_n_try + 1
        if (nc_n_try > n_max_retries) {
            stop(msg)
        }
        else {
            message(msg, "\nRETRYing...")
            Sys.sleep(1)
        }
    }
    else {
        nc_retry <- F
    }
}
debug: res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
    url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
        bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
    time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
debug: if (inherits(res, "try-error")) {
    err <- attr(res, "condition")
    msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
    nc_n_try <- nc_n_try + 1
    if (nc_n_try > n_max_retries) {
        stop(msg)
    }
    else {
        message(msg, "\nRETRYing...")
        Sys.sleep(1)
    }
} else {
    nc_retry <- F
}
debug: nc_retry <- F
debug: (while) nc_retry
debug: i_req <- i_req + 1
debug: (while) i_req <= n_reqs
debug: ncs <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size > 
    0), nc)
debug: r <- terra::rast(ncs)
debug: stopifnot(all(class(terra::time(r)) %in% c("POSIXct", "POSIXt")))
debug: idx <- dplyr::pull(dplyr::filter(dplyr::arrange(dplyr::tibble(idx = 1:terra::nlyr(r), 
    time = terra::time(r)), time), !duplicated(time)), idx)
debug: r <- terra::subset(r, idx)
debug: stopifnot(terra::crs(r, proj = T) == wgs84)
debug: if (mask_tif) r <- terra::mask(r, sf_zones)
debug: lyrs <- glue("{var}|{terra::time(r)}")
debug: if (length(dims_other) > 0 && !all(length(dims[dims_other]) == 
    1)) stop(glue("Other dimensions not yet supported: {paste(dims_other, collapse = ',')}"))
debug: names(r) <- lyrs
debug: if (!is.null(rast_tif)) {
    if (fs::file_exists(rast_tif)) {
        r_tmp_tif <- tempfile(fileext = ".tif")
        r_tmp <- c(rast(rast_tif), r)
        r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
        terra::writeRaster(r_tmp, r_tmp_tif)
        fs::file_delete(rast_tif)
        fs::file_move(r_tmp_tif, rast_tif)
        rm(r)
        rm(r_tmp)
    }
    else {
        terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
    }
    r <- terra::rast(rast_tif)
}
debug: if (fs::file_exists(rast_tif)) {
    r_tmp_tif <- tempfile(fileext = ".tif")
    r_tmp <- c(rast(rast_tif), r)
    r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
    terra::writeRaster(r_tmp, r_tmp_tif)
    fs::file_delete(rast_tif)
    fs::file_move(r_tmp_tif, rast_tif)
    rm(r)
    rm(r_tmp)
} else {
    terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
}
debug: terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
debug: r <- terra::rast(rast_tif)
debug: d_r <- mutate(tidyr::pivot_longer(sf::st_drop_geometry(sf::st_as_sf(terra::zonal(x = r, 
    z = terra::vect(dplyr::select(sf_zones, dplyr::all_of(fld_zones))), 
    fun = zonal_fun, exact = T, na.rm = T, as.polygons = T))), 
    cols = -dplyr::any_of(fld_zones), names_to = "lyr", values_to = zonal_fun), 
    time = readr::parse_datetime(str_replace(lyr, glue("{var}\\|(.*)"), 
        "\\1")))
debug: if (!is.null(zonal_csv)) write_csv(d_r, zonal_csv)
debug: write_csv(d_r, zonal_csv)
debug: if (!keep_nc) unlink(dir_nc, recursive = T)
debug: unlink(dir_nc, recursive = T)
debug: return(d_r)
Downloading 1 requests, up to 166 time slices each
Called from: extractr::ed_extract(ed, var = v, sf_zones = ply, bbox = bb, 
    mask_tif = F, rast_tif = glue("{dir_out}/{nms}/{yr}.tif"), 
    zonal_fun = "mean", zonal_csv = glue("{dir_out}/{nms}/{yr}.csv"), 
    dir_nc = glue("{dir_out}/{nms}/{yr}_nc"), keep_nc = F, n_max_vals_per_req = 1e+05, 
    time_min = time_min, time_max = time_max, verbose = T)
debug: while (i_req <= n_reqs) {
    i_t_beg <- (i_req - 1) * n_t_per_req + 1
    i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
    t_req <- times_todo[c(i_t_beg, i_t_end)]
    t_req_str <- format_ISO8601(t_req, usetz = "Z")
    if (verbose) 
        message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
    ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
        ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
        0), nc)
    unlink(ncs0)
    nc_retry <- T
    nc_n_try <- 1
    n_max_retries
    while (nc_retry) {
        res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
            url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
                bbox[["xmax"]]), latitude = c(bbox[["ymin"]], 
                bbox[["ymax"]]), time = t_req_str, fmt = "nc", 
            store = rerddap::disk(path = dir_nc)))
        if (inherits(res, "try-error")) {
            err <- attr(res, "condition")
            msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
            nc_n_try <- nc_n_try + 1
            if (nc_n_try > n_max_retries) {
                stop(msg)
            }
            else {
                message(msg, "\nRETRYing...")
                Sys.sleep(1)
            }
        }
        else {
            nc_retry <- F
        }
    }
    i_req <- i_req + 1
}
debug: i_t_beg <- (i_req - 1) * n_t_per_req + 1
debug: i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
debug: t_req <- times_todo[c(i_t_beg, i_t_end)]
debug: t_req_str <- format_ISO8601(t_req, usetz = "Z")
debug: if (verbose) message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
debug: message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
Fetching request 1 of 1 (1998-01-01 to 1998-12-01) ~ 19:45:36 UTC
debug: ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
    0), nc)
debug: unlink(ncs0)
debug: nc_retry <- T
debug: nc_n_try <- 1
debug: n_max_retries
debug: while (nc_retry) {
    res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
        url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
            bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
        time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
    if (inherits(res, "try-error")) {
        err <- attr(res, "condition")
        msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
        nc_n_try <- nc_n_try + 1
        if (nc_n_try > n_max_retries) {
            stop(msg)
        }
        else {
            message(msg, "\nRETRYing...")
            Sys.sleep(1)
        }
    }
    else {
        nc_retry <- F
    }
}
debug: res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
    url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
        bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
    time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
debug: if (inherits(res, "try-error")) {
    err <- attr(res, "condition")
    msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
    nc_n_try <- nc_n_try + 1
    if (nc_n_try > n_max_retries) {
        stop(msg)
    }
    else {
        message(msg, "\nRETRYing...")
        Sys.sleep(1)
    }
} else {
    nc_retry <- F
}
debug: nc_retry <- F
debug: (while) nc_retry
debug: i_req <- i_req + 1
debug: (while) i_req <= n_reqs
debug: ncs <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size > 
    0), nc)
debug: r <- terra::rast(ncs)
debug: stopifnot(all(class(terra::time(r)) %in% c("POSIXct", "POSIXt")))
debug: idx <- dplyr::pull(dplyr::filter(dplyr::arrange(dplyr::tibble(idx = 1:terra::nlyr(r), 
    time = terra::time(r)), time), !duplicated(time)), idx)
debug: r <- terra::subset(r, idx)
debug: stopifnot(terra::crs(r, proj = T) == wgs84)
debug: if (mask_tif) r <- terra::mask(r, sf_zones)
debug: lyrs <- glue("{var}|{terra::time(r)}")
debug: if (length(dims_other) > 0 && !all(length(dims[dims_other]) == 
    1)) stop(glue("Other dimensions not yet supported: {paste(dims_other, collapse = ',')}"))
debug: names(r) <- lyrs
debug: if (!is.null(rast_tif)) {
    if (fs::file_exists(rast_tif)) {
        r_tmp_tif <- tempfile(fileext = ".tif")
        r_tmp <- c(rast(rast_tif), r)
        r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
        terra::writeRaster(r_tmp, r_tmp_tif)
        fs::file_delete(rast_tif)
        fs::file_move(r_tmp_tif, rast_tif)
        rm(r)
        rm(r_tmp)
    }
    else {
        terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
    }
    r <- terra::rast(rast_tif)
}
debug: if (fs::file_exists(rast_tif)) {
    r_tmp_tif <- tempfile(fileext = ".tif")
    r_tmp <- c(rast(rast_tif), r)
    r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
    terra::writeRaster(r_tmp, r_tmp_tif)
    fs::file_delete(rast_tif)
    fs::file_move(r_tmp_tif, rast_tif)
    rm(r)
    rm(r_tmp)
} else {
    terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
}
debug: terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
debug: r <- terra::rast(rast_tif)
debug: d_r <- mutate(tidyr::pivot_longer(sf::st_drop_geometry(sf::st_as_sf(terra::zonal(x = r, 
    z = terra::vect(dplyr::select(sf_zones, dplyr::all_of(fld_zones))), 
    fun = zonal_fun, exact = T, na.rm = T, as.polygons = T))), 
    cols = -dplyr::any_of(fld_zones), names_to = "lyr", values_to = zonal_fun), 
    time = readr::parse_datetime(str_replace(lyr, glue("{var}\\|(.*)"), 
        "\\1")))
debug: if (!is.null(zonal_csv)) write_csv(d_r, zonal_csv)
debug: write_csv(d_r, zonal_csv)
debug: if (!keep_nc) unlink(dir_nc, recursive = T)
debug: unlink(dir_nc, recursive = T)
debug: return(d_r)
Downloading 1 requests, up to 166 time slices each
Called from: extractr::ed_extract(ed, var = v, sf_zones = ply, bbox = bb, 
    mask_tif = F, rast_tif = glue("{dir_out}/{nms}/{yr}.tif"), 
    zonal_fun = "mean", zonal_csv = glue("{dir_out}/{nms}/{yr}.csv"), 
    dir_nc = glue("{dir_out}/{nms}/{yr}_nc"), keep_nc = F, n_max_vals_per_req = 1e+05, 
    time_min = time_min, time_max = time_max, verbose = T)
debug: while (i_req <= n_reqs) {
    i_t_beg <- (i_req - 1) * n_t_per_req + 1
    i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
    t_req <- times_todo[c(i_t_beg, i_t_end)]
    t_req_str <- format_ISO8601(t_req, usetz = "Z")
    if (verbose) 
        message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
    ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
        ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
        0), nc)
    unlink(ncs0)
    nc_retry <- T
    nc_n_try <- 1
    n_max_retries
    while (nc_retry) {
        res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
            url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
                bbox[["xmax"]]), latitude = c(bbox[["ymin"]], 
                bbox[["ymax"]]), time = t_req_str, fmt = "nc", 
            store = rerddap::disk(path = dir_nc)))
        if (inherits(res, "try-error")) {
            err <- attr(res, "condition")
            msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
            nc_n_try <- nc_n_try + 1
            if (nc_n_try > n_max_retries) {
                stop(msg)
            }
            else {
                message(msg, "\nRETRYing...")
                Sys.sleep(1)
            }
        }
        else {
            nc_retry <- F
        }
    }
    i_req <- i_req + 1
}
debug: i_t_beg <- (i_req - 1) * n_t_per_req + 1
debug: i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
debug: t_req <- times_todo[c(i_t_beg, i_t_end)]
debug: t_req_str <- format_ISO8601(t_req, usetz = "Z")
debug: if (verbose) message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
debug: message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
Fetching request 1 of 1 (1999-01-01 to 1999-12-01) ~ 19:45:40 UTC
debug: ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
    0), nc)
debug: unlink(ncs0)
debug: nc_retry <- T
debug: nc_n_try <- 1
debug: n_max_retries
debug: while (nc_retry) {
    res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
        url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
            bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
        time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
    if (inherits(res, "try-error")) {
        err <- attr(res, "condition")
        msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
        nc_n_try <- nc_n_try + 1
        if (nc_n_try > n_max_retries) {
            stop(msg)
        }
        else {
            message(msg, "\nRETRYing...")
            Sys.sleep(1)
        }
    }
    else {
        nc_retry <- F
    }
}
debug: res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
    url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
        bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
    time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
debug: if (inherits(res, "try-error")) {
    err <- attr(res, "condition")
    msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
    nc_n_try <- nc_n_try + 1
    if (nc_n_try > n_max_retries) {
        stop(msg)
    }
    else {
        message(msg, "\nRETRYing...")
        Sys.sleep(1)
    }
} else {
    nc_retry <- F
}
debug: nc_retry <- F
debug: (while) nc_retry
debug: i_req <- i_req + 1
debug: (while) i_req <= n_reqs
debug: ncs <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size > 
    0), nc)
debug: r <- terra::rast(ncs)
debug: stopifnot(all(class(terra::time(r)) %in% c("POSIXct", "POSIXt")))
debug: idx <- dplyr::pull(dplyr::filter(dplyr::arrange(dplyr::tibble(idx = 1:terra::nlyr(r), 
    time = terra::time(r)), time), !duplicated(time)), idx)
debug: r <- terra::subset(r, idx)
debug: stopifnot(terra::crs(r, proj = T) == wgs84)
debug: if (mask_tif) r <- terra::mask(r, sf_zones)
debug: lyrs <- glue("{var}|{terra::time(r)}")
debug: if (length(dims_other) > 0 && !all(length(dims[dims_other]) == 
    1)) stop(glue("Other dimensions not yet supported: {paste(dims_other, collapse = ',')}"))
debug: names(r) <- lyrs
debug: if (!is.null(rast_tif)) {
    if (fs::file_exists(rast_tif)) {
        r_tmp_tif <- tempfile(fileext = ".tif")
        r_tmp <- c(rast(rast_tif), r)
        r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
        terra::writeRaster(r_tmp, r_tmp_tif)
        fs::file_delete(rast_tif)
        fs::file_move(r_tmp_tif, rast_tif)
        rm(r)
        rm(r_tmp)
    }
    else {
        terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
    }
    r <- terra::rast(rast_tif)
}
debug: if (fs::file_exists(rast_tif)) {
    r_tmp_tif <- tempfile(fileext = ".tif")
    r_tmp <- c(rast(rast_tif), r)
    r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
    terra::writeRaster(r_tmp, r_tmp_tif)
    fs::file_delete(rast_tif)
    fs::file_move(r_tmp_tif, rast_tif)
    rm(r)
    rm(r_tmp)
} else {
    terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
}
debug: terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
debug: r <- terra::rast(rast_tif)
debug: d_r <- mutate(tidyr::pivot_longer(sf::st_drop_geometry(sf::st_as_sf(terra::zonal(x = r, 
    z = terra::vect(dplyr::select(sf_zones, dplyr::all_of(fld_zones))), 
    fun = zonal_fun, exact = T, na.rm = T, as.polygons = T))), 
    cols = -dplyr::any_of(fld_zones), names_to = "lyr", values_to = zonal_fun), 
    time = readr::parse_datetime(str_replace(lyr, glue("{var}\\|(.*)"), 
        "\\1")))
debug: if (!is.null(zonal_csv)) write_csv(d_r, zonal_csv)
debug: write_csv(d_r, zonal_csv)
debug: if (!keep_nc) unlink(dir_nc, recursive = T)
debug: unlink(dir_nc, recursive = T)
debug: return(d_r)
Downloading 1 requests, up to 166 time slices each
Called from: extractr::ed_extract(ed, var = v, sf_zones = ply, bbox = bb, 
    mask_tif = F, rast_tif = glue("{dir_out}/{nms}/{yr}.tif"), 
    zonal_fun = "mean", zonal_csv = glue("{dir_out}/{nms}/{yr}.csv"), 
    dir_nc = glue("{dir_out}/{nms}/{yr}_nc"), keep_nc = F, n_max_vals_per_req = 1e+05, 
    time_min = time_min, time_max = time_max, verbose = T)
debug: while (i_req <= n_reqs) {
    i_t_beg <- (i_req - 1) * n_t_per_req + 1
    i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
    t_req <- times_todo[c(i_t_beg, i_t_end)]
    t_req_str <- format_ISO8601(t_req, usetz = "Z")
    if (verbose) 
        message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
    ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
        ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
        0), nc)
    unlink(ncs0)
    nc_retry <- T
    nc_n_try <- 1
    n_max_retries
    while (nc_retry) {
        res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
            url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
                bbox[["xmax"]]), latitude = c(bbox[["ymin"]], 
                bbox[["ymax"]]), time = t_req_str, fmt = "nc", 
            store = rerddap::disk(path = dir_nc)))
        if (inherits(res, "try-error")) {
            err <- attr(res, "condition")
            msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
            nc_n_try <- nc_n_try + 1
            if (nc_n_try > n_max_retries) {
                stop(msg)
            }
            else {
                message(msg, "\nRETRYing...")
                Sys.sleep(1)
            }
        }
        else {
            nc_retry <- F
        }
    }
    i_req <- i_req + 1
}
debug: i_t_beg <- (i_req - 1) * n_t_per_req + 1
debug: i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
debug: t_req <- times_todo[c(i_t_beg, i_t_end)]
debug: t_req_str <- format_ISO8601(t_req, usetz = "Z")
debug: if (verbose) message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
debug: message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
Fetching request 1 of 1 (2000-01-01 to 2000-12-01) ~ 19:45:44 UTC
debug: ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
    0), nc)
debug: unlink(ncs0)
debug: nc_retry <- T
debug: nc_n_try <- 1
debug: n_max_retries
debug: while (nc_retry) {
    res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
        url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
            bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
        time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
    if (inherits(res, "try-error")) {
        err <- attr(res, "condition")
        msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
        nc_n_try <- nc_n_try + 1
        if (nc_n_try > n_max_retries) {
            stop(msg)
        }
        else {
            message(msg, "\nRETRYing...")
            Sys.sleep(1)
        }
    }
    else {
        nc_retry <- F
    }
}
debug: res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
    url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
        bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
    time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
debug: if (inherits(res, "try-error")) {
    err <- attr(res, "condition")
    msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
    nc_n_try <- nc_n_try + 1
    if (nc_n_try > n_max_retries) {
        stop(msg)
    }
    else {
        message(msg, "\nRETRYing...")
        Sys.sleep(1)
    }
} else {
    nc_retry <- F
}
debug: nc_retry <- F
debug: (while) nc_retry
debug: i_req <- i_req + 1
debug: (while) i_req <= n_reqs
debug: ncs <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size > 
    0), nc)
debug: r <- terra::rast(ncs)
debug: stopifnot(all(class(terra::time(r)) %in% c("POSIXct", "POSIXt")))
debug: idx <- dplyr::pull(dplyr::filter(dplyr::arrange(dplyr::tibble(idx = 1:terra::nlyr(r), 
    time = terra::time(r)), time), !duplicated(time)), idx)
debug: r <- terra::subset(r, idx)
debug: stopifnot(terra::crs(r, proj = T) == wgs84)
debug: if (mask_tif) r <- terra::mask(r, sf_zones)
debug: lyrs <- glue("{var}|{terra::time(r)}")
debug: if (length(dims_other) > 0 && !all(length(dims[dims_other]) == 
    1)) stop(glue("Other dimensions not yet supported: {paste(dims_other, collapse = ',')}"))
debug: names(r) <- lyrs
debug: if (!is.null(rast_tif)) {
    if (fs::file_exists(rast_tif)) {
        r_tmp_tif <- tempfile(fileext = ".tif")
        r_tmp <- c(rast(rast_tif), r)
        r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
        terra::writeRaster(r_tmp, r_tmp_tif)
        fs::file_delete(rast_tif)
        fs::file_move(r_tmp_tif, rast_tif)
        rm(r)
        rm(r_tmp)
    }
    else {
        terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
    }
    r <- terra::rast(rast_tif)
}
debug: if (fs::file_exists(rast_tif)) {
    r_tmp_tif <- tempfile(fileext = ".tif")
    r_tmp <- c(rast(rast_tif), r)
    r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
    terra::writeRaster(r_tmp, r_tmp_tif)
    fs::file_delete(rast_tif)
    fs::file_move(r_tmp_tif, rast_tif)
    rm(r)
    rm(r_tmp)
} else {
    terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
}
debug: terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
debug: r <- terra::rast(rast_tif)
debug: d_r <- mutate(tidyr::pivot_longer(sf::st_drop_geometry(sf::st_as_sf(terra::zonal(x = r, 
    z = terra::vect(dplyr::select(sf_zones, dplyr::all_of(fld_zones))), 
    fun = zonal_fun, exact = T, na.rm = T, as.polygons = T))), 
    cols = -dplyr::any_of(fld_zones), names_to = "lyr", values_to = zonal_fun), 
    time = readr::parse_datetime(str_replace(lyr, glue("{var}\\|(.*)"), 
        "\\1")))
debug: if (!is.null(zonal_csv)) write_csv(d_r, zonal_csv)
debug: write_csv(d_r, zonal_csv)
debug: if (!keep_nc) unlink(dir_nc, recursive = T)
debug: unlink(dir_nc, recursive = T)
debug: return(d_r)
Downloading 1 requests, up to 166 time slices each
Called from: extractr::ed_extract(ed, var = v, sf_zones = ply, bbox = bb, 
    mask_tif = F, rast_tif = glue("{dir_out}/{nms}/{yr}.tif"), 
    zonal_fun = "mean", zonal_csv = glue("{dir_out}/{nms}/{yr}.csv"), 
    dir_nc = glue("{dir_out}/{nms}/{yr}_nc"), keep_nc = F, n_max_vals_per_req = 1e+05, 
    time_min = time_min, time_max = time_max, verbose = T)
debug: while (i_req <= n_reqs) {
    i_t_beg <- (i_req - 1) * n_t_per_req + 1
    i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
    t_req <- times_todo[c(i_t_beg, i_t_end)]
    t_req_str <- format_ISO8601(t_req, usetz = "Z")
    if (verbose) 
        message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
    ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
        ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
        0), nc)
    unlink(ncs0)
    nc_retry <- T
    nc_n_try <- 1
    n_max_retries
    while (nc_retry) {
        res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
            url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
                bbox[["xmax"]]), latitude = c(bbox[["ymin"]], 
                bbox[["ymax"]]), time = t_req_str, fmt = "nc", 
            store = rerddap::disk(path = dir_nc)))
        if (inherits(res, "try-error")) {
            err <- attr(res, "condition")
            msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
            nc_n_try <- nc_n_try + 1
            if (nc_n_try > n_max_retries) {
                stop(msg)
            }
            else {
                message(msg, "\nRETRYing...")
                Sys.sleep(1)
            }
        }
        else {
            nc_retry <- F
        }
    }
    i_req <- i_req + 1
}
debug: i_t_beg <- (i_req - 1) * n_t_per_req + 1
debug: i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
debug: t_req <- times_todo[c(i_t_beg, i_t_end)]
debug: t_req_str <- format_ISO8601(t_req, usetz = "Z")
debug: if (verbose) message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
debug: message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
Fetching request 1 of 1 (2001-01-01 to 2001-12-01) ~ 19:45:48 UTC
debug: ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
    0), nc)
debug: unlink(ncs0)
debug: nc_retry <- T
debug: nc_n_try <- 1
debug: n_max_retries
debug: while (nc_retry) {
    res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
        url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
            bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
        time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
    if (inherits(res, "try-error")) {
        err <- attr(res, "condition")
        msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
        nc_n_try <- nc_n_try + 1
        if (nc_n_try > n_max_retries) {
            stop(msg)
        }
        else {
            message(msg, "\nRETRYing...")
            Sys.sleep(1)
        }
    }
    else {
        nc_retry <- F
    }
}
debug: res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
    url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
        bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
    time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
debug: if (inherits(res, "try-error")) {
    err <- attr(res, "condition")
    msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
    nc_n_try <- nc_n_try + 1
    if (nc_n_try > n_max_retries) {
        stop(msg)
    }
    else {
        message(msg, "\nRETRYing...")
        Sys.sleep(1)
    }
} else {
    nc_retry <- F
}
debug: nc_retry <- F
debug: (while) nc_retry
debug: i_req <- i_req + 1
debug: (while) i_req <= n_reqs
debug: ncs <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size > 
    0), nc)
debug: r <- terra::rast(ncs)
debug: stopifnot(all(class(terra::time(r)) %in% c("POSIXct", "POSIXt")))
debug: idx <- dplyr::pull(dplyr::filter(dplyr::arrange(dplyr::tibble(idx = 1:terra::nlyr(r), 
    time = terra::time(r)), time), !duplicated(time)), idx)
debug: r <- terra::subset(r, idx)
debug: stopifnot(terra::crs(r, proj = T) == wgs84)
debug: if (mask_tif) r <- terra::mask(r, sf_zones)
debug: lyrs <- glue("{var}|{terra::time(r)}")
debug: if (length(dims_other) > 0 && !all(length(dims[dims_other]) == 
    1)) stop(glue("Other dimensions not yet supported: {paste(dims_other, collapse = ',')}"))
debug: names(r) <- lyrs
debug: if (!is.null(rast_tif)) {
    if (fs::file_exists(rast_tif)) {
        r_tmp_tif <- tempfile(fileext = ".tif")
        r_tmp <- c(rast(rast_tif), r)
        r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
        terra::writeRaster(r_tmp, r_tmp_tif)
        fs::file_delete(rast_tif)
        fs::file_move(r_tmp_tif, rast_tif)
        rm(r)
        rm(r_tmp)
    }
    else {
        terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
    }
    r <- terra::rast(rast_tif)
}
debug: if (fs::file_exists(rast_tif)) {
    r_tmp_tif <- tempfile(fileext = ".tif")
    r_tmp <- c(rast(rast_tif), r)
    r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
    terra::writeRaster(r_tmp, r_tmp_tif)
    fs::file_delete(rast_tif)
    fs::file_move(r_tmp_tif, rast_tif)
    rm(r)
    rm(r_tmp)
} else {
    terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
}
debug: terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
debug: r <- terra::rast(rast_tif)
debug: d_r <- mutate(tidyr::pivot_longer(sf::st_drop_geometry(sf::st_as_sf(terra::zonal(x = r, 
    z = terra::vect(dplyr::select(sf_zones, dplyr::all_of(fld_zones))), 
    fun = zonal_fun, exact = T, na.rm = T, as.polygons = T))), 
    cols = -dplyr::any_of(fld_zones), names_to = "lyr", values_to = zonal_fun), 
    time = readr::parse_datetime(str_replace(lyr, glue("{var}\\|(.*)"), 
        "\\1")))
debug: if (!is.null(zonal_csv)) write_csv(d_r, zonal_csv)
debug: write_csv(d_r, zonal_csv)
debug: if (!keep_nc) unlink(dir_nc, recursive = T)
debug: unlink(dir_nc, recursive = T)
debug: return(d_r)
Downloading 1 requests, up to 166 time slices each
Called from: extractr::ed_extract(ed, var = v, sf_zones = ply, bbox = bb, 
    mask_tif = F, rast_tif = glue("{dir_out}/{nms}/{yr}.tif"), 
    zonal_fun = "mean", zonal_csv = glue("{dir_out}/{nms}/{yr}.csv"), 
    dir_nc = glue("{dir_out}/{nms}/{yr}_nc"), keep_nc = F, n_max_vals_per_req = 1e+05, 
    time_min = time_min, time_max = time_max, verbose = T)
debug: while (i_req <= n_reqs) {
    i_t_beg <- (i_req - 1) * n_t_per_req + 1
    i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
    t_req <- times_todo[c(i_t_beg, i_t_end)]
    t_req_str <- format_ISO8601(t_req, usetz = "Z")
    if (verbose) 
        message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
    ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
        ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
        0), nc)
    unlink(ncs0)
    nc_retry <- T
    nc_n_try <- 1
    n_max_retries
    while (nc_retry) {
        res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
            url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
                bbox[["xmax"]]), latitude = c(bbox[["ymin"]], 
                bbox[["ymax"]]), time = t_req_str, fmt = "nc", 
            store = rerddap::disk(path = dir_nc)))
        if (inherits(res, "try-error")) {
            err <- attr(res, "condition")
            msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
            nc_n_try <- nc_n_try + 1
            if (nc_n_try > n_max_retries) {
                stop(msg)
            }
            else {
                message(msg, "\nRETRYing...")
                Sys.sleep(1)
            }
        }
        else {
            nc_retry <- F
        }
    }
    i_req <- i_req + 1
}
debug: i_t_beg <- (i_req - 1) * n_t_per_req + 1
debug: i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
debug: t_req <- times_todo[c(i_t_beg, i_t_end)]
debug: t_req_str <- format_ISO8601(t_req, usetz = "Z")
debug: if (verbose) message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
debug: message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
Fetching request 1 of 1 (2002-01-01 to 2002-12-01) ~ 19:45:52 UTC
debug: ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
    0), nc)
debug: unlink(ncs0)
debug: nc_retry <- T
debug: nc_n_try <- 1
debug: n_max_retries
debug: while (nc_retry) {
    res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
        url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
            bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
        time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
    if (inherits(res, "try-error")) {
        err <- attr(res, "condition")
        msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
        nc_n_try <- nc_n_try + 1
        if (nc_n_try > n_max_retries) {
            stop(msg)
        }
        else {
            message(msg, "\nRETRYing...")
            Sys.sleep(1)
        }
    }
    else {
        nc_retry <- F
    }
}
debug: res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
    url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
        bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
    time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
debug: if (inherits(res, "try-error")) {
    err <- attr(res, "condition")
    msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
    nc_n_try <- nc_n_try + 1
    if (nc_n_try > n_max_retries) {
        stop(msg)
    }
    else {
        message(msg, "\nRETRYing...")
        Sys.sleep(1)
    }
} else {
    nc_retry <- F
}
debug: nc_retry <- F
debug: (while) nc_retry
debug: i_req <- i_req + 1
debug: (while) i_req <= n_reqs
debug: ncs <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size > 
    0), nc)
debug: r <- terra::rast(ncs)
debug: stopifnot(all(class(terra::time(r)) %in% c("POSIXct", "POSIXt")))
debug: idx <- dplyr::pull(dplyr::filter(dplyr::arrange(dplyr::tibble(idx = 1:terra::nlyr(r), 
    time = terra::time(r)), time), !duplicated(time)), idx)
debug: r <- terra::subset(r, idx)
debug: stopifnot(terra::crs(r, proj = T) == wgs84)
debug: if (mask_tif) r <- terra::mask(r, sf_zones)
debug: lyrs <- glue("{var}|{terra::time(r)}")
debug: if (length(dims_other) > 0 && !all(length(dims[dims_other]) == 
    1)) stop(glue("Other dimensions not yet supported: {paste(dims_other, collapse = ',')}"))
debug: names(r) <- lyrs
debug: if (!is.null(rast_tif)) {
    if (fs::file_exists(rast_tif)) {
        r_tmp_tif <- tempfile(fileext = ".tif")
        r_tmp <- c(rast(rast_tif), r)
        r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
        terra::writeRaster(r_tmp, r_tmp_tif)
        fs::file_delete(rast_tif)
        fs::file_move(r_tmp_tif, rast_tif)
        rm(r)
        rm(r_tmp)
    }
    else {
        terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
    }
    r <- terra::rast(rast_tif)
}
debug: if (fs::file_exists(rast_tif)) {
    r_tmp_tif <- tempfile(fileext = ".tif")
    r_tmp <- c(rast(rast_tif), r)
    r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
    terra::writeRaster(r_tmp, r_tmp_tif)
    fs::file_delete(rast_tif)
    fs::file_move(r_tmp_tif, rast_tif)
    rm(r)
    rm(r_tmp)
} else {
    terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
}
debug: terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
debug: r <- terra::rast(rast_tif)
debug: d_r <- mutate(tidyr::pivot_longer(sf::st_drop_geometry(sf::st_as_sf(terra::zonal(x = r, 
    z = terra::vect(dplyr::select(sf_zones, dplyr::all_of(fld_zones))), 
    fun = zonal_fun, exact = T, na.rm = T, as.polygons = T))), 
    cols = -dplyr::any_of(fld_zones), names_to = "lyr", values_to = zonal_fun), 
    time = readr::parse_datetime(str_replace(lyr, glue("{var}\\|(.*)"), 
        "\\1")))
debug: if (!is.null(zonal_csv)) write_csv(d_r, zonal_csv)
debug: write_csv(d_r, zonal_csv)
debug: if (!keep_nc) unlink(dir_nc, recursive = T)
debug: unlink(dir_nc, recursive = T)
debug: return(d_r)
Downloading 1 requests, up to 166 time slices each
Called from: extractr::ed_extract(ed, var = v, sf_zones = ply, bbox = bb, 
    mask_tif = F, rast_tif = glue("{dir_out}/{nms}/{yr}.tif"), 
    zonal_fun = "mean", zonal_csv = glue("{dir_out}/{nms}/{yr}.csv"), 
    dir_nc = glue("{dir_out}/{nms}/{yr}_nc"), keep_nc = F, n_max_vals_per_req = 1e+05, 
    time_min = time_min, time_max = time_max, verbose = T)
debug: while (i_req <= n_reqs) {
    i_t_beg <- (i_req - 1) * n_t_per_req + 1
    i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
    t_req <- times_todo[c(i_t_beg, i_t_end)]
    t_req_str <- format_ISO8601(t_req, usetz = "Z")
    if (verbose) 
        message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
    ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
        ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
        0), nc)
    unlink(ncs0)
    nc_retry <- T
    nc_n_try <- 1
    n_max_retries
    while (nc_retry) {
        res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
            url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
                bbox[["xmax"]]), latitude = c(bbox[["ymin"]], 
                bbox[["ymax"]]), time = t_req_str, fmt = "nc", 
            store = rerddap::disk(path = dir_nc)))
        if (inherits(res, "try-error")) {
            err <- attr(res, "condition")
            msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
            nc_n_try <- nc_n_try + 1
            if (nc_n_try > n_max_retries) {
                stop(msg)
            }
            else {
                message(msg, "\nRETRYing...")
                Sys.sleep(1)
            }
        }
        else {
            nc_retry <- F
        }
    }
    i_req <- i_req + 1
}
debug: i_t_beg <- (i_req - 1) * n_t_per_req + 1
debug: i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
debug: t_req <- times_todo[c(i_t_beg, i_t_end)]
debug: t_req_str <- format_ISO8601(t_req, usetz = "Z")
debug: if (verbose) message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
debug: message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
Fetching request 1 of 1 (2003-01-01 to 2003-12-01) ~ 19:45:56 UTC
debug: ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
    0), nc)
debug: unlink(ncs0)
debug: nc_retry <- T
debug: nc_n_try <- 1
debug: n_max_retries
debug: while (nc_retry) {
    res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
        url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
            bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
        time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
    if (inherits(res, "try-error")) {
        err <- attr(res, "condition")
        msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
        nc_n_try <- nc_n_try + 1
        if (nc_n_try > n_max_retries) {
            stop(msg)
        }
        else {
            message(msg, "\nRETRYing...")
            Sys.sleep(1)
        }
    }
    else {
        nc_retry <- F
    }
}
debug: res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
    url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
        bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
    time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
debug: if (inherits(res, "try-error")) {
    err <- attr(res, "condition")
    msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
    nc_n_try <- nc_n_try + 1
    if (nc_n_try > n_max_retries) {
        stop(msg)
    }
    else {
        message(msg, "\nRETRYing...")
        Sys.sleep(1)
    }
} else {
    nc_retry <- F
}
debug: nc_retry <- F
debug: (while) nc_retry
debug: i_req <- i_req + 1
debug: (while) i_req <= n_reqs
debug: ncs <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size > 
    0), nc)
debug: r <- terra::rast(ncs)
debug: stopifnot(all(class(terra::time(r)) %in% c("POSIXct", "POSIXt")))
debug: idx <- dplyr::pull(dplyr::filter(dplyr::arrange(dplyr::tibble(idx = 1:terra::nlyr(r), 
    time = terra::time(r)), time), !duplicated(time)), idx)
debug: r <- terra::subset(r, idx)
debug: stopifnot(terra::crs(r, proj = T) == wgs84)
debug: if (mask_tif) r <- terra::mask(r, sf_zones)
debug: lyrs <- glue("{var}|{terra::time(r)}")
debug: if (length(dims_other) > 0 && !all(length(dims[dims_other]) == 
    1)) stop(glue("Other dimensions not yet supported: {paste(dims_other, collapse = ',')}"))
debug: names(r) <- lyrs
debug: if (!is.null(rast_tif)) {
    if (fs::file_exists(rast_tif)) {
        r_tmp_tif <- tempfile(fileext = ".tif")
        r_tmp <- c(rast(rast_tif), r)
        r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
        terra::writeRaster(r_tmp, r_tmp_tif)
        fs::file_delete(rast_tif)
        fs::file_move(r_tmp_tif, rast_tif)
        rm(r)
        rm(r_tmp)
    }
    else {
        terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
    }
    r <- terra::rast(rast_tif)
}
debug: if (fs::file_exists(rast_tif)) {
    r_tmp_tif <- tempfile(fileext = ".tif")
    r_tmp <- c(rast(rast_tif), r)
    r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
    terra::writeRaster(r_tmp, r_tmp_tif)
    fs::file_delete(rast_tif)
    fs::file_move(r_tmp_tif, rast_tif)
    rm(r)
    rm(r_tmp)
} else {
    terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
}
debug: terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
debug: r <- terra::rast(rast_tif)
debug: d_r <- mutate(tidyr::pivot_longer(sf::st_drop_geometry(sf::st_as_sf(terra::zonal(x = r, 
    z = terra::vect(dplyr::select(sf_zones, dplyr::all_of(fld_zones))), 
    fun = zonal_fun, exact = T, na.rm = T, as.polygons = T))), 
    cols = -dplyr::any_of(fld_zones), names_to = "lyr", values_to = zonal_fun), 
    time = readr::parse_datetime(str_replace(lyr, glue("{var}\\|(.*)"), 
        "\\1")))
debug: if (!is.null(zonal_csv)) write_csv(d_r, zonal_csv)
debug: write_csv(d_r, zonal_csv)
debug: if (!keep_nc) unlink(dir_nc, recursive = T)
debug: unlink(dir_nc, recursive = T)
debug: return(d_r)
Downloading 1 requests, up to 166 time slices each
Called from: extractr::ed_extract(ed, var = v, sf_zones = ply, bbox = bb, 
    mask_tif = F, rast_tif = glue("{dir_out}/{nms}/{yr}.tif"), 
    zonal_fun = "mean", zonal_csv = glue("{dir_out}/{nms}/{yr}.csv"), 
    dir_nc = glue("{dir_out}/{nms}/{yr}_nc"), keep_nc = F, n_max_vals_per_req = 1e+05, 
    time_min = time_min, time_max = time_max, verbose = T)
debug: while (i_req <= n_reqs) {
    i_t_beg <- (i_req - 1) * n_t_per_req + 1
    i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
    t_req <- times_todo[c(i_t_beg, i_t_end)]
    t_req_str <- format_ISO8601(t_req, usetz = "Z")
    if (verbose) 
        message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
    ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
        ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
        0), nc)
    unlink(ncs0)
    nc_retry <- T
    nc_n_try <- 1
    n_max_retries
    while (nc_retry) {
        res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
            url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
                bbox[["xmax"]]), latitude = c(bbox[["ymin"]], 
                bbox[["ymax"]]), time = t_req_str, fmt = "nc", 
            store = rerddap::disk(path = dir_nc)))
        if (inherits(res, "try-error")) {
            err <- attr(res, "condition")
            msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
            nc_n_try <- nc_n_try + 1
            if (nc_n_try > n_max_retries) {
                stop(msg)
            }
            else {
                message(msg, "\nRETRYing...")
                Sys.sleep(1)
            }
        }
        else {
            nc_retry <- F
        }
    }
    i_req <- i_req + 1
}
debug: i_t_beg <- (i_req - 1) * n_t_per_req + 1
debug: i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
debug: t_req <- times_todo[c(i_t_beg, i_t_end)]
debug: t_req_str <- format_ISO8601(t_req, usetz = "Z")
debug: if (verbose) message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
debug: message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
Fetching request 1 of 1 (2004-01-01 to 2004-12-01) ~ 19:46:00 UTC
debug: ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
    0), nc)
debug: unlink(ncs0)
debug: nc_retry <- T
debug: nc_n_try <- 1
debug: n_max_retries
debug: while (nc_retry) {
    res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
        url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
            bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
        time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
    if (inherits(res, "try-error")) {
        err <- attr(res, "condition")
        msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
        nc_n_try <- nc_n_try + 1
        if (nc_n_try > n_max_retries) {
            stop(msg)
        }
        else {
            message(msg, "\nRETRYing...")
            Sys.sleep(1)
        }
    }
    else {
        nc_retry <- F
    }
}
debug: res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
    url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
        bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
    time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
debug: if (inherits(res, "try-error")) {
    err <- attr(res, "condition")
    msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
    nc_n_try <- nc_n_try + 1
    if (nc_n_try > n_max_retries) {
        stop(msg)
    }
    else {
        message(msg, "\nRETRYing...")
        Sys.sleep(1)
    }
} else {
    nc_retry <- F
}
debug: nc_retry <- F
debug: (while) nc_retry
debug: i_req <- i_req + 1
debug: (while) i_req <= n_reqs
debug: ncs <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size > 
    0), nc)
debug: r <- terra::rast(ncs)
debug: stopifnot(all(class(terra::time(r)) %in% c("POSIXct", "POSIXt")))
debug: idx <- dplyr::pull(dplyr::filter(dplyr::arrange(dplyr::tibble(idx = 1:terra::nlyr(r), 
    time = terra::time(r)), time), !duplicated(time)), idx)
debug: r <- terra::subset(r, idx)
debug: stopifnot(terra::crs(r, proj = T) == wgs84)
debug: if (mask_tif) r <- terra::mask(r, sf_zones)
debug: lyrs <- glue("{var}|{terra::time(r)}")
debug: if (length(dims_other) > 0 && !all(length(dims[dims_other]) == 
    1)) stop(glue("Other dimensions not yet supported: {paste(dims_other, collapse = ',')}"))
debug: names(r) <- lyrs
debug: if (!is.null(rast_tif)) {
    if (fs::file_exists(rast_tif)) {
        r_tmp_tif <- tempfile(fileext = ".tif")
        r_tmp <- c(rast(rast_tif), r)
        r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
        terra::writeRaster(r_tmp, r_tmp_tif)
        fs::file_delete(rast_tif)
        fs::file_move(r_tmp_tif, rast_tif)
        rm(r)
        rm(r_tmp)
    }
    else {
        terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
    }
    r <- terra::rast(rast_tif)
}
debug: if (fs::file_exists(rast_tif)) {
    r_tmp_tif <- tempfile(fileext = ".tif")
    r_tmp <- c(rast(rast_tif), r)
    r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
    terra::writeRaster(r_tmp, r_tmp_tif)
    fs::file_delete(rast_tif)
    fs::file_move(r_tmp_tif, rast_tif)
    rm(r)
    rm(r_tmp)
} else {
    terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
}
debug: terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
debug: r <- terra::rast(rast_tif)
debug: d_r <- mutate(tidyr::pivot_longer(sf::st_drop_geometry(sf::st_as_sf(terra::zonal(x = r, 
    z = terra::vect(dplyr::select(sf_zones, dplyr::all_of(fld_zones))), 
    fun = zonal_fun, exact = T, na.rm = T, as.polygons = T))), 
    cols = -dplyr::any_of(fld_zones), names_to = "lyr", values_to = zonal_fun), 
    time = readr::parse_datetime(str_replace(lyr, glue("{var}\\|(.*)"), 
        "\\1")))
debug: if (!is.null(zonal_csv)) write_csv(d_r, zonal_csv)
debug: write_csv(d_r, zonal_csv)
debug: if (!keep_nc) unlink(dir_nc, recursive = T)
debug: unlink(dir_nc, recursive = T)
debug: return(d_r)
Downloading 1 requests, up to 166 time slices each
Called from: extractr::ed_extract(ed, var = v, sf_zones = ply, bbox = bb, 
    mask_tif = F, rast_tif = glue("{dir_out}/{nms}/{yr}.tif"), 
    zonal_fun = "mean", zonal_csv = glue("{dir_out}/{nms}/{yr}.csv"), 
    dir_nc = glue("{dir_out}/{nms}/{yr}_nc"), keep_nc = F, n_max_vals_per_req = 1e+05, 
    time_min = time_min, time_max = time_max, verbose = T)
debug: while (i_req <= n_reqs) {
    i_t_beg <- (i_req - 1) * n_t_per_req + 1
    i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
    t_req <- times_todo[c(i_t_beg, i_t_end)]
    t_req_str <- format_ISO8601(t_req, usetz = "Z")
    if (verbose) 
        message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
    ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
        ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
        0), nc)
    unlink(ncs0)
    nc_retry <- T
    nc_n_try <- 1
    n_max_retries
    while (nc_retry) {
        res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
            url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
                bbox[["xmax"]]), latitude = c(bbox[["ymin"]], 
                bbox[["ymax"]]), time = t_req_str, fmt = "nc", 
            store = rerddap::disk(path = dir_nc)))
        if (inherits(res, "try-error")) {
            err <- attr(res, "condition")
            msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
            nc_n_try <- nc_n_try + 1
            if (nc_n_try > n_max_retries) {
                stop(msg)
            }
            else {
                message(msg, "\nRETRYing...")
                Sys.sleep(1)
            }
        }
        else {
            nc_retry <- F
        }
    }
    i_req <- i_req + 1
}
debug: i_t_beg <- (i_req - 1) * n_t_per_req + 1
debug: i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
debug: t_req <- times_todo[c(i_t_beg, i_t_end)]
debug: t_req_str <- format_ISO8601(t_req, usetz = "Z")
debug: if (verbose) message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
debug: message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
Fetching request 1 of 1 (2005-01-01 to 2005-12-01) ~ 19:46:04 UTC
debug: ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
    0), nc)
debug: unlink(ncs0)
debug: nc_retry <- T
debug: nc_n_try <- 1
debug: n_max_retries
debug: while (nc_retry) {
    res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
        url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
            bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
        time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
    if (inherits(res, "try-error")) {
        err <- attr(res, "condition")
        msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
        nc_n_try <- nc_n_try + 1
        if (nc_n_try > n_max_retries) {
            stop(msg)
        }
        else {
            message(msg, "\nRETRYing...")
            Sys.sleep(1)
        }
    }
    else {
        nc_retry <- F
    }
}
debug: res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
    url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
        bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
    time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
debug: if (inherits(res, "try-error")) {
    err <- attr(res, "condition")
    msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
    nc_n_try <- nc_n_try + 1
    if (nc_n_try > n_max_retries) {
        stop(msg)
    }
    else {
        message(msg, "\nRETRYing...")
        Sys.sleep(1)
    }
} else {
    nc_retry <- F
}
debug: nc_retry <- F
debug: (while) nc_retry
debug: i_req <- i_req + 1
debug: (while) i_req <= n_reqs
debug: ncs <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size > 
    0), nc)
debug: r <- terra::rast(ncs)
debug: stopifnot(all(class(terra::time(r)) %in% c("POSIXct", "POSIXt")))
debug: idx <- dplyr::pull(dplyr::filter(dplyr::arrange(dplyr::tibble(idx = 1:terra::nlyr(r), 
    time = terra::time(r)), time), !duplicated(time)), idx)
debug: r <- terra::subset(r, idx)
debug: stopifnot(terra::crs(r, proj = T) == wgs84)
debug: if (mask_tif) r <- terra::mask(r, sf_zones)
debug: lyrs <- glue("{var}|{terra::time(r)}")
debug: if (length(dims_other) > 0 && !all(length(dims[dims_other]) == 
    1)) stop(glue("Other dimensions not yet supported: {paste(dims_other, collapse = ',')}"))
debug: names(r) <- lyrs
debug: if (!is.null(rast_tif)) {
    if (fs::file_exists(rast_tif)) {
        r_tmp_tif <- tempfile(fileext = ".tif")
        r_tmp <- c(rast(rast_tif), r)
        r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
        terra::writeRaster(r_tmp, r_tmp_tif)
        fs::file_delete(rast_tif)
        fs::file_move(r_tmp_tif, rast_tif)
        rm(r)
        rm(r_tmp)
    }
    else {
        terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
    }
    r <- terra::rast(rast_tif)
}
debug: if (fs::file_exists(rast_tif)) {
    r_tmp_tif <- tempfile(fileext = ".tif")
    r_tmp <- c(rast(rast_tif), r)
    r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
    terra::writeRaster(r_tmp, r_tmp_tif)
    fs::file_delete(rast_tif)
    fs::file_move(r_tmp_tif, rast_tif)
    rm(r)
    rm(r_tmp)
} else {
    terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
}
debug: terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
debug: r <- terra::rast(rast_tif)
debug: d_r <- mutate(tidyr::pivot_longer(sf::st_drop_geometry(sf::st_as_sf(terra::zonal(x = r, 
    z = terra::vect(dplyr::select(sf_zones, dplyr::all_of(fld_zones))), 
    fun = zonal_fun, exact = T, na.rm = T, as.polygons = T))), 
    cols = -dplyr::any_of(fld_zones), names_to = "lyr", values_to = zonal_fun), 
    time = readr::parse_datetime(str_replace(lyr, glue("{var}\\|(.*)"), 
        "\\1")))
debug: if (!is.null(zonal_csv)) write_csv(d_r, zonal_csv)
debug: write_csv(d_r, zonal_csv)
debug: if (!keep_nc) unlink(dir_nc, recursive = T)
debug: unlink(dir_nc, recursive = T)
debug: return(d_r)
Downloading 1 requests, up to 166 time slices each
Called from: extractr::ed_extract(ed, var = v, sf_zones = ply, bbox = bb, 
    mask_tif = F, rast_tif = glue("{dir_out}/{nms}/{yr}.tif"), 
    zonal_fun = "mean", zonal_csv = glue("{dir_out}/{nms}/{yr}.csv"), 
    dir_nc = glue("{dir_out}/{nms}/{yr}_nc"), keep_nc = F, n_max_vals_per_req = 1e+05, 
    time_min = time_min, time_max = time_max, verbose = T)
debug: while (i_req <= n_reqs) {
    i_t_beg <- (i_req - 1) * n_t_per_req + 1
    i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
    t_req <- times_todo[c(i_t_beg, i_t_end)]
    t_req_str <- format_ISO8601(t_req, usetz = "Z")
    if (verbose) 
        message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
    ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
        ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
        0), nc)
    unlink(ncs0)
    nc_retry <- T
    nc_n_try <- 1
    n_max_retries
    while (nc_retry) {
        res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
            url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
                bbox[["xmax"]]), latitude = c(bbox[["ymin"]], 
                bbox[["ymax"]]), time = t_req_str, fmt = "nc", 
            store = rerddap::disk(path = dir_nc)))
        if (inherits(res, "try-error")) {
            err <- attr(res, "condition")
            msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
            nc_n_try <- nc_n_try + 1
            if (nc_n_try > n_max_retries) {
                stop(msg)
            }
            else {
                message(msg, "\nRETRYing...")
                Sys.sleep(1)
            }
        }
        else {
            nc_retry <- F
        }
    }
    i_req <- i_req + 1
}
debug: i_t_beg <- (i_req - 1) * n_t_per_req + 1
debug: i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
debug: t_req <- times_todo[c(i_t_beg, i_t_end)]
debug: t_req_str <- format_ISO8601(t_req, usetz = "Z")
debug: if (verbose) message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
debug: message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
Fetching request 1 of 1 (2006-01-01 to 2006-12-01) ~ 19:46:10 UTC
debug: ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
    0), nc)
debug: unlink(ncs0)
debug: nc_retry <- T
debug: nc_n_try <- 1
debug: n_max_retries
debug: while (nc_retry) {
    res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
        url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
            bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
        time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
    if (inherits(res, "try-error")) {
        err <- attr(res, "condition")
        msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
        nc_n_try <- nc_n_try + 1
        if (nc_n_try > n_max_retries) {
            stop(msg)
        }
        else {
            message(msg, "\nRETRYing...")
            Sys.sleep(1)
        }
    }
    else {
        nc_retry <- F
    }
}
debug: res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
    url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
        bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
    time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
debug: if (inherits(res, "try-error")) {
    err <- attr(res, "condition")
    msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
    nc_n_try <- nc_n_try + 1
    if (nc_n_try > n_max_retries) {
        stop(msg)
    }
    else {
        message(msg, "\nRETRYing...")
        Sys.sleep(1)
    }
} else {
    nc_retry <- F
}
debug: nc_retry <- F
debug: (while) nc_retry
debug: i_req <- i_req + 1
debug: (while) i_req <= n_reqs
debug: ncs <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size > 
    0), nc)
debug: r <- terra::rast(ncs)
debug: stopifnot(all(class(terra::time(r)) %in% c("POSIXct", "POSIXt")))
debug: idx <- dplyr::pull(dplyr::filter(dplyr::arrange(dplyr::tibble(idx = 1:terra::nlyr(r), 
    time = terra::time(r)), time), !duplicated(time)), idx)
debug: r <- terra::subset(r, idx)
debug: stopifnot(terra::crs(r, proj = T) == wgs84)
debug: if (mask_tif) r <- terra::mask(r, sf_zones)
debug: lyrs <- glue("{var}|{terra::time(r)}")
debug: if (length(dims_other) > 0 && !all(length(dims[dims_other]) == 
    1)) stop(glue("Other dimensions not yet supported: {paste(dims_other, collapse = ',')}"))
debug: names(r) <- lyrs
debug: if (!is.null(rast_tif)) {
    if (fs::file_exists(rast_tif)) {
        r_tmp_tif <- tempfile(fileext = ".tif")
        r_tmp <- c(rast(rast_tif), r)
        r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
        terra::writeRaster(r_tmp, r_tmp_tif)
        fs::file_delete(rast_tif)
        fs::file_move(r_tmp_tif, rast_tif)
        rm(r)
        rm(r_tmp)
    }
    else {
        terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
    }
    r <- terra::rast(rast_tif)
}
debug: if (fs::file_exists(rast_tif)) {
    r_tmp_tif <- tempfile(fileext = ".tif")
    r_tmp <- c(rast(rast_tif), r)
    r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
    terra::writeRaster(r_tmp, r_tmp_tif)
    fs::file_delete(rast_tif)
    fs::file_move(r_tmp_tif, rast_tif)
    rm(r)
    rm(r_tmp)
} else {
    terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
}
debug: terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
debug: r <- terra::rast(rast_tif)
debug: d_r <- mutate(tidyr::pivot_longer(sf::st_drop_geometry(sf::st_as_sf(terra::zonal(x = r, 
    z = terra::vect(dplyr::select(sf_zones, dplyr::all_of(fld_zones))), 
    fun = zonal_fun, exact = T, na.rm = T, as.polygons = T))), 
    cols = -dplyr::any_of(fld_zones), names_to = "lyr", values_to = zonal_fun), 
    time = readr::parse_datetime(str_replace(lyr, glue("{var}\\|(.*)"), 
        "\\1")))
debug: if (!is.null(zonal_csv)) write_csv(d_r, zonal_csv)
debug: write_csv(d_r, zonal_csv)
debug: if (!keep_nc) unlink(dir_nc, recursive = T)
debug: unlink(dir_nc, recursive = T)
debug: return(d_r)
Downloading 1 requests, up to 166 time slices each
Called from: extractr::ed_extract(ed, var = v, sf_zones = ply, bbox = bb, 
    mask_tif = F, rast_tif = glue("{dir_out}/{nms}/{yr}.tif"), 
    zonal_fun = "mean", zonal_csv = glue("{dir_out}/{nms}/{yr}.csv"), 
    dir_nc = glue("{dir_out}/{nms}/{yr}_nc"), keep_nc = F, n_max_vals_per_req = 1e+05, 
    time_min = time_min, time_max = time_max, verbose = T)
debug: while (i_req <= n_reqs) {
    i_t_beg <- (i_req - 1) * n_t_per_req + 1
    i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
    t_req <- times_todo[c(i_t_beg, i_t_end)]
    t_req_str <- format_ISO8601(t_req, usetz = "Z")
    if (verbose) 
        message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
    ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
        ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
        0), nc)
    unlink(ncs0)
    nc_retry <- T
    nc_n_try <- 1
    n_max_retries
    while (nc_retry) {
        res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
            url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
                bbox[["xmax"]]), latitude = c(bbox[["ymin"]], 
                bbox[["ymax"]]), time = t_req_str, fmt = "nc", 
            store = rerddap::disk(path = dir_nc)))
        if (inherits(res, "try-error")) {
            err <- attr(res, "condition")
            msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
            nc_n_try <- nc_n_try + 1
            if (nc_n_try > n_max_retries) {
                stop(msg)
            }
            else {
                message(msg, "\nRETRYing...")
                Sys.sleep(1)
            }
        }
        else {
            nc_retry <- F
        }
    }
    i_req <- i_req + 1
}
debug: i_t_beg <- (i_req - 1) * n_t_per_req + 1
debug: i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
debug: t_req <- times_todo[c(i_t_beg, i_t_end)]
debug: t_req_str <- format_ISO8601(t_req, usetz = "Z")
debug: if (verbose) message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
debug: message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
Fetching request 1 of 1 (2007-01-01 to 2007-12-01) ~ 19:46:15 UTC
debug: ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
    0), nc)
debug: unlink(ncs0)
debug: nc_retry <- T
debug: nc_n_try <- 1
debug: n_max_retries
debug: while (nc_retry) {
    res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
        url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
            bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
        time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
    if (inherits(res, "try-error")) {
        err <- attr(res, "condition")
        msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
        nc_n_try <- nc_n_try + 1
        if (nc_n_try > n_max_retries) {
            stop(msg)
        }
        else {
            message(msg, "\nRETRYing...")
            Sys.sleep(1)
        }
    }
    else {
        nc_retry <- F
    }
}
debug: res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
    url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
        bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
    time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
debug: if (inherits(res, "try-error")) {
    err <- attr(res, "condition")
    msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
    nc_n_try <- nc_n_try + 1
    if (nc_n_try > n_max_retries) {
        stop(msg)
    }
    else {
        message(msg, "\nRETRYing...")
        Sys.sleep(1)
    }
} else {
    nc_retry <- F
}
debug: nc_retry <- F
debug: (while) nc_retry
debug: i_req <- i_req + 1
debug: (while) i_req <= n_reqs
debug: ncs <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size > 
    0), nc)
debug: r <- terra::rast(ncs)
debug: stopifnot(all(class(terra::time(r)) %in% c("POSIXct", "POSIXt")))
debug: idx <- dplyr::pull(dplyr::filter(dplyr::arrange(dplyr::tibble(idx = 1:terra::nlyr(r), 
    time = terra::time(r)), time), !duplicated(time)), idx)
debug: r <- terra::subset(r, idx)
debug: stopifnot(terra::crs(r, proj = T) == wgs84)
debug: if (mask_tif) r <- terra::mask(r, sf_zones)
debug: lyrs <- glue("{var}|{terra::time(r)}")
debug: if (length(dims_other) > 0 && !all(length(dims[dims_other]) == 
    1)) stop(glue("Other dimensions not yet supported: {paste(dims_other, collapse = ',')}"))
debug: names(r) <- lyrs
debug: if (!is.null(rast_tif)) {
    if (fs::file_exists(rast_tif)) {
        r_tmp_tif <- tempfile(fileext = ".tif")
        r_tmp <- c(rast(rast_tif), r)
        r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
        terra::writeRaster(r_tmp, r_tmp_tif)
        fs::file_delete(rast_tif)
        fs::file_move(r_tmp_tif, rast_tif)
        rm(r)
        rm(r_tmp)
    }
    else {
        terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
    }
    r <- terra::rast(rast_tif)
}
debug: if (fs::file_exists(rast_tif)) {
    r_tmp_tif <- tempfile(fileext = ".tif")
    r_tmp <- c(rast(rast_tif), r)
    r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
    terra::writeRaster(r_tmp, r_tmp_tif)
    fs::file_delete(rast_tif)
    fs::file_move(r_tmp_tif, rast_tif)
    rm(r)
    rm(r_tmp)
} else {
    terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
}
debug: terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
debug: r <- terra::rast(rast_tif)
debug: d_r <- mutate(tidyr::pivot_longer(sf::st_drop_geometry(sf::st_as_sf(terra::zonal(x = r, 
    z = terra::vect(dplyr::select(sf_zones, dplyr::all_of(fld_zones))), 
    fun = zonal_fun, exact = T, na.rm = T, as.polygons = T))), 
    cols = -dplyr::any_of(fld_zones), names_to = "lyr", values_to = zonal_fun), 
    time = readr::parse_datetime(str_replace(lyr, glue("{var}\\|(.*)"), 
        "\\1")))
debug: if (!is.null(zonal_csv)) write_csv(d_r, zonal_csv)
debug: write_csv(d_r, zonal_csv)
debug: if (!keep_nc) unlink(dir_nc, recursive = T)
debug: unlink(dir_nc, recursive = T)
debug: return(d_r)
Downloading 1 requests, up to 166 time slices each
Called from: extractr::ed_extract(ed, var = v, sf_zones = ply, bbox = bb, 
    mask_tif = F, rast_tif = glue("{dir_out}/{nms}/{yr}.tif"), 
    zonal_fun = "mean", zonal_csv = glue("{dir_out}/{nms}/{yr}.csv"), 
    dir_nc = glue("{dir_out}/{nms}/{yr}_nc"), keep_nc = F, n_max_vals_per_req = 1e+05, 
    time_min = time_min, time_max = time_max, verbose = T)
debug: while (i_req <= n_reqs) {
    i_t_beg <- (i_req - 1) * n_t_per_req + 1
    i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
    t_req <- times_todo[c(i_t_beg, i_t_end)]
    t_req_str <- format_ISO8601(t_req, usetz = "Z")
    if (verbose) 
        message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
    ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
        ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
        0), nc)
    unlink(ncs0)
    nc_retry <- T
    nc_n_try <- 1
    n_max_retries
    while (nc_retry) {
        res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
            url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
                bbox[["xmax"]]), latitude = c(bbox[["ymin"]], 
                bbox[["ymax"]]), time = t_req_str, fmt = "nc", 
            store = rerddap::disk(path = dir_nc)))
        if (inherits(res, "try-error")) {
            err <- attr(res, "condition")
            msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
            nc_n_try <- nc_n_try + 1
            if (nc_n_try > n_max_retries) {
                stop(msg)
            }
            else {
                message(msg, "\nRETRYing...")
                Sys.sleep(1)
            }
        }
        else {
            nc_retry <- F
        }
    }
    i_req <- i_req + 1
}
debug: i_t_beg <- (i_req - 1) * n_t_per_req + 1
debug: i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
debug: t_req <- times_todo[c(i_t_beg, i_t_end)]
debug: t_req_str <- format_ISO8601(t_req, usetz = "Z")
debug: if (verbose) message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
debug: message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
Fetching request 1 of 1 (2008-01-01 to 2008-12-01) ~ 19:46:19 UTC
debug: ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
    0), nc)
debug: unlink(ncs0)
debug: nc_retry <- T
debug: nc_n_try <- 1
debug: n_max_retries
debug: while (nc_retry) {
    res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
        url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
            bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
        time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
    if (inherits(res, "try-error")) {
        err <- attr(res, "condition")
        msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
        nc_n_try <- nc_n_try + 1
        if (nc_n_try > n_max_retries) {
            stop(msg)
        }
        else {
            message(msg, "\nRETRYing...")
            Sys.sleep(1)
        }
    }
    else {
        nc_retry <- F
    }
}
debug: res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
    url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
        bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
    time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
debug: if (inherits(res, "try-error")) {
    err <- attr(res, "condition")
    msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
    nc_n_try <- nc_n_try + 1
    if (nc_n_try > n_max_retries) {
        stop(msg)
    }
    else {
        message(msg, "\nRETRYing...")
        Sys.sleep(1)
    }
} else {
    nc_retry <- F
}
debug: nc_retry <- F
debug: (while) nc_retry
debug: i_req <- i_req + 1
debug: (while) i_req <= n_reqs
debug: ncs <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size > 
    0), nc)
debug: r <- terra::rast(ncs)
debug: stopifnot(all(class(terra::time(r)) %in% c("POSIXct", "POSIXt")))
debug: idx <- dplyr::pull(dplyr::filter(dplyr::arrange(dplyr::tibble(idx = 1:terra::nlyr(r), 
    time = terra::time(r)), time), !duplicated(time)), idx)
debug: r <- terra::subset(r, idx)
debug: stopifnot(terra::crs(r, proj = T) == wgs84)
debug: if (mask_tif) r <- terra::mask(r, sf_zones)
debug: lyrs <- glue("{var}|{terra::time(r)}")
debug: if (length(dims_other) > 0 && !all(length(dims[dims_other]) == 
    1)) stop(glue("Other dimensions not yet supported: {paste(dims_other, collapse = ',')}"))
debug: names(r) <- lyrs
debug: if (!is.null(rast_tif)) {
    if (fs::file_exists(rast_tif)) {
        r_tmp_tif <- tempfile(fileext = ".tif")
        r_tmp <- c(rast(rast_tif), r)
        r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
        terra::writeRaster(r_tmp, r_tmp_tif)
        fs::file_delete(rast_tif)
        fs::file_move(r_tmp_tif, rast_tif)
        rm(r)
        rm(r_tmp)
    }
    else {
        terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
    }
    r <- terra::rast(rast_tif)
}
debug: if (fs::file_exists(rast_tif)) {
    r_tmp_tif <- tempfile(fileext = ".tif")
    r_tmp <- c(rast(rast_tif), r)
    r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
    terra::writeRaster(r_tmp, r_tmp_tif)
    fs::file_delete(rast_tif)
    fs::file_move(r_tmp_tif, rast_tif)
    rm(r)
    rm(r_tmp)
} else {
    terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
}
debug: terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
debug: r <- terra::rast(rast_tif)
debug: d_r <- mutate(tidyr::pivot_longer(sf::st_drop_geometry(sf::st_as_sf(terra::zonal(x = r, 
    z = terra::vect(dplyr::select(sf_zones, dplyr::all_of(fld_zones))), 
    fun = zonal_fun, exact = T, na.rm = T, as.polygons = T))), 
    cols = -dplyr::any_of(fld_zones), names_to = "lyr", values_to = zonal_fun), 
    time = readr::parse_datetime(str_replace(lyr, glue("{var}\\|(.*)"), 
        "\\1")))
debug: if (!is.null(zonal_csv)) write_csv(d_r, zonal_csv)
debug: write_csv(d_r, zonal_csv)
debug: if (!keep_nc) unlink(dir_nc, recursive = T)
debug: unlink(dir_nc, recursive = T)
debug: return(d_r)
Downloading 1 requests, up to 166 time slices each
Called from: extractr::ed_extract(ed, var = v, sf_zones = ply, bbox = bb, 
    mask_tif = F, rast_tif = glue("{dir_out}/{nms}/{yr}.tif"), 
    zonal_fun = "mean", zonal_csv = glue("{dir_out}/{nms}/{yr}.csv"), 
    dir_nc = glue("{dir_out}/{nms}/{yr}_nc"), keep_nc = F, n_max_vals_per_req = 1e+05, 
    time_min = time_min, time_max = time_max, verbose = T)
debug: while (i_req <= n_reqs) {
    i_t_beg <- (i_req - 1) * n_t_per_req + 1
    i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
    t_req <- times_todo[c(i_t_beg, i_t_end)]
    t_req_str <- format_ISO8601(t_req, usetz = "Z")
    if (verbose) 
        message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
    ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
        ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
        0), nc)
    unlink(ncs0)
    nc_retry <- T
    nc_n_try <- 1
    n_max_retries
    while (nc_retry) {
        res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
            url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
                bbox[["xmax"]]), latitude = c(bbox[["ymin"]], 
                bbox[["ymax"]]), time = t_req_str, fmt = "nc", 
            store = rerddap::disk(path = dir_nc)))
        if (inherits(res, "try-error")) {
            err <- attr(res, "condition")
            msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
            nc_n_try <- nc_n_try + 1
            if (nc_n_try > n_max_retries) {
                stop(msg)
            }
            else {
                message(msg, "\nRETRYing...")
                Sys.sleep(1)
            }
        }
        else {
            nc_retry <- F
        }
    }
    i_req <- i_req + 1
}
debug: i_t_beg <- (i_req - 1) * n_t_per_req + 1
debug: i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
debug: t_req <- times_todo[c(i_t_beg, i_t_end)]
debug: t_req_str <- format_ISO8601(t_req, usetz = "Z")
debug: if (verbose) message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
debug: message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
Fetching request 1 of 1 (2009-01-01 to 2009-12-01) ~ 19:46:23 UTC
debug: ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
    0), nc)
debug: unlink(ncs0)
debug: nc_retry <- T
debug: nc_n_try <- 1
debug: n_max_retries
debug: while (nc_retry) {
    res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
        url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
            bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
        time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
    if (inherits(res, "try-error")) {
        err <- attr(res, "condition")
        msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
        nc_n_try <- nc_n_try + 1
        if (nc_n_try > n_max_retries) {
            stop(msg)
        }
        else {
            message(msg, "\nRETRYing...")
            Sys.sleep(1)
        }
    }
    else {
        nc_retry <- F
    }
}
debug: res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
    url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
        bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
    time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
debug: if (inherits(res, "try-error")) {
    err <- attr(res, "condition")
    msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
    nc_n_try <- nc_n_try + 1
    if (nc_n_try > n_max_retries) {
        stop(msg)
    }
    else {
        message(msg, "\nRETRYing...")
        Sys.sleep(1)
    }
} else {
    nc_retry <- F
}
debug: nc_retry <- F
debug: (while) nc_retry
debug: i_req <- i_req + 1
debug: (while) i_req <= n_reqs
debug: ncs <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size > 
    0), nc)
debug: r <- terra::rast(ncs)
debug: stopifnot(all(class(terra::time(r)) %in% c("POSIXct", "POSIXt")))
debug: idx <- dplyr::pull(dplyr::filter(dplyr::arrange(dplyr::tibble(idx = 1:terra::nlyr(r), 
    time = terra::time(r)), time), !duplicated(time)), idx)
debug: r <- terra::subset(r, idx)
debug: stopifnot(terra::crs(r, proj = T) == wgs84)
debug: if (mask_tif) r <- terra::mask(r, sf_zones)
debug: lyrs <- glue("{var}|{terra::time(r)}")
debug: if (length(dims_other) > 0 && !all(length(dims[dims_other]) == 
    1)) stop(glue("Other dimensions not yet supported: {paste(dims_other, collapse = ',')}"))
debug: names(r) <- lyrs
debug: if (!is.null(rast_tif)) {
    if (fs::file_exists(rast_tif)) {
        r_tmp_tif <- tempfile(fileext = ".tif")
        r_tmp <- c(rast(rast_tif), r)
        r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
        terra::writeRaster(r_tmp, r_tmp_tif)
        fs::file_delete(rast_tif)
        fs::file_move(r_tmp_tif, rast_tif)
        rm(r)
        rm(r_tmp)
    }
    else {
        terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
    }
    r <- terra::rast(rast_tif)
}
debug: if (fs::file_exists(rast_tif)) {
    r_tmp_tif <- tempfile(fileext = ".tif")
    r_tmp <- c(rast(rast_tif), r)
    r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
    terra::writeRaster(r_tmp, r_tmp_tif)
    fs::file_delete(rast_tif)
    fs::file_move(r_tmp_tif, rast_tif)
    rm(r)
    rm(r_tmp)
} else {
    terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
}
debug: terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
debug: r <- terra::rast(rast_tif)
debug: d_r <- mutate(tidyr::pivot_longer(sf::st_drop_geometry(sf::st_as_sf(terra::zonal(x = r, 
    z = terra::vect(dplyr::select(sf_zones, dplyr::all_of(fld_zones))), 
    fun = zonal_fun, exact = T, na.rm = T, as.polygons = T))), 
    cols = -dplyr::any_of(fld_zones), names_to = "lyr", values_to = zonal_fun), 
    time = readr::parse_datetime(str_replace(lyr, glue("{var}\\|(.*)"), 
        "\\1")))
debug: if (!is.null(zonal_csv)) write_csv(d_r, zonal_csv)
debug: write_csv(d_r, zonal_csv)
debug: if (!keep_nc) unlink(dir_nc, recursive = T)
debug: unlink(dir_nc, recursive = T)
debug: return(d_r)
Downloading 1 requests, up to 166 time slices each
Called from: extractr::ed_extract(ed, var = v, sf_zones = ply, bbox = bb, 
    mask_tif = F, rast_tif = glue("{dir_out}/{nms}/{yr}.tif"), 
    zonal_fun = "mean", zonal_csv = glue("{dir_out}/{nms}/{yr}.csv"), 
    dir_nc = glue("{dir_out}/{nms}/{yr}_nc"), keep_nc = F, n_max_vals_per_req = 1e+05, 
    time_min = time_min, time_max = time_max, verbose = T)
debug: while (i_req <= n_reqs) {
    i_t_beg <- (i_req - 1) * n_t_per_req + 1
    i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
    t_req <- times_todo[c(i_t_beg, i_t_end)]
    t_req_str <- format_ISO8601(t_req, usetz = "Z")
    if (verbose) 
        message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
    ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
        ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
        0), nc)
    unlink(ncs0)
    nc_retry <- T
    nc_n_try <- 1
    n_max_retries
    while (nc_retry) {
        res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
            url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
                bbox[["xmax"]]), latitude = c(bbox[["ymin"]], 
                bbox[["ymax"]]), time = t_req_str, fmt = "nc", 
            store = rerddap::disk(path = dir_nc)))
        if (inherits(res, "try-error")) {
            err <- attr(res, "condition")
            msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
            nc_n_try <- nc_n_try + 1
            if (nc_n_try > n_max_retries) {
                stop(msg)
            }
            else {
                message(msg, "\nRETRYing...")
                Sys.sleep(1)
            }
        }
        else {
            nc_retry <- F
        }
    }
    i_req <- i_req + 1
}
debug: i_t_beg <- (i_req - 1) * n_t_per_req + 1
debug: i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
debug: t_req <- times_todo[c(i_t_beg, i_t_end)]
debug: t_req_str <- format_ISO8601(t_req, usetz = "Z")
debug: if (verbose) message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
debug: message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
Fetching request 1 of 1 (2010-01-01 to 2010-12-01) ~ 19:46:27 UTC
debug: ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
    0), nc)
debug: unlink(ncs0)
debug: nc_retry <- T
debug: nc_n_try <- 1
debug: n_max_retries
debug: while (nc_retry) {
    res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
        url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
            bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
        time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
    if (inherits(res, "try-error")) {
        err <- attr(res, "condition")
        msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
        nc_n_try <- nc_n_try + 1
        if (nc_n_try > n_max_retries) {
            stop(msg)
        }
        else {
            message(msg, "\nRETRYing...")
            Sys.sleep(1)
        }
    }
    else {
        nc_retry <- F
    }
}
debug: res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
    url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
        bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
    time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
debug: if (inherits(res, "try-error")) {
    err <- attr(res, "condition")
    msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
    nc_n_try <- nc_n_try + 1
    if (nc_n_try > n_max_retries) {
        stop(msg)
    }
    else {
        message(msg, "\nRETRYing...")
        Sys.sleep(1)
    }
} else {
    nc_retry <- F
}
debug: nc_retry <- F
debug: (while) nc_retry
debug: i_req <- i_req + 1
debug: (while) i_req <= n_reqs
debug: ncs <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size > 
    0), nc)
debug: r <- terra::rast(ncs)
debug: stopifnot(all(class(terra::time(r)) %in% c("POSIXct", "POSIXt")))
debug: idx <- dplyr::pull(dplyr::filter(dplyr::arrange(dplyr::tibble(idx = 1:terra::nlyr(r), 
    time = terra::time(r)), time), !duplicated(time)), idx)
debug: r <- terra::subset(r, idx)
debug: stopifnot(terra::crs(r, proj = T) == wgs84)
debug: if (mask_tif) r <- terra::mask(r, sf_zones)
debug: lyrs <- glue("{var}|{terra::time(r)}")
debug: if (length(dims_other) > 0 && !all(length(dims[dims_other]) == 
    1)) stop(glue("Other dimensions not yet supported: {paste(dims_other, collapse = ',')}"))
debug: names(r) <- lyrs
debug: if (!is.null(rast_tif)) {
    if (fs::file_exists(rast_tif)) {
        r_tmp_tif <- tempfile(fileext = ".tif")
        r_tmp <- c(rast(rast_tif), r)
        r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
        terra::writeRaster(r_tmp, r_tmp_tif)
        fs::file_delete(rast_tif)
        fs::file_move(r_tmp_tif, rast_tif)
        rm(r)
        rm(r_tmp)
    }
    else {
        terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
    }
    r <- terra::rast(rast_tif)
}
debug: if (fs::file_exists(rast_tif)) {
    r_tmp_tif <- tempfile(fileext = ".tif")
    r_tmp <- c(rast(rast_tif), r)
    r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
    terra::writeRaster(r_tmp, r_tmp_tif)
    fs::file_delete(rast_tif)
    fs::file_move(r_tmp_tif, rast_tif)
    rm(r)
    rm(r_tmp)
} else {
    terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
}
debug: terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
debug: r <- terra::rast(rast_tif)
debug: d_r <- mutate(tidyr::pivot_longer(sf::st_drop_geometry(sf::st_as_sf(terra::zonal(x = r, 
    z = terra::vect(dplyr::select(sf_zones, dplyr::all_of(fld_zones))), 
    fun = zonal_fun, exact = T, na.rm = T, as.polygons = T))), 
    cols = -dplyr::any_of(fld_zones), names_to = "lyr", values_to = zonal_fun), 
    time = readr::parse_datetime(str_replace(lyr, glue("{var}\\|(.*)"), 
        "\\1")))
debug: if (!is.null(zonal_csv)) write_csv(d_r, zonal_csv)
debug: write_csv(d_r, zonal_csv)
debug: if (!keep_nc) unlink(dir_nc, recursive = T)
debug: unlink(dir_nc, recursive = T)
debug: return(d_r)
Downloading 1 requests, up to 166 time slices each
Called from: extractr::ed_extract(ed, var = v, sf_zones = ply, bbox = bb, 
    mask_tif = F, rast_tif = glue("{dir_out}/{nms}/{yr}.tif"), 
    zonal_fun = "mean", zonal_csv = glue("{dir_out}/{nms}/{yr}.csv"), 
    dir_nc = glue("{dir_out}/{nms}/{yr}_nc"), keep_nc = F, n_max_vals_per_req = 1e+05, 
    time_min = time_min, time_max = time_max, verbose = T)
debug: while (i_req <= n_reqs) {
    i_t_beg <- (i_req - 1) * n_t_per_req + 1
    i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
    t_req <- times_todo[c(i_t_beg, i_t_end)]
    t_req_str <- format_ISO8601(t_req, usetz = "Z")
    if (verbose) 
        message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
    ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
        ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
        0), nc)
    unlink(ncs0)
    nc_retry <- T
    nc_n_try <- 1
    n_max_retries
    while (nc_retry) {
        res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
            url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
                bbox[["xmax"]]), latitude = c(bbox[["ymin"]], 
                bbox[["ymax"]]), time = t_req_str, fmt = "nc", 
            store = rerddap::disk(path = dir_nc)))
        if (inherits(res, "try-error")) {
            err <- attr(res, "condition")
            msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
            nc_n_try <- nc_n_try + 1
            if (nc_n_try > n_max_retries) {
                stop(msg)
            }
            else {
                message(msg, "\nRETRYing...")
                Sys.sleep(1)
            }
        }
        else {
            nc_retry <- F
        }
    }
    i_req <- i_req + 1
}
debug: i_t_beg <- (i_req - 1) * n_t_per_req + 1
debug: i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
debug: t_req <- times_todo[c(i_t_beg, i_t_end)]
debug: t_req_str <- format_ISO8601(t_req, usetz = "Z")
debug: if (verbose) message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
debug: message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
Fetching request 1 of 1 (2011-01-01 to 2011-12-01) ~ 19:46:31 UTC
debug: ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
    0), nc)
debug: unlink(ncs0)
debug: nc_retry <- T
debug: nc_n_try <- 1
debug: n_max_retries
debug: while (nc_retry) {
    res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
        url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
            bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
        time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
    if (inherits(res, "try-error")) {
        err <- attr(res, "condition")
        msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
        nc_n_try <- nc_n_try + 1
        if (nc_n_try > n_max_retries) {
            stop(msg)
        }
        else {
            message(msg, "\nRETRYing...")
            Sys.sleep(1)
        }
    }
    else {
        nc_retry <- F
    }
}
debug: res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
    url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
        bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
    time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
debug: if (inherits(res, "try-error")) {
    err <- attr(res, "condition")
    msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
    nc_n_try <- nc_n_try + 1
    if (nc_n_try > n_max_retries) {
        stop(msg)
    }
    else {
        message(msg, "\nRETRYing...")
        Sys.sleep(1)
    }
} else {
    nc_retry <- F
}
debug: nc_retry <- F
debug: (while) nc_retry
debug: i_req <- i_req + 1
debug: (while) i_req <= n_reqs
debug: ncs <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size > 
    0), nc)
debug: r <- terra::rast(ncs)
debug: stopifnot(all(class(terra::time(r)) %in% c("POSIXct", "POSIXt")))
debug: idx <- dplyr::pull(dplyr::filter(dplyr::arrange(dplyr::tibble(idx = 1:terra::nlyr(r), 
    time = terra::time(r)), time), !duplicated(time)), idx)
debug: r <- terra::subset(r, idx)
debug: stopifnot(terra::crs(r, proj = T) == wgs84)
debug: if (mask_tif) r <- terra::mask(r, sf_zones)
debug: lyrs <- glue("{var}|{terra::time(r)}")
debug: if (length(dims_other) > 0 && !all(length(dims[dims_other]) == 
    1)) stop(glue("Other dimensions not yet supported: {paste(dims_other, collapse = ',')}"))
debug: names(r) <- lyrs
debug: if (!is.null(rast_tif)) {
    if (fs::file_exists(rast_tif)) {
        r_tmp_tif <- tempfile(fileext = ".tif")
        r_tmp <- c(rast(rast_tif), r)
        r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
        terra::writeRaster(r_tmp, r_tmp_tif)
        fs::file_delete(rast_tif)
        fs::file_move(r_tmp_tif, rast_tif)
        rm(r)
        rm(r_tmp)
    }
    else {
        terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
    }
    r <- terra::rast(rast_tif)
}
debug: if (fs::file_exists(rast_tif)) {
    r_tmp_tif <- tempfile(fileext = ".tif")
    r_tmp <- c(rast(rast_tif), r)
    r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
    terra::writeRaster(r_tmp, r_tmp_tif)
    fs::file_delete(rast_tif)
    fs::file_move(r_tmp_tif, rast_tif)
    rm(r)
    rm(r_tmp)
} else {
    terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
}
debug: terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
debug: r <- terra::rast(rast_tif)
debug: d_r <- mutate(tidyr::pivot_longer(sf::st_drop_geometry(sf::st_as_sf(terra::zonal(x = r, 
    z = terra::vect(dplyr::select(sf_zones, dplyr::all_of(fld_zones))), 
    fun = zonal_fun, exact = T, na.rm = T, as.polygons = T))), 
    cols = -dplyr::any_of(fld_zones), names_to = "lyr", values_to = zonal_fun), 
    time = readr::parse_datetime(str_replace(lyr, glue("{var}\\|(.*)"), 
        "\\1")))
debug: if (!is.null(zonal_csv)) write_csv(d_r, zonal_csv)
debug: write_csv(d_r, zonal_csv)
debug: if (!keep_nc) unlink(dir_nc, recursive = T)
debug: unlink(dir_nc, recursive = T)
debug: return(d_r)
Downloading 1 requests, up to 166 time slices each
Called from: extractr::ed_extract(ed, var = v, sf_zones = ply, bbox = bb, 
    mask_tif = F, rast_tif = glue("{dir_out}/{nms}/{yr}.tif"), 
    zonal_fun = "mean", zonal_csv = glue("{dir_out}/{nms}/{yr}.csv"), 
    dir_nc = glue("{dir_out}/{nms}/{yr}_nc"), keep_nc = F, n_max_vals_per_req = 1e+05, 
    time_min = time_min, time_max = time_max, verbose = T)
debug: while (i_req <= n_reqs) {
    i_t_beg <- (i_req - 1) * n_t_per_req + 1
    i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
    t_req <- times_todo[c(i_t_beg, i_t_end)]
    t_req_str <- format_ISO8601(t_req, usetz = "Z")
    if (verbose) 
        message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
    ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
        ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
        0), nc)
    unlink(ncs0)
    nc_retry <- T
    nc_n_try <- 1
    n_max_retries
    while (nc_retry) {
        res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
            url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
                bbox[["xmax"]]), latitude = c(bbox[["ymin"]], 
                bbox[["ymax"]]), time = t_req_str, fmt = "nc", 
            store = rerddap::disk(path = dir_nc)))
        if (inherits(res, "try-error")) {
            err <- attr(res, "condition")
            msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
            nc_n_try <- nc_n_try + 1
            if (nc_n_try > n_max_retries) {
                stop(msg)
            }
            else {
                message(msg, "\nRETRYing...")
                Sys.sleep(1)
            }
        }
        else {
            nc_retry <- F
        }
    }
    i_req <- i_req + 1
}
debug: i_t_beg <- (i_req - 1) * n_t_per_req + 1
debug: i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
debug: t_req <- times_todo[c(i_t_beg, i_t_end)]
debug: t_req_str <- format_ISO8601(t_req, usetz = "Z")
debug: if (verbose) message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
debug: message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
Fetching request 1 of 1 (2012-01-01 to 2012-12-01) ~ 19:46:35 UTC
debug: ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
    0), nc)
debug: unlink(ncs0)
debug: nc_retry <- T
debug: nc_n_try <- 1
debug: n_max_retries
debug: while (nc_retry) {
    res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
        url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
            bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
        time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
    if (inherits(res, "try-error")) {
        err <- attr(res, "condition")
        msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
        nc_n_try <- nc_n_try + 1
        if (nc_n_try > n_max_retries) {
            stop(msg)
        }
        else {
            message(msg, "\nRETRYing...")
            Sys.sleep(1)
        }
    }
    else {
        nc_retry <- F
    }
}
debug: res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
    url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
        bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
    time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
debug: if (inherits(res, "try-error")) {
    err <- attr(res, "condition")
    msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
    nc_n_try <- nc_n_try + 1
    if (nc_n_try > n_max_retries) {
        stop(msg)
    }
    else {
        message(msg, "\nRETRYing...")
        Sys.sleep(1)
    }
} else {
    nc_retry <- F
}
debug: nc_retry <- F
debug: (while) nc_retry
debug: i_req <- i_req + 1
debug: (while) i_req <= n_reqs
debug: ncs <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size > 
    0), nc)
debug: r <- terra::rast(ncs)
debug: stopifnot(all(class(terra::time(r)) %in% c("POSIXct", "POSIXt")))
debug: idx <- dplyr::pull(dplyr::filter(dplyr::arrange(dplyr::tibble(idx = 1:terra::nlyr(r), 
    time = terra::time(r)), time), !duplicated(time)), idx)
debug: r <- terra::subset(r, idx)
debug: stopifnot(terra::crs(r, proj = T) == wgs84)
debug: if (mask_tif) r <- terra::mask(r, sf_zones)
debug: lyrs <- glue("{var}|{terra::time(r)}")
debug: if (length(dims_other) > 0 && !all(length(dims[dims_other]) == 
    1)) stop(glue("Other dimensions not yet supported: {paste(dims_other, collapse = ',')}"))
debug: names(r) <- lyrs
debug: if (!is.null(rast_tif)) {
    if (fs::file_exists(rast_tif)) {
        r_tmp_tif <- tempfile(fileext = ".tif")
        r_tmp <- c(rast(rast_tif), r)
        r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
        terra::writeRaster(r_tmp, r_tmp_tif)
        fs::file_delete(rast_tif)
        fs::file_move(r_tmp_tif, rast_tif)
        rm(r)
        rm(r_tmp)
    }
    else {
        terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
    }
    r <- terra::rast(rast_tif)
}
debug: if (fs::file_exists(rast_tif)) {
    r_tmp_tif <- tempfile(fileext = ".tif")
    r_tmp <- c(rast(rast_tif), r)
    r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
    terra::writeRaster(r_tmp, r_tmp_tif)
    fs::file_delete(rast_tif)
    fs::file_move(r_tmp_tif, rast_tif)
    rm(r)
    rm(r_tmp)
} else {
    terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
}
debug: terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
debug: r <- terra::rast(rast_tif)
debug: d_r <- mutate(tidyr::pivot_longer(sf::st_drop_geometry(sf::st_as_sf(terra::zonal(x = r, 
    z = terra::vect(dplyr::select(sf_zones, dplyr::all_of(fld_zones))), 
    fun = zonal_fun, exact = T, na.rm = T, as.polygons = T))), 
    cols = -dplyr::any_of(fld_zones), names_to = "lyr", values_to = zonal_fun), 
    time = readr::parse_datetime(str_replace(lyr, glue("{var}\\|(.*)"), 
        "\\1")))
debug: if (!is.null(zonal_csv)) write_csv(d_r, zonal_csv)
debug: write_csv(d_r, zonal_csv)
debug: if (!keep_nc) unlink(dir_nc, recursive = T)
debug: unlink(dir_nc, recursive = T)
debug: return(d_r)
Downloading 1 requests, up to 166 time slices each
Called from: extractr::ed_extract(ed, var = v, sf_zones = ply, bbox = bb, 
    mask_tif = F, rast_tif = glue("{dir_out}/{nms}/{yr}.tif"), 
    zonal_fun = "mean", zonal_csv = glue("{dir_out}/{nms}/{yr}.csv"), 
    dir_nc = glue("{dir_out}/{nms}/{yr}_nc"), keep_nc = F, n_max_vals_per_req = 1e+05, 
    time_min = time_min, time_max = time_max, verbose = T)
debug: while (i_req <= n_reqs) {
    i_t_beg <- (i_req - 1) * n_t_per_req + 1
    i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
    t_req <- times_todo[c(i_t_beg, i_t_end)]
    t_req_str <- format_ISO8601(t_req, usetz = "Z")
    if (verbose) 
        message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
    ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
        ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
        0), nc)
    unlink(ncs0)
    nc_retry <- T
    nc_n_try <- 1
    n_max_retries
    while (nc_retry) {
        res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
            url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
                bbox[["xmax"]]), latitude = c(bbox[["ymin"]], 
                bbox[["ymax"]]), time = t_req_str, fmt = "nc", 
            store = rerddap::disk(path = dir_nc)))
        if (inherits(res, "try-error")) {
            err <- attr(res, "condition")
            msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
            nc_n_try <- nc_n_try + 1
            if (nc_n_try > n_max_retries) {
                stop(msg)
            }
            else {
                message(msg, "\nRETRYing...")
                Sys.sleep(1)
            }
        }
        else {
            nc_retry <- F
        }
    }
    i_req <- i_req + 1
}
debug: i_t_beg <- (i_req - 1) * n_t_per_req + 1
debug: i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
debug: t_req <- times_todo[c(i_t_beg, i_t_end)]
debug: t_req_str <- format_ISO8601(t_req, usetz = "Z")
debug: if (verbose) message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
debug: message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
Fetching request 1 of 1 (2013-01-01 to 2013-12-01) ~ 19:46:39 UTC
debug: ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
    0), nc)
debug: unlink(ncs0)
debug: nc_retry <- T
debug: nc_n_try <- 1
debug: n_max_retries
debug: while (nc_retry) {
    res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
        url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
            bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
        time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
    if (inherits(res, "try-error")) {
        err <- attr(res, "condition")
        msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
        nc_n_try <- nc_n_try + 1
        if (nc_n_try > n_max_retries) {
            stop(msg)
        }
        else {
            message(msg, "\nRETRYing...")
            Sys.sleep(1)
        }
    }
    else {
        nc_retry <- F
    }
}
debug: res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
    url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
        bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
    time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
debug: if (inherits(res, "try-error")) {
    err <- attr(res, "condition")
    msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
    nc_n_try <- nc_n_try + 1
    if (nc_n_try > n_max_retries) {
        stop(msg)
    }
    else {
        message(msg, "\nRETRYing...")
        Sys.sleep(1)
    }
} else {
    nc_retry <- F
}
debug: nc_retry <- F
debug: (while) nc_retry
debug: i_req <- i_req + 1
debug: (while) i_req <= n_reqs
debug: ncs <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size > 
    0), nc)
debug: r <- terra::rast(ncs)
debug: stopifnot(all(class(terra::time(r)) %in% c("POSIXct", "POSIXt")))
debug: idx <- dplyr::pull(dplyr::filter(dplyr::arrange(dplyr::tibble(idx = 1:terra::nlyr(r), 
    time = terra::time(r)), time), !duplicated(time)), idx)
debug: r <- terra::subset(r, idx)
debug: stopifnot(terra::crs(r, proj = T) == wgs84)
debug: if (mask_tif) r <- terra::mask(r, sf_zones)
debug: lyrs <- glue("{var}|{terra::time(r)}")
debug: if (length(dims_other) > 0 && !all(length(dims[dims_other]) == 
    1)) stop(glue("Other dimensions not yet supported: {paste(dims_other, collapse = ',')}"))
debug: names(r) <- lyrs
debug: if (!is.null(rast_tif)) {
    if (fs::file_exists(rast_tif)) {
        r_tmp_tif <- tempfile(fileext = ".tif")
        r_tmp <- c(rast(rast_tif), r)
        r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
        terra::writeRaster(r_tmp, r_tmp_tif)
        fs::file_delete(rast_tif)
        fs::file_move(r_tmp_tif, rast_tif)
        rm(r)
        rm(r_tmp)
    }
    else {
        terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
    }
    r <- terra::rast(rast_tif)
}
debug: if (fs::file_exists(rast_tif)) {
    r_tmp_tif <- tempfile(fileext = ".tif")
    r_tmp <- c(rast(rast_tif), r)
    r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
    terra::writeRaster(r_tmp, r_tmp_tif)
    fs::file_delete(rast_tif)
    fs::file_move(r_tmp_tif, rast_tif)
    rm(r)
    rm(r_tmp)
} else {
    terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
}
debug: terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
debug: r <- terra::rast(rast_tif)
debug: d_r <- mutate(tidyr::pivot_longer(sf::st_drop_geometry(sf::st_as_sf(terra::zonal(x = r, 
    z = terra::vect(dplyr::select(sf_zones, dplyr::all_of(fld_zones))), 
    fun = zonal_fun, exact = T, na.rm = T, as.polygons = T))), 
    cols = -dplyr::any_of(fld_zones), names_to = "lyr", values_to = zonal_fun), 
    time = readr::parse_datetime(str_replace(lyr, glue("{var}\\|(.*)"), 
        "\\1")))
debug: if (!is.null(zonal_csv)) write_csv(d_r, zonal_csv)
debug: write_csv(d_r, zonal_csv)
debug: if (!keep_nc) unlink(dir_nc, recursive = T)
debug: unlink(dir_nc, recursive = T)
debug: return(d_r)
Downloading 1 requests, up to 166 time slices each
Called from: extractr::ed_extract(ed, var = v, sf_zones = ply, bbox = bb, 
    mask_tif = F, rast_tif = glue("{dir_out}/{nms}/{yr}.tif"), 
    zonal_fun = "mean", zonal_csv = glue("{dir_out}/{nms}/{yr}.csv"), 
    dir_nc = glue("{dir_out}/{nms}/{yr}_nc"), keep_nc = F, n_max_vals_per_req = 1e+05, 
    time_min = time_min, time_max = time_max, verbose = T)
debug: while (i_req <= n_reqs) {
    i_t_beg <- (i_req - 1) * n_t_per_req + 1
    i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
    t_req <- times_todo[c(i_t_beg, i_t_end)]
    t_req_str <- format_ISO8601(t_req, usetz = "Z")
    if (verbose) 
        message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
    ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
        ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
        0), nc)
    unlink(ncs0)
    nc_retry <- T
    nc_n_try <- 1
    n_max_retries
    while (nc_retry) {
        res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
            url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
                bbox[["xmax"]]), latitude = c(bbox[["ymin"]], 
                bbox[["ymax"]]), time = t_req_str, fmt = "nc", 
            store = rerddap::disk(path = dir_nc)))
        if (inherits(res, "try-error")) {
            err <- attr(res, "condition")
            msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
            nc_n_try <- nc_n_try + 1
            if (nc_n_try > n_max_retries) {
                stop(msg)
            }
            else {
                message(msg, "\nRETRYing...")
                Sys.sleep(1)
            }
        }
        else {
            nc_retry <- F
        }
    }
    i_req <- i_req + 1
}
debug: i_t_beg <- (i_req - 1) * n_t_per_req + 1
debug: i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
debug: t_req <- times_todo[c(i_t_beg, i_t_end)]
debug: t_req_str <- format_ISO8601(t_req, usetz = "Z")
debug: if (verbose) message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
debug: message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
Fetching request 1 of 1 (2014-01-01 to 2014-12-01) ~ 19:46:43 UTC
debug: ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
    0), nc)
debug: unlink(ncs0)
debug: nc_retry <- T
debug: nc_n_try <- 1
debug: n_max_retries
debug: while (nc_retry) {
    res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
        url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
            bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
        time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
    if (inherits(res, "try-error")) {
        err <- attr(res, "condition")
        msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
        nc_n_try <- nc_n_try + 1
        if (nc_n_try > n_max_retries) {
            stop(msg)
        }
        else {
            message(msg, "\nRETRYing...")
            Sys.sleep(1)
        }
    }
    else {
        nc_retry <- F
    }
}
debug: res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
    url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
        bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
    time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
debug: if (inherits(res, "try-error")) {
    err <- attr(res, "condition")
    msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
    nc_n_try <- nc_n_try + 1
    if (nc_n_try > n_max_retries) {
        stop(msg)
    }
    else {
        message(msg, "\nRETRYing...")
        Sys.sleep(1)
    }
} else {
    nc_retry <- F
}
debug: nc_retry <- F
debug: (while) nc_retry
debug: i_req <- i_req + 1
debug: (while) i_req <= n_reqs
debug: ncs <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size > 
    0), nc)
debug: r <- terra::rast(ncs)
debug: stopifnot(all(class(terra::time(r)) %in% c("POSIXct", "POSIXt")))
debug: idx <- dplyr::pull(dplyr::filter(dplyr::arrange(dplyr::tibble(idx = 1:terra::nlyr(r), 
    time = terra::time(r)), time), !duplicated(time)), idx)
debug: r <- terra::subset(r, idx)
debug: stopifnot(terra::crs(r, proj = T) == wgs84)
debug: if (mask_tif) r <- terra::mask(r, sf_zones)
debug: lyrs <- glue("{var}|{terra::time(r)}")
debug: if (length(dims_other) > 0 && !all(length(dims[dims_other]) == 
    1)) stop(glue("Other dimensions not yet supported: {paste(dims_other, collapse = ',')}"))
debug: names(r) <- lyrs
debug: if (!is.null(rast_tif)) {
    if (fs::file_exists(rast_tif)) {
        r_tmp_tif <- tempfile(fileext = ".tif")
        r_tmp <- c(rast(rast_tif), r)
        r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
        terra::writeRaster(r_tmp, r_tmp_tif)
        fs::file_delete(rast_tif)
        fs::file_move(r_tmp_tif, rast_tif)
        rm(r)
        rm(r_tmp)
    }
    else {
        terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
    }
    r <- terra::rast(rast_tif)
}
debug: if (fs::file_exists(rast_tif)) {
    r_tmp_tif <- tempfile(fileext = ".tif")
    r_tmp <- c(rast(rast_tif), r)
    r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
    terra::writeRaster(r_tmp, r_tmp_tif)
    fs::file_delete(rast_tif)
    fs::file_move(r_tmp_tif, rast_tif)
    rm(r)
    rm(r_tmp)
} else {
    terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
}
debug: terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
debug: r <- terra::rast(rast_tif)
debug: d_r <- mutate(tidyr::pivot_longer(sf::st_drop_geometry(sf::st_as_sf(terra::zonal(x = r, 
    z = terra::vect(dplyr::select(sf_zones, dplyr::all_of(fld_zones))), 
    fun = zonal_fun, exact = T, na.rm = T, as.polygons = T))), 
    cols = -dplyr::any_of(fld_zones), names_to = "lyr", values_to = zonal_fun), 
    time = readr::parse_datetime(str_replace(lyr, glue("{var}\\|(.*)"), 
        "\\1")))
debug: if (!is.null(zonal_csv)) write_csv(d_r, zonal_csv)
debug: write_csv(d_r, zonal_csv)
debug: if (!keep_nc) unlink(dir_nc, recursive = T)
debug: unlink(dir_nc, recursive = T)
debug: return(d_r)
Downloading 1 requests, up to 166 time slices each
Called from: extractr::ed_extract(ed, var = v, sf_zones = ply, bbox = bb, 
    mask_tif = F, rast_tif = glue("{dir_out}/{nms}/{yr}.tif"), 
    zonal_fun = "mean", zonal_csv = glue("{dir_out}/{nms}/{yr}.csv"), 
    dir_nc = glue("{dir_out}/{nms}/{yr}_nc"), keep_nc = F, n_max_vals_per_req = 1e+05, 
    time_min = time_min, time_max = time_max, verbose = T)
debug: while (i_req <= n_reqs) {
    i_t_beg <- (i_req - 1) * n_t_per_req + 1
    i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
    t_req <- times_todo[c(i_t_beg, i_t_end)]
    t_req_str <- format_ISO8601(t_req, usetz = "Z")
    if (verbose) 
        message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
    ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
        ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
        0), nc)
    unlink(ncs0)
    nc_retry <- T
    nc_n_try <- 1
    n_max_retries
    while (nc_retry) {
        res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
            url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
                bbox[["xmax"]]), latitude = c(bbox[["ymin"]], 
                bbox[["ymax"]]), time = t_req_str, fmt = "nc", 
            store = rerddap::disk(path = dir_nc)))
        if (inherits(res, "try-error")) {
            err <- attr(res, "condition")
            msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
            nc_n_try <- nc_n_try + 1
            if (nc_n_try > n_max_retries) {
                stop(msg)
            }
            else {
                message(msg, "\nRETRYing...")
                Sys.sleep(1)
            }
        }
        else {
            nc_retry <- F
        }
    }
    i_req <- i_req + 1
}
debug: i_t_beg <- (i_req - 1) * n_t_per_req + 1
debug: i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
debug: t_req <- times_todo[c(i_t_beg, i_t_end)]
debug: t_req_str <- format_ISO8601(t_req, usetz = "Z")
debug: if (verbose) message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
debug: message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
Fetching request 1 of 1 (2015-01-01 to 2015-12-01) ~ 19:46:47 UTC
debug: ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
    0), nc)
debug: unlink(ncs0)
debug: nc_retry <- T
debug: nc_n_try <- 1
debug: n_max_retries
debug: while (nc_retry) {
    res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
        url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
            bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
        time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
    if (inherits(res, "try-error")) {
        err <- attr(res, "condition")
        msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
        nc_n_try <- nc_n_try + 1
        if (nc_n_try > n_max_retries) {
            stop(msg)
        }
        else {
            message(msg, "\nRETRYing...")
            Sys.sleep(1)
        }
    }
    else {
        nc_retry <- F
    }
}
debug: res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
    url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
        bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
    time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
debug: if (inherits(res, "try-error")) {
    err <- attr(res, "condition")
    msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
    nc_n_try <- nc_n_try + 1
    if (nc_n_try > n_max_retries) {
        stop(msg)
    }
    else {
        message(msg, "\nRETRYing...")
        Sys.sleep(1)
    }
} else {
    nc_retry <- F
}
debug: nc_retry <- F
debug: (while) nc_retry
debug: i_req <- i_req + 1
debug: (while) i_req <= n_reqs
debug: ncs <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size > 
    0), nc)
debug: r <- terra::rast(ncs)
debug: stopifnot(all(class(terra::time(r)) %in% c("POSIXct", "POSIXt")))
debug: idx <- dplyr::pull(dplyr::filter(dplyr::arrange(dplyr::tibble(idx = 1:terra::nlyr(r), 
    time = terra::time(r)), time), !duplicated(time)), idx)
debug: r <- terra::subset(r, idx)
debug: stopifnot(terra::crs(r, proj = T) == wgs84)
debug: if (mask_tif) r <- terra::mask(r, sf_zones)
debug: lyrs <- glue("{var}|{terra::time(r)}")
debug: if (length(dims_other) > 0 && !all(length(dims[dims_other]) == 
    1)) stop(glue("Other dimensions not yet supported: {paste(dims_other, collapse = ',')}"))
debug: names(r) <- lyrs
debug: if (!is.null(rast_tif)) {
    if (fs::file_exists(rast_tif)) {
        r_tmp_tif <- tempfile(fileext = ".tif")
        r_tmp <- c(rast(rast_tif), r)
        r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
        terra::writeRaster(r_tmp, r_tmp_tif)
        fs::file_delete(rast_tif)
        fs::file_move(r_tmp_tif, rast_tif)
        rm(r)
        rm(r_tmp)
    }
    else {
        terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
    }
    r <- terra::rast(rast_tif)
}
debug: if (fs::file_exists(rast_tif)) {
    r_tmp_tif <- tempfile(fileext = ".tif")
    r_tmp <- c(rast(rast_tif), r)
    r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
    terra::writeRaster(r_tmp, r_tmp_tif)
    fs::file_delete(rast_tif)
    fs::file_move(r_tmp_tif, rast_tif)
    rm(r)
    rm(r_tmp)
} else {
    terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
}
debug: terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
debug: r <- terra::rast(rast_tif)
debug: d_r <- mutate(tidyr::pivot_longer(sf::st_drop_geometry(sf::st_as_sf(terra::zonal(x = r, 
    z = terra::vect(dplyr::select(sf_zones, dplyr::all_of(fld_zones))), 
    fun = zonal_fun, exact = T, na.rm = T, as.polygons = T))), 
    cols = -dplyr::any_of(fld_zones), names_to = "lyr", values_to = zonal_fun), 
    time = readr::parse_datetime(str_replace(lyr, glue("{var}\\|(.*)"), 
        "\\1")))
debug: if (!is.null(zonal_csv)) write_csv(d_r, zonal_csv)
debug: write_csv(d_r, zonal_csv)
debug: if (!keep_nc) unlink(dir_nc, recursive = T)
debug: unlink(dir_nc, recursive = T)
debug: return(d_r)
Downloading 1 requests, up to 166 time slices each
Called from: extractr::ed_extract(ed, var = v, sf_zones = ply, bbox = bb, 
    mask_tif = F, rast_tif = glue("{dir_out}/{nms}/{yr}.tif"), 
    zonal_fun = "mean", zonal_csv = glue("{dir_out}/{nms}/{yr}.csv"), 
    dir_nc = glue("{dir_out}/{nms}/{yr}_nc"), keep_nc = F, n_max_vals_per_req = 1e+05, 
    time_min = time_min, time_max = time_max, verbose = T)
debug: while (i_req <= n_reqs) {
    i_t_beg <- (i_req - 1) * n_t_per_req + 1
    i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
    t_req <- times_todo[c(i_t_beg, i_t_end)]
    t_req_str <- format_ISO8601(t_req, usetz = "Z")
    if (verbose) 
        message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
    ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
        ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
        0), nc)
    unlink(ncs0)
    nc_retry <- T
    nc_n_try <- 1
    n_max_retries
    while (nc_retry) {
        res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
            url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
                bbox[["xmax"]]), latitude = c(bbox[["ymin"]], 
                bbox[["ymax"]]), time = t_req_str, fmt = "nc", 
            store = rerddap::disk(path = dir_nc)))
        if (inherits(res, "try-error")) {
            err <- attr(res, "condition")
            msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
            nc_n_try <- nc_n_try + 1
            if (nc_n_try > n_max_retries) {
                stop(msg)
            }
            else {
                message(msg, "\nRETRYing...")
                Sys.sleep(1)
            }
        }
        else {
            nc_retry <- F
        }
    }
    i_req <- i_req + 1
}
debug: i_t_beg <- (i_req - 1) * n_t_per_req + 1
debug: i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
debug: t_req <- times_todo[c(i_t_beg, i_t_end)]
debug: t_req_str <- format_ISO8601(t_req, usetz = "Z")
debug: if (verbose) message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
debug: message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
Fetching request 1 of 1 (2016-01-01 to 2016-12-01) ~ 19:46:51 UTC
debug: ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
    0), nc)
debug: unlink(ncs0)
debug: nc_retry <- T
debug: nc_n_try <- 1
debug: n_max_retries
debug: while (nc_retry) {
    res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
        url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
            bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
        time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
    if (inherits(res, "try-error")) {
        err <- attr(res, "condition")
        msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
        nc_n_try <- nc_n_try + 1
        if (nc_n_try > n_max_retries) {
            stop(msg)
        }
        else {
            message(msg, "\nRETRYing...")
            Sys.sleep(1)
        }
    }
    else {
        nc_retry <- F
    }
}
debug: res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
    url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
        bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
    time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
debug: if (inherits(res, "try-error")) {
    err <- attr(res, "condition")
    msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
    nc_n_try <- nc_n_try + 1
    if (nc_n_try > n_max_retries) {
        stop(msg)
    }
    else {
        message(msg, "\nRETRYing...")
        Sys.sleep(1)
    }
} else {
    nc_retry <- F
}
debug: nc_retry <- F
debug: (while) nc_retry
debug: i_req <- i_req + 1
debug: (while) i_req <= n_reqs
debug: ncs <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size > 
    0), nc)
debug: r <- terra::rast(ncs)
debug: stopifnot(all(class(terra::time(r)) %in% c("POSIXct", "POSIXt")))
debug: idx <- dplyr::pull(dplyr::filter(dplyr::arrange(dplyr::tibble(idx = 1:terra::nlyr(r), 
    time = terra::time(r)), time), !duplicated(time)), idx)
debug: r <- terra::subset(r, idx)
debug: stopifnot(terra::crs(r, proj = T) == wgs84)
debug: if (mask_tif) r <- terra::mask(r, sf_zones)
debug: lyrs <- glue("{var}|{terra::time(r)}")
debug: if (length(dims_other) > 0 && !all(length(dims[dims_other]) == 
    1)) stop(glue("Other dimensions not yet supported: {paste(dims_other, collapse = ',')}"))
debug: names(r) <- lyrs
debug: if (!is.null(rast_tif)) {
    if (fs::file_exists(rast_tif)) {
        r_tmp_tif <- tempfile(fileext = ".tif")
        r_tmp <- c(rast(rast_tif), r)
        r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
        terra::writeRaster(r_tmp, r_tmp_tif)
        fs::file_delete(rast_tif)
        fs::file_move(r_tmp_tif, rast_tif)
        rm(r)
        rm(r_tmp)
    }
    else {
        terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
    }
    r <- terra::rast(rast_tif)
}
debug: if (fs::file_exists(rast_tif)) {
    r_tmp_tif <- tempfile(fileext = ".tif")
    r_tmp <- c(rast(rast_tif), r)
    r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
    terra::writeRaster(r_tmp, r_tmp_tif)
    fs::file_delete(rast_tif)
    fs::file_move(r_tmp_tif, rast_tif)
    rm(r)
    rm(r_tmp)
} else {
    terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
}
debug: terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
debug: r <- terra::rast(rast_tif)
debug: d_r <- mutate(tidyr::pivot_longer(sf::st_drop_geometry(sf::st_as_sf(terra::zonal(x = r, 
    z = terra::vect(dplyr::select(sf_zones, dplyr::all_of(fld_zones))), 
    fun = zonal_fun, exact = T, na.rm = T, as.polygons = T))), 
    cols = -dplyr::any_of(fld_zones), names_to = "lyr", values_to = zonal_fun), 
    time = readr::parse_datetime(str_replace(lyr, glue("{var}\\|(.*)"), 
        "\\1")))
debug: if (!is.null(zonal_csv)) write_csv(d_r, zonal_csv)
debug: write_csv(d_r, zonal_csv)
debug: if (!keep_nc) unlink(dir_nc, recursive = T)
debug: unlink(dir_nc, recursive = T)
debug: return(d_r)
Downloading 1 requests, up to 166 time slices each
Called from: extractr::ed_extract(ed, var = v, sf_zones = ply, bbox = bb, 
    mask_tif = F, rast_tif = glue("{dir_out}/{nms}/{yr}.tif"), 
    zonal_fun = "mean", zonal_csv = glue("{dir_out}/{nms}/{yr}.csv"), 
    dir_nc = glue("{dir_out}/{nms}/{yr}_nc"), keep_nc = F, n_max_vals_per_req = 1e+05, 
    time_min = time_min, time_max = time_max, verbose = T)
debug: while (i_req <= n_reqs) {
    i_t_beg <- (i_req - 1) * n_t_per_req + 1
    i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
    t_req <- times_todo[c(i_t_beg, i_t_end)]
    t_req_str <- format_ISO8601(t_req, usetz = "Z")
    if (verbose) 
        message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
    ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
        ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
        0), nc)
    unlink(ncs0)
    nc_retry <- T
    nc_n_try <- 1
    n_max_retries
    while (nc_retry) {
        res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
            url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
                bbox[["xmax"]]), latitude = c(bbox[["ymin"]], 
                bbox[["ymax"]]), time = t_req_str, fmt = "nc", 
            store = rerddap::disk(path = dir_nc)))
        if (inherits(res, "try-error")) {
            err <- attr(res, "condition")
            msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
            nc_n_try <- nc_n_try + 1
            if (nc_n_try > n_max_retries) {
                stop(msg)
            }
            else {
                message(msg, "\nRETRYing...")
                Sys.sleep(1)
            }
        }
        else {
            nc_retry <- F
        }
    }
    i_req <- i_req + 1
}
debug: i_t_beg <- (i_req - 1) * n_t_per_req + 1
debug: i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
debug: t_req <- times_todo[c(i_t_beg, i_t_end)]
debug: t_req_str <- format_ISO8601(t_req, usetz = "Z")
debug: if (verbose) message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
debug: message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
Fetching request 1 of 1 (2017-01-01 to 2017-12-01) ~ 19:46:55 UTC
debug: ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
    0), nc)
debug: unlink(ncs0)
debug: nc_retry <- T
debug: nc_n_try <- 1
debug: n_max_retries
debug: while (nc_retry) {
    res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
        url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
            bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
        time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
    if (inherits(res, "try-error")) {
        err <- attr(res, "condition")
        msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
        nc_n_try <- nc_n_try + 1
        if (nc_n_try > n_max_retries) {
            stop(msg)
        }
        else {
            message(msg, "\nRETRYing...")
            Sys.sleep(1)
        }
    }
    else {
        nc_retry <- F
    }
}
debug: res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
    url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
        bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
    time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
debug: if (inherits(res, "try-error")) {
    err <- attr(res, "condition")
    msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
    nc_n_try <- nc_n_try + 1
    if (nc_n_try > n_max_retries) {
        stop(msg)
    }
    else {
        message(msg, "\nRETRYing...")
        Sys.sleep(1)
    }
} else {
    nc_retry <- F
}
debug: nc_retry <- F
debug: (while) nc_retry
debug: i_req <- i_req + 1
debug: (while) i_req <= n_reqs
debug: ncs <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size > 
    0), nc)
debug: r <- terra::rast(ncs)
debug: stopifnot(all(class(terra::time(r)) %in% c("POSIXct", "POSIXt")))
debug: idx <- dplyr::pull(dplyr::filter(dplyr::arrange(dplyr::tibble(idx = 1:terra::nlyr(r), 
    time = terra::time(r)), time), !duplicated(time)), idx)
debug: r <- terra::subset(r, idx)
debug: stopifnot(terra::crs(r, proj = T) == wgs84)
debug: if (mask_tif) r <- terra::mask(r, sf_zones)
debug: lyrs <- glue("{var}|{terra::time(r)}")
debug: if (length(dims_other) > 0 && !all(length(dims[dims_other]) == 
    1)) stop(glue("Other dimensions not yet supported: {paste(dims_other, collapse = ',')}"))
debug: names(r) <- lyrs
debug: if (!is.null(rast_tif)) {
    if (fs::file_exists(rast_tif)) {
        r_tmp_tif <- tempfile(fileext = ".tif")
        r_tmp <- c(rast(rast_tif), r)
        r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
        terra::writeRaster(r_tmp, r_tmp_tif)
        fs::file_delete(rast_tif)
        fs::file_move(r_tmp_tif, rast_tif)
        rm(r)
        rm(r_tmp)
    }
    else {
        terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
    }
    r <- terra::rast(rast_tif)
}
debug: if (fs::file_exists(rast_tif)) {
    r_tmp_tif <- tempfile(fileext = ".tif")
    r_tmp <- c(rast(rast_tif), r)
    r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
    terra::writeRaster(r_tmp, r_tmp_tif)
    fs::file_delete(rast_tif)
    fs::file_move(r_tmp_tif, rast_tif)
    rm(r)
    rm(r_tmp)
} else {
    terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
}
debug: terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
debug: r <- terra::rast(rast_tif)
debug: d_r <- mutate(tidyr::pivot_longer(sf::st_drop_geometry(sf::st_as_sf(terra::zonal(x = r, 
    z = terra::vect(dplyr::select(sf_zones, dplyr::all_of(fld_zones))), 
    fun = zonal_fun, exact = T, na.rm = T, as.polygons = T))), 
    cols = -dplyr::any_of(fld_zones), names_to = "lyr", values_to = zonal_fun), 
    time = readr::parse_datetime(str_replace(lyr, glue("{var}\\|(.*)"), 
        "\\1")))
debug: if (!is.null(zonal_csv)) write_csv(d_r, zonal_csv)
debug: write_csv(d_r, zonal_csv)
debug: if (!keep_nc) unlink(dir_nc, recursive = T)
debug: unlink(dir_nc, recursive = T)
debug: return(d_r)
Downloading 1 requests, up to 166 time slices each
Called from: extractr::ed_extract(ed, var = v, sf_zones = ply, bbox = bb, 
    mask_tif = F, rast_tif = glue("{dir_out}/{nms}/{yr}.tif"), 
    zonal_fun = "mean", zonal_csv = glue("{dir_out}/{nms}/{yr}.csv"), 
    dir_nc = glue("{dir_out}/{nms}/{yr}_nc"), keep_nc = F, n_max_vals_per_req = 1e+05, 
    time_min = time_min, time_max = time_max, verbose = T)
debug: while (i_req <= n_reqs) {
    i_t_beg <- (i_req - 1) * n_t_per_req + 1
    i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
    t_req <- times_todo[c(i_t_beg, i_t_end)]
    t_req_str <- format_ISO8601(t_req, usetz = "Z")
    if (verbose) 
        message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
    ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
        ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
        0), nc)
    unlink(ncs0)
    nc_retry <- T
    nc_n_try <- 1
    n_max_retries
    while (nc_retry) {
        res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
            url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
                bbox[["xmax"]]), latitude = c(bbox[["ymin"]], 
                bbox[["ymax"]]), time = t_req_str, fmt = "nc", 
            store = rerddap::disk(path = dir_nc)))
        if (inherits(res, "try-error")) {
            err <- attr(res, "condition")
            msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
            nc_n_try <- nc_n_try + 1
            if (nc_n_try > n_max_retries) {
                stop(msg)
            }
            else {
                message(msg, "\nRETRYing...")
                Sys.sleep(1)
            }
        }
        else {
            nc_retry <- F
        }
    }
    i_req <- i_req + 1
}
debug: i_t_beg <- (i_req - 1) * n_t_per_req + 1
debug: i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
debug: t_req <- times_todo[c(i_t_beg, i_t_end)]
debug: t_req_str <- format_ISO8601(t_req, usetz = "Z")
debug: if (verbose) message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
debug: message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
Fetching request 1 of 1 (2018-01-01 to 2018-12-01) ~ 19:46:59 UTC
debug: ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
    0), nc)
debug: unlink(ncs0)
debug: nc_retry <- T
debug: nc_n_try <- 1
debug: n_max_retries
debug: while (nc_retry) {
    res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
        url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
            bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
        time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
    if (inherits(res, "try-error")) {
        err <- attr(res, "condition")
        msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
        nc_n_try <- nc_n_try + 1
        if (nc_n_try > n_max_retries) {
            stop(msg)
        }
        else {
            message(msg, "\nRETRYing...")
            Sys.sleep(1)
        }
    }
    else {
        nc_retry <- F
    }
}
debug: res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
    url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
        bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
    time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
debug: if (inherits(res, "try-error")) {
    err <- attr(res, "condition")
    msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
    nc_n_try <- nc_n_try + 1
    if (nc_n_try > n_max_retries) {
        stop(msg)
    }
    else {
        message(msg, "\nRETRYing...")
        Sys.sleep(1)
    }
} else {
    nc_retry <- F
}
debug: nc_retry <- F
debug: (while) nc_retry
debug: i_req <- i_req + 1
debug: (while) i_req <= n_reqs
debug: ncs <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size > 
    0), nc)
debug: r <- terra::rast(ncs)
debug: stopifnot(all(class(terra::time(r)) %in% c("POSIXct", "POSIXt")))
debug: idx <- dplyr::pull(dplyr::filter(dplyr::arrange(dplyr::tibble(idx = 1:terra::nlyr(r), 
    time = terra::time(r)), time), !duplicated(time)), idx)
debug: r <- terra::subset(r, idx)
debug: stopifnot(terra::crs(r, proj = T) == wgs84)
debug: if (mask_tif) r <- terra::mask(r, sf_zones)
debug: lyrs <- glue("{var}|{terra::time(r)}")
debug: if (length(dims_other) > 0 && !all(length(dims[dims_other]) == 
    1)) stop(glue("Other dimensions not yet supported: {paste(dims_other, collapse = ',')}"))
debug: names(r) <- lyrs
debug: if (!is.null(rast_tif)) {
    if (fs::file_exists(rast_tif)) {
        r_tmp_tif <- tempfile(fileext = ".tif")
        r_tmp <- c(rast(rast_tif), r)
        r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
        terra::writeRaster(r_tmp, r_tmp_tif)
        fs::file_delete(rast_tif)
        fs::file_move(r_tmp_tif, rast_tif)
        rm(r)
        rm(r_tmp)
    }
    else {
        terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
    }
    r <- terra::rast(rast_tif)
}
debug: if (fs::file_exists(rast_tif)) {
    r_tmp_tif <- tempfile(fileext = ".tif")
    r_tmp <- c(rast(rast_tif), r)
    r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
    terra::writeRaster(r_tmp, r_tmp_tif)
    fs::file_delete(rast_tif)
    fs::file_move(r_tmp_tif, rast_tif)
    rm(r)
    rm(r_tmp)
} else {
    terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
}
debug: terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
debug: r <- terra::rast(rast_tif)
debug: d_r <- mutate(tidyr::pivot_longer(sf::st_drop_geometry(sf::st_as_sf(terra::zonal(x = r, 
    z = terra::vect(dplyr::select(sf_zones, dplyr::all_of(fld_zones))), 
    fun = zonal_fun, exact = T, na.rm = T, as.polygons = T))), 
    cols = -dplyr::any_of(fld_zones), names_to = "lyr", values_to = zonal_fun), 
    time = readr::parse_datetime(str_replace(lyr, glue("{var}\\|(.*)"), 
        "\\1")))
debug: if (!is.null(zonal_csv)) write_csv(d_r, zonal_csv)
debug: write_csv(d_r, zonal_csv)
debug: if (!keep_nc) unlink(dir_nc, recursive = T)
debug: unlink(dir_nc, recursive = T)
debug: return(d_r)
Downloading 1 requests, up to 166 time slices each
Called from: extractr::ed_extract(ed, var = v, sf_zones = ply, bbox = bb, 
    mask_tif = F, rast_tif = glue("{dir_out}/{nms}/{yr}.tif"), 
    zonal_fun = "mean", zonal_csv = glue("{dir_out}/{nms}/{yr}.csv"), 
    dir_nc = glue("{dir_out}/{nms}/{yr}_nc"), keep_nc = F, n_max_vals_per_req = 1e+05, 
    time_min = time_min, time_max = time_max, verbose = T)
debug: while (i_req <= n_reqs) {
    i_t_beg <- (i_req - 1) * n_t_per_req + 1
    i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
    t_req <- times_todo[c(i_t_beg, i_t_end)]
    t_req_str <- format_ISO8601(t_req, usetz = "Z")
    if (verbose) 
        message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
    ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
        ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
        0), nc)
    unlink(ncs0)
    nc_retry <- T
    nc_n_try <- 1
    n_max_retries
    while (nc_retry) {
        res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
            url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
                bbox[["xmax"]]), latitude = c(bbox[["ymin"]], 
                bbox[["ymax"]]), time = t_req_str, fmt = "nc", 
            store = rerddap::disk(path = dir_nc)))
        if (inherits(res, "try-error")) {
            err <- attr(res, "condition")
            msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
            nc_n_try <- nc_n_try + 1
            if (nc_n_try > n_max_retries) {
                stop(msg)
            }
            else {
                message(msg, "\nRETRYing...")
                Sys.sleep(1)
            }
        }
        else {
            nc_retry <- F
        }
    }
    i_req <- i_req + 1
}
debug: i_t_beg <- (i_req - 1) * n_t_per_req + 1
debug: i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
debug: t_req <- times_todo[c(i_t_beg, i_t_end)]
debug: t_req_str <- format_ISO8601(t_req, usetz = "Z")
debug: if (verbose) message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
debug: message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
Fetching request 1 of 1 (2019-01-01 to 2019-12-01) ~ 19:47:03 UTC
debug: ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
    0), nc)
debug: unlink(ncs0)
debug: nc_retry <- T
debug: nc_n_try <- 1
debug: n_max_retries
debug: while (nc_retry) {
    res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
        url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
            bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
        time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
    if (inherits(res, "try-error")) {
        err <- attr(res, "condition")
        msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
        nc_n_try <- nc_n_try + 1
        if (nc_n_try > n_max_retries) {
            stop(msg)
        }
        else {
            message(msg, "\nRETRYing...")
            Sys.sleep(1)
        }
    }
    else {
        nc_retry <- F
    }
}
debug: res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
    url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
        bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
    time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
debug: if (inherits(res, "try-error")) {
    err <- attr(res, "condition")
    msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
    nc_n_try <- nc_n_try + 1
    if (nc_n_try > n_max_retries) {
        stop(msg)
    }
    else {
        message(msg, "\nRETRYing...")
        Sys.sleep(1)
    }
} else {
    nc_retry <- F
}
debug: nc_retry <- F
debug: (while) nc_retry
debug: i_req <- i_req + 1
debug: (while) i_req <= n_reqs
debug: ncs <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size > 
    0), nc)
debug: r <- terra::rast(ncs)
debug: stopifnot(all(class(terra::time(r)) %in% c("POSIXct", "POSIXt")))
debug: idx <- dplyr::pull(dplyr::filter(dplyr::arrange(dplyr::tibble(idx = 1:terra::nlyr(r), 
    time = terra::time(r)), time), !duplicated(time)), idx)
debug: r <- terra::subset(r, idx)
debug: stopifnot(terra::crs(r, proj = T) == wgs84)
debug: if (mask_tif) r <- terra::mask(r, sf_zones)
debug: lyrs <- glue("{var}|{terra::time(r)}")
debug: if (length(dims_other) > 0 && !all(length(dims[dims_other]) == 
    1)) stop(glue("Other dimensions not yet supported: {paste(dims_other, collapse = ',')}"))
debug: names(r) <- lyrs
debug: if (!is.null(rast_tif)) {
    if (fs::file_exists(rast_tif)) {
        r_tmp_tif <- tempfile(fileext = ".tif")
        r_tmp <- c(rast(rast_tif), r)
        r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
        terra::writeRaster(r_tmp, r_tmp_tif)
        fs::file_delete(rast_tif)
        fs::file_move(r_tmp_tif, rast_tif)
        rm(r)
        rm(r_tmp)
    }
    else {
        terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
    }
    r <- terra::rast(rast_tif)
}
debug: if (fs::file_exists(rast_tif)) {
    r_tmp_tif <- tempfile(fileext = ".tif")
    r_tmp <- c(rast(rast_tif), r)
    r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
    terra::writeRaster(r_tmp, r_tmp_tif)
    fs::file_delete(rast_tif)
    fs::file_move(r_tmp_tif, rast_tif)
    rm(r)
    rm(r_tmp)
} else {
    terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
}
debug: terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
debug: r <- terra::rast(rast_tif)
debug: d_r <- mutate(tidyr::pivot_longer(sf::st_drop_geometry(sf::st_as_sf(terra::zonal(x = r, 
    z = terra::vect(dplyr::select(sf_zones, dplyr::all_of(fld_zones))), 
    fun = zonal_fun, exact = T, na.rm = T, as.polygons = T))), 
    cols = -dplyr::any_of(fld_zones), names_to = "lyr", values_to = zonal_fun), 
    time = readr::parse_datetime(str_replace(lyr, glue("{var}\\|(.*)"), 
        "\\1")))
debug: if (!is.null(zonal_csv)) write_csv(d_r, zonal_csv)
debug: write_csv(d_r, zonal_csv)
debug: if (!keep_nc) unlink(dir_nc, recursive = T)
debug: unlink(dir_nc, recursive = T)
debug: return(d_r)
Downloading 1 requests, up to 166 time slices each
Called from: extractr::ed_extract(ed, var = v, sf_zones = ply, bbox = bb, 
    mask_tif = F, rast_tif = glue("{dir_out}/{nms}/{yr}.tif"), 
    zonal_fun = "mean", zonal_csv = glue("{dir_out}/{nms}/{yr}.csv"), 
    dir_nc = glue("{dir_out}/{nms}/{yr}_nc"), keep_nc = F, n_max_vals_per_req = 1e+05, 
    time_min = time_min, time_max = time_max, verbose = T)
debug: while (i_req <= n_reqs) {
    i_t_beg <- (i_req - 1) * n_t_per_req + 1
    i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
    t_req <- times_todo[c(i_t_beg, i_t_end)]
    t_req_str <- format_ISO8601(t_req, usetz = "Z")
    if (verbose) 
        message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
    ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
        ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
        0), nc)
    unlink(ncs0)
    nc_retry <- T
    nc_n_try <- 1
    n_max_retries
    while (nc_retry) {
        res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
            url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
                bbox[["xmax"]]), latitude = c(bbox[["ymin"]], 
                bbox[["ymax"]]), time = t_req_str, fmt = "nc", 
            store = rerddap::disk(path = dir_nc)))
        if (inherits(res, "try-error")) {
            err <- attr(res, "condition")
            msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
            nc_n_try <- nc_n_try + 1
            if (nc_n_try > n_max_retries) {
                stop(msg)
            }
            else {
                message(msg, "\nRETRYing...")
                Sys.sleep(1)
            }
        }
        else {
            nc_retry <- F
        }
    }
    i_req <- i_req + 1
}
debug: i_t_beg <- (i_req - 1) * n_t_per_req + 1
debug: i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
debug: t_req <- times_todo[c(i_t_beg, i_t_end)]
debug: t_req_str <- format_ISO8601(t_req, usetz = "Z")
debug: if (verbose) message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
debug: message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
Fetching request 1 of 1 (2020-01-01 to 2020-12-01) ~ 19:47:07 UTC
debug: ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
    0), nc)
debug: unlink(ncs0)
debug: nc_retry <- T
debug: nc_n_try <- 1
debug: n_max_retries
debug: while (nc_retry) {
    res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
        url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
            bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
        time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
    if (inherits(res, "try-error")) {
        err <- attr(res, "condition")
        msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
        nc_n_try <- nc_n_try + 1
        if (nc_n_try > n_max_retries) {
            stop(msg)
        }
        else {
            message(msg, "\nRETRYing...")
            Sys.sleep(1)
        }
    }
    else {
        nc_retry <- F
    }
}
debug: res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
    url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
        bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
    time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
debug: if (inherits(res, "try-error")) {
    err <- attr(res, "condition")
    msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
    nc_n_try <- nc_n_try + 1
    if (nc_n_try > n_max_retries) {
        stop(msg)
    }
    else {
        message(msg, "\nRETRYing...")
        Sys.sleep(1)
    }
} else {
    nc_retry <- F
}
debug: nc_retry <- F
debug: (while) nc_retry
debug: i_req <- i_req + 1
debug: (while) i_req <= n_reqs
debug: ncs <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size > 
    0), nc)
debug: r <- terra::rast(ncs)
debug: stopifnot(all(class(terra::time(r)) %in% c("POSIXct", "POSIXt")))
debug: idx <- dplyr::pull(dplyr::filter(dplyr::arrange(dplyr::tibble(idx = 1:terra::nlyr(r), 
    time = terra::time(r)), time), !duplicated(time)), idx)
debug: r <- terra::subset(r, idx)
debug: stopifnot(terra::crs(r, proj = T) == wgs84)
debug: if (mask_tif) r <- terra::mask(r, sf_zones)
debug: lyrs <- glue("{var}|{terra::time(r)}")
debug: if (length(dims_other) > 0 && !all(length(dims[dims_other]) == 
    1)) stop(glue("Other dimensions not yet supported: {paste(dims_other, collapse = ',')}"))
debug: names(r) <- lyrs
debug: if (!is.null(rast_tif)) {
    if (fs::file_exists(rast_tif)) {
        r_tmp_tif <- tempfile(fileext = ".tif")
        r_tmp <- c(rast(rast_tif), r)
        r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
        terra::writeRaster(r_tmp, r_tmp_tif)
        fs::file_delete(rast_tif)
        fs::file_move(r_tmp_tif, rast_tif)
        rm(r)
        rm(r_tmp)
    }
    else {
        terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
    }
    r <- terra::rast(rast_tif)
}
debug: if (fs::file_exists(rast_tif)) {
    r_tmp_tif <- tempfile(fileext = ".tif")
    r_tmp <- c(rast(rast_tif), r)
    r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
    terra::writeRaster(r_tmp, r_tmp_tif)
    fs::file_delete(rast_tif)
    fs::file_move(r_tmp_tif, rast_tif)
    rm(r)
    rm(r_tmp)
} else {
    terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
}
debug: terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
debug: r <- terra::rast(rast_tif)
debug: d_r <- mutate(tidyr::pivot_longer(sf::st_drop_geometry(sf::st_as_sf(terra::zonal(x = r, 
    z = terra::vect(dplyr::select(sf_zones, dplyr::all_of(fld_zones))), 
    fun = zonal_fun, exact = T, na.rm = T, as.polygons = T))), 
    cols = -dplyr::any_of(fld_zones), names_to = "lyr", values_to = zonal_fun), 
    time = readr::parse_datetime(str_replace(lyr, glue("{var}\\|(.*)"), 
        "\\1")))
debug: if (!is.null(zonal_csv)) write_csv(d_r, zonal_csv)
debug: write_csv(d_r, zonal_csv)
debug: if (!keep_nc) unlink(dir_nc, recursive = T)
debug: unlink(dir_nc, recursive = T)
debug: return(d_r)
Downloading 1 requests, up to 166 time slices each
Called from: extractr::ed_extract(ed, var = v, sf_zones = ply, bbox = bb, 
    mask_tif = F, rast_tif = glue("{dir_out}/{nms}/{yr}.tif"), 
    zonal_fun = "mean", zonal_csv = glue("{dir_out}/{nms}/{yr}.csv"), 
    dir_nc = glue("{dir_out}/{nms}/{yr}_nc"), keep_nc = F, n_max_vals_per_req = 1e+05, 
    time_min = time_min, time_max = time_max, verbose = T)
debug: while (i_req <= n_reqs) {
    i_t_beg <- (i_req - 1) * n_t_per_req + 1
    i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
    t_req <- times_todo[c(i_t_beg, i_t_end)]
    t_req_str <- format_ISO8601(t_req, usetz = "Z")
    if (verbose) 
        message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
    ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
        ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
        0), nc)
    unlink(ncs0)
    nc_retry <- T
    nc_n_try <- 1
    n_max_retries
    while (nc_retry) {
        res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
            url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
                bbox[["xmax"]]), latitude = c(bbox[["ymin"]], 
                bbox[["ymax"]]), time = t_req_str, fmt = "nc", 
            store = rerddap::disk(path = dir_nc)))
        if (inherits(res, "try-error")) {
            err <- attr(res, "condition")
            msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
            nc_n_try <- nc_n_try + 1
            if (nc_n_try > n_max_retries) {
                stop(msg)
            }
            else {
                message(msg, "\nRETRYing...")
                Sys.sleep(1)
            }
        }
        else {
            nc_retry <- F
        }
    }
    i_req <- i_req + 1
}
debug: i_t_beg <- (i_req - 1) * n_t_per_req + 1
debug: i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
debug: t_req <- times_todo[c(i_t_beg, i_t_end)]
debug: t_req_str <- format_ISO8601(t_req, usetz = "Z")
debug: if (verbose) message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
debug: message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
Fetching request 1 of 1 (2021-01-01 to 2021-12-01) ~ 19:47:11 UTC
debug: ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
    0), nc)
debug: unlink(ncs0)
debug: nc_retry <- T
debug: nc_n_try <- 1
debug: n_max_retries
debug: while (nc_retry) {
    res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
        url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
            bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
        time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
    if (inherits(res, "try-error")) {
        err <- attr(res, "condition")
        msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
        nc_n_try <- nc_n_try + 1
        if (nc_n_try > n_max_retries) {
            stop(msg)
        }
        else {
            message(msg, "\nRETRYing...")
            Sys.sleep(1)
        }
    }
    else {
        nc_retry <- F
    }
}
debug: res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
    url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
        bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
    time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
debug: if (inherits(res, "try-error")) {
    err <- attr(res, "condition")
    msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
    nc_n_try <- nc_n_try + 1
    if (nc_n_try > n_max_retries) {
        stop(msg)
    }
    else {
        message(msg, "\nRETRYing...")
        Sys.sleep(1)
    }
} else {
    nc_retry <- F
}
debug: nc_retry <- F
debug: (while) nc_retry
debug: i_req <- i_req + 1
debug: (while) i_req <= n_reqs
debug: ncs <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size > 
    0), nc)
debug: r <- terra::rast(ncs)
debug: stopifnot(all(class(terra::time(r)) %in% c("POSIXct", "POSIXt")))
debug: idx <- dplyr::pull(dplyr::filter(dplyr::arrange(dplyr::tibble(idx = 1:terra::nlyr(r), 
    time = terra::time(r)), time), !duplicated(time)), idx)
debug: r <- terra::subset(r, idx)
debug: stopifnot(terra::crs(r, proj = T) == wgs84)
debug: if (mask_tif) r <- terra::mask(r, sf_zones)
debug: lyrs <- glue("{var}|{terra::time(r)}")
debug: if (length(dims_other) > 0 && !all(length(dims[dims_other]) == 
    1)) stop(glue("Other dimensions not yet supported: {paste(dims_other, collapse = ',')}"))
debug: names(r) <- lyrs
debug: if (!is.null(rast_tif)) {
    if (fs::file_exists(rast_tif)) {
        r_tmp_tif <- tempfile(fileext = ".tif")
        r_tmp <- c(rast(rast_tif), r)
        r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
        terra::writeRaster(r_tmp, r_tmp_tif)
        fs::file_delete(rast_tif)
        fs::file_move(r_tmp_tif, rast_tif)
        rm(r)
        rm(r_tmp)
    }
    else {
        terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
    }
    r <- terra::rast(rast_tif)
}
debug: if (fs::file_exists(rast_tif)) {
    r_tmp_tif <- tempfile(fileext = ".tif")
    r_tmp <- c(rast(rast_tif), r)
    r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
    terra::writeRaster(r_tmp, r_tmp_tif)
    fs::file_delete(rast_tif)
    fs::file_move(r_tmp_tif, rast_tif)
    rm(r)
    rm(r_tmp)
} else {
    terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
}
debug: terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
debug: r <- terra::rast(rast_tif)
debug: d_r <- mutate(tidyr::pivot_longer(sf::st_drop_geometry(sf::st_as_sf(terra::zonal(x = r, 
    z = terra::vect(dplyr::select(sf_zones, dplyr::all_of(fld_zones))), 
    fun = zonal_fun, exact = T, na.rm = T, as.polygons = T))), 
    cols = -dplyr::any_of(fld_zones), names_to = "lyr", values_to = zonal_fun), 
    time = readr::parse_datetime(str_replace(lyr, glue("{var}\\|(.*)"), 
        "\\1")))
debug: if (!is.null(zonal_csv)) write_csv(d_r, zonal_csv)
debug: write_csv(d_r, zonal_csv)
debug: if (!keep_nc) unlink(dir_nc, recursive = T)
debug: unlink(dir_nc, recursive = T)
debug: return(d_r)
Downloading 1 requests, up to 166 time slices each
Called from: extractr::ed_extract(ed, var = v, sf_zones = ply, bbox = bb, 
    mask_tif = F, rast_tif = glue("{dir_out}/{nms}/{yr}.tif"), 
    zonal_fun = "mean", zonal_csv = glue("{dir_out}/{nms}/{yr}.csv"), 
    dir_nc = glue("{dir_out}/{nms}/{yr}_nc"), keep_nc = F, n_max_vals_per_req = 1e+05, 
    time_min = time_min, time_max = time_max, verbose = T)
debug: while (i_req <= n_reqs) {
    i_t_beg <- (i_req - 1) * n_t_per_req + 1
    i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
    t_req <- times_todo[c(i_t_beg, i_t_end)]
    t_req_str <- format_ISO8601(t_req, usetz = "Z")
    if (verbose) 
        message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
    ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
        ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
        0), nc)
    unlink(ncs0)
    nc_retry <- T
    nc_n_try <- 1
    n_max_retries
    while (nc_retry) {
        res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
            url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
                bbox[["xmax"]]), latitude = c(bbox[["ymin"]], 
                bbox[["ymax"]]), time = t_req_str, fmt = "nc", 
            store = rerddap::disk(path = dir_nc)))
        if (inherits(res, "try-error")) {
            err <- attr(res, "condition")
            msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
            nc_n_try <- nc_n_try + 1
            if (nc_n_try > n_max_retries) {
                stop(msg)
            }
            else {
                message(msg, "\nRETRYing...")
                Sys.sleep(1)
            }
        }
        else {
            nc_retry <- F
        }
    }
    i_req <- i_req + 1
}
debug: i_t_beg <- (i_req - 1) * n_t_per_req + 1
debug: i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
debug: t_req <- times_todo[c(i_t_beg, i_t_end)]
debug: t_req_str <- format_ISO8601(t_req, usetz = "Z")
debug: if (verbose) message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
debug: message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
Fetching request 1 of 1 (2022-01-01 to 2022-12-01) ~ 19:47:15 UTC
debug: ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
    0), nc)
debug: unlink(ncs0)
debug: nc_retry <- T
debug: nc_n_try <- 1
debug: n_max_retries
debug: while (nc_retry) {
    res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
        url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
            bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
        time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
    if (inherits(res, "try-error")) {
        err <- attr(res, "condition")
        msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
        nc_n_try <- nc_n_try + 1
        if (nc_n_try > n_max_retries) {
            stop(msg)
        }
        else {
            message(msg, "\nRETRYing...")
            Sys.sleep(1)
        }
    }
    else {
        nc_retry <- F
    }
}
debug: res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
    url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
        bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
    time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
debug: if (inherits(res, "try-error")) {
    err <- attr(res, "condition")
    msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
    nc_n_try <- nc_n_try + 1
    if (nc_n_try > n_max_retries) {
        stop(msg)
    }
    else {
        message(msg, "\nRETRYing...")
        Sys.sleep(1)
    }
} else {
    nc_retry <- F
}
debug: nc_retry <- F
debug: (while) nc_retry
debug: i_req <- i_req + 1
debug: (while) i_req <= n_reqs
debug: ncs <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size > 
    0), nc)
debug: r <- terra::rast(ncs)
debug: stopifnot(all(class(terra::time(r)) %in% c("POSIXct", "POSIXt")))
debug: idx <- dplyr::pull(dplyr::filter(dplyr::arrange(dplyr::tibble(idx = 1:terra::nlyr(r), 
    time = terra::time(r)), time), !duplicated(time)), idx)
debug: r <- terra::subset(r, idx)
debug: stopifnot(terra::crs(r, proj = T) == wgs84)
debug: if (mask_tif) r <- terra::mask(r, sf_zones)
debug: lyrs <- glue("{var}|{terra::time(r)}")
debug: if (length(dims_other) > 0 && !all(length(dims[dims_other]) == 
    1)) stop(glue("Other dimensions not yet supported: {paste(dims_other, collapse = ',')}"))
debug: names(r) <- lyrs
debug: if (!is.null(rast_tif)) {
    if (fs::file_exists(rast_tif)) {
        r_tmp_tif <- tempfile(fileext = ".tif")
        r_tmp <- c(rast(rast_tif), r)
        r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
        terra::writeRaster(r_tmp, r_tmp_tif)
        fs::file_delete(rast_tif)
        fs::file_move(r_tmp_tif, rast_tif)
        rm(r)
        rm(r_tmp)
    }
    else {
        terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
    }
    r <- terra::rast(rast_tif)
}
debug: if (fs::file_exists(rast_tif)) {
    r_tmp_tif <- tempfile(fileext = ".tif")
    r_tmp <- c(rast(rast_tif), r)
    r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
    terra::writeRaster(r_tmp, r_tmp_tif)
    fs::file_delete(rast_tif)
    fs::file_move(r_tmp_tif, rast_tif)
    rm(r)
    rm(r_tmp)
} else {
    terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
}
debug: terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
debug: r <- terra::rast(rast_tif)
debug: d_r <- mutate(tidyr::pivot_longer(sf::st_drop_geometry(sf::st_as_sf(terra::zonal(x = r, 
    z = terra::vect(dplyr::select(sf_zones, dplyr::all_of(fld_zones))), 
    fun = zonal_fun, exact = T, na.rm = T, as.polygons = T))), 
    cols = -dplyr::any_of(fld_zones), names_to = "lyr", values_to = zonal_fun), 
    time = readr::parse_datetime(str_replace(lyr, glue("{var}\\|(.*)"), 
        "\\1")))
debug: if (!is.null(zonal_csv)) write_csv(d_r, zonal_csv)
debug: write_csv(d_r, zonal_csv)
debug: if (!keep_nc) unlink(dir_nc, recursive = T)
debug: unlink(dir_nc, recursive = T)
debug: return(d_r)
Downloading 1 requests, up to 166 time slices each
Called from: extractr::ed_extract(ed, var = v, sf_zones = ply, bbox = bb, 
    mask_tif = F, rast_tif = glue("{dir_out}/{nms}/{yr}.tif"), 
    zonal_fun = "mean", zonal_csv = glue("{dir_out}/{nms}/{yr}.csv"), 
    dir_nc = glue("{dir_out}/{nms}/{yr}_nc"), keep_nc = F, n_max_vals_per_req = 1e+05, 
    time_min = time_min, time_max = time_max, verbose = T)
debug: while (i_req <= n_reqs) {
    i_t_beg <- (i_req - 1) * n_t_per_req + 1
    i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
    t_req <- times_todo[c(i_t_beg, i_t_end)]
    t_req_str <- format_ISO8601(t_req, usetz = "Z")
    if (verbose) 
        message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
    ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
        ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
        0), nc)
    unlink(ncs0)
    nc_retry <- T
    nc_n_try <- 1
    n_max_retries
    while (nc_retry) {
        res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
            url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
                bbox[["xmax"]]), latitude = c(bbox[["ymin"]], 
                bbox[["ymax"]]), time = t_req_str, fmt = "nc", 
            store = rerddap::disk(path = dir_nc)))
        if (inherits(res, "try-error")) {
            err <- attr(res, "condition")
            msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
            nc_n_try <- nc_n_try + 1
            if (nc_n_try > n_max_retries) {
                stop(msg)
            }
            else {
                message(msg, "\nRETRYing...")
                Sys.sleep(1)
            }
        }
        else {
            nc_retry <- F
        }
    }
    i_req <- i_req + 1
}
debug: i_t_beg <- (i_req - 1) * n_t_per_req + 1
debug: i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
debug: t_req <- times_todo[c(i_t_beg, i_t_end)]
debug: t_req_str <- format_ISO8601(t_req, usetz = "Z")
debug: if (verbose) message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
debug: message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
Fetching request 1 of 1 (2023-01-01 to 2023-12-01) ~ 19:47:19 UTC
debug: ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
    0), nc)
debug: unlink(ncs0)
debug: nc_retry <- T
debug: nc_n_try <- 1
debug: n_max_retries
debug: while (nc_retry) {
    res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
        url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
            bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
        time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
    if (inherits(res, "try-error")) {
        err <- attr(res, "condition")
        msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
        nc_n_try <- nc_n_try + 1
        if (nc_n_try > n_max_retries) {
            stop(msg)
        }
        else {
            message(msg, "\nRETRYing...")
            Sys.sleep(1)
        }
    }
    else {
        nc_retry <- F
    }
}
debug: res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
    url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
        bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
    time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
debug: if (inherits(res, "try-error")) {
    err <- attr(res, "condition")
    msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
    nc_n_try <- nc_n_try + 1
    if (nc_n_try > n_max_retries) {
        stop(msg)
    }
    else {
        message(msg, "\nRETRYing...")
        Sys.sleep(1)
    }
} else {
    nc_retry <- F
}
debug: nc_retry <- F
debug: (while) nc_retry
debug: i_req <- i_req + 1
debug: (while) i_req <= n_reqs
debug: ncs <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size > 
    0), nc)
debug: r <- terra::rast(ncs)
debug: stopifnot(all(class(terra::time(r)) %in% c("POSIXct", "POSIXt")))
debug: idx <- dplyr::pull(dplyr::filter(dplyr::arrange(dplyr::tibble(idx = 1:terra::nlyr(r), 
    time = terra::time(r)), time), !duplicated(time)), idx)
debug: r <- terra::subset(r, idx)
debug: stopifnot(terra::crs(r, proj = T) == wgs84)
debug: if (mask_tif) r <- terra::mask(r, sf_zones)
debug: lyrs <- glue("{var}|{terra::time(r)}")
debug: if (length(dims_other) > 0 && !all(length(dims[dims_other]) == 
    1)) stop(glue("Other dimensions not yet supported: {paste(dims_other, collapse = ',')}"))
debug: names(r) <- lyrs
debug: if (!is.null(rast_tif)) {
    if (fs::file_exists(rast_tif)) {
        r_tmp_tif <- tempfile(fileext = ".tif")
        r_tmp <- c(rast(rast_tif), r)
        r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
        terra::writeRaster(r_tmp, r_tmp_tif)
        fs::file_delete(rast_tif)
        fs::file_move(r_tmp_tif, rast_tif)
        rm(r)
        rm(r_tmp)
    }
    else {
        terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
    }
    r <- terra::rast(rast_tif)
}
debug: if (fs::file_exists(rast_tif)) {
    r_tmp_tif <- tempfile(fileext = ".tif")
    r_tmp <- c(rast(rast_tif), r)
    r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
    terra::writeRaster(r_tmp, r_tmp_tif)
    fs::file_delete(rast_tif)
    fs::file_move(r_tmp_tif, rast_tif)
    rm(r)
    rm(r_tmp)
} else {
    terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
}
debug: terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
debug: r <- terra::rast(rast_tif)
debug: d_r <- mutate(tidyr::pivot_longer(sf::st_drop_geometry(sf::st_as_sf(terra::zonal(x = r, 
    z = terra::vect(dplyr::select(sf_zones, dplyr::all_of(fld_zones))), 
    fun = zonal_fun, exact = T, na.rm = T, as.polygons = T))), 
    cols = -dplyr::any_of(fld_zones), names_to = "lyr", values_to = zonal_fun), 
    time = readr::parse_datetime(str_replace(lyr, glue("{var}\\|(.*)"), 
        "\\1")))
debug: if (!is.null(zonal_csv)) write_csv(d_r, zonal_csv)
debug: write_csv(d_r, zonal_csv)
debug: if (!keep_nc) unlink(dir_nc, recursive = T)
debug: unlink(dir_nc, recursive = T)
debug: return(d_r)
Downloading 1 requests, up to 166 time slices each
Called from: extractr::ed_extract(ed, var = v, sf_zones = ply, bbox = bb, 
    mask_tif = F, rast_tif = glue("{dir_out}/{nms}/{yr}.tif"), 
    zonal_fun = "mean", zonal_csv = glue("{dir_out}/{nms}/{yr}.csv"), 
    dir_nc = glue("{dir_out}/{nms}/{yr}_nc"), keep_nc = F, n_max_vals_per_req = 1e+05, 
    time_min = time_min, time_max = time_max, verbose = T)
debug: while (i_req <= n_reqs) {
    i_t_beg <- (i_req - 1) * n_t_per_req + 1
    i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
    t_req <- times_todo[c(i_t_beg, i_t_end)]
    t_req_str <- format_ISO8601(t_req, usetz = "Z")
    if (verbose) 
        message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
    ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
        ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
        0), nc)
    unlink(ncs0)
    nc_retry <- T
    nc_n_try <- 1
    n_max_retries
    while (nc_retry) {
        res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
            url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
                bbox[["xmax"]]), latitude = c(bbox[["ymin"]], 
                bbox[["ymax"]]), time = t_req_str, fmt = "nc", 
            store = rerddap::disk(path = dir_nc)))
        if (inherits(res, "try-error")) {
            err <- attr(res, "condition")
            msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
            nc_n_try <- nc_n_try + 1
            if (nc_n_try > n_max_retries) {
                stop(msg)
            }
            else {
                message(msg, "\nRETRYing...")
                Sys.sleep(1)
            }
        }
        else {
            nc_retry <- F
        }
    }
    i_req <- i_req + 1
}
debug: i_t_beg <- (i_req - 1) * n_t_per_req + 1
debug: i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
debug: t_req <- times_todo[c(i_t_beg, i_t_end)]
debug: t_req_str <- format_ISO8601(t_req, usetz = "Z")
debug: if (verbose) message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
debug: message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
Fetching request 1 of 1 (2024-01-01 to 2024-12-01) ~ 19:47:23 UTC
debug: ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
    0), nc)
debug: unlink(ncs0)
debug: nc_retry <- T
debug: nc_n_try <- 1
debug: n_max_retries
debug: while (nc_retry) {
    res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
        url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
            bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
        time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
    if (inherits(res, "try-error")) {
        err <- attr(res, "condition")
        msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
        nc_n_try <- nc_n_try + 1
        if (nc_n_try > n_max_retries) {
            stop(msg)
        }
        else {
            message(msg, "\nRETRYing...")
            Sys.sleep(1)
        }
    }
    else {
        nc_retry <- F
    }
}
debug: res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
    url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
        bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
    time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
debug: if (inherits(res, "try-error")) {
    err <- attr(res, "condition")
    msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
    nc_n_try <- nc_n_try + 1
    if (nc_n_try > n_max_retries) {
        stop(msg)
    }
    else {
        message(msg, "\nRETRYing...")
        Sys.sleep(1)
    }
} else {
    nc_retry <- F
}
debug: nc_retry <- F
debug: (while) nc_retry
debug: i_req <- i_req + 1
debug: (while) i_req <= n_reqs
debug: ncs <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size > 
    0), nc)
debug: r <- terra::rast(ncs)
debug: stopifnot(all(class(terra::time(r)) %in% c("POSIXct", "POSIXt")))
debug: idx <- dplyr::pull(dplyr::filter(dplyr::arrange(dplyr::tibble(idx = 1:terra::nlyr(r), 
    time = terra::time(r)), time), !duplicated(time)), idx)
debug: r <- terra::subset(r, idx)
debug: stopifnot(terra::crs(r, proj = T) == wgs84)
debug: if (mask_tif) r <- terra::mask(r, sf_zones)
debug: lyrs <- glue("{var}|{terra::time(r)}")
debug: if (length(dims_other) > 0 && !all(length(dims[dims_other]) == 
    1)) stop(glue("Other dimensions not yet supported: {paste(dims_other, collapse = ',')}"))
debug: names(r) <- lyrs
debug: if (!is.null(rast_tif)) {
    if (fs::file_exists(rast_tif)) {
        r_tmp_tif <- tempfile(fileext = ".tif")
        r_tmp <- c(rast(rast_tif), r)
        r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
        terra::writeRaster(r_tmp, r_tmp_tif)
        fs::file_delete(rast_tif)
        fs::file_move(r_tmp_tif, rast_tif)
        rm(r)
        rm(r_tmp)
    }
    else {
        terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
    }
    r <- terra::rast(rast_tif)
}
debug: if (fs::file_exists(rast_tif)) {
    r_tmp_tif <- tempfile(fileext = ".tif")
    r_tmp <- c(rast(rast_tif), r)
    r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
    terra::writeRaster(r_tmp, r_tmp_tif)
    fs::file_delete(rast_tif)
    fs::file_move(r_tmp_tif, rast_tif)
    rm(r)
    rm(r_tmp)
} else {
    terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
}
debug: terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
debug: r <- terra::rast(rast_tif)
debug: d_r <- mutate(tidyr::pivot_longer(sf::st_drop_geometry(sf::st_as_sf(terra::zonal(x = r, 
    z = terra::vect(dplyr::select(sf_zones, dplyr::all_of(fld_zones))), 
    fun = zonal_fun, exact = T, na.rm = T, as.polygons = T))), 
    cols = -dplyr::any_of(fld_zones), names_to = "lyr", values_to = zonal_fun), 
    time = readr::parse_datetime(str_replace(lyr, glue("{var}\\|(.*)"), 
        "\\1")))
debug: if (!is.null(zonal_csv)) write_csv(d_r, zonal_csv)
debug: write_csv(d_r, zonal_csv)
debug: if (!keep_nc) unlink(dir_nc, recursive = T)
debug: unlink(dir_nc, recursive = T)
debug: return(d_r)
Downloading 1 requests, up to 166 time slices each
Called from: extractr::ed_extract(ed, var = v, sf_zones = ply, bbox = bb, 
    mask_tif = F, rast_tif = glue("{dir_out}/{nms}/{yr}.tif"), 
    zonal_fun = "mean", zonal_csv = glue("{dir_out}/{nms}/{yr}.csv"), 
    dir_nc = glue("{dir_out}/{nms}/{yr}_nc"), keep_nc = F, n_max_vals_per_req = 1e+05, 
    time_min = time_min, time_max = time_max, verbose = T)
debug: while (i_req <= n_reqs) {
    i_t_beg <- (i_req - 1) * n_t_per_req + 1
    i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
    t_req <- times_todo[c(i_t_beg, i_t_end)]
    t_req_str <- format_ISO8601(t_req, usetz = "Z")
    if (verbose) 
        message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
    ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
        ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
        0), nc)
    unlink(ncs0)
    nc_retry <- T
    nc_n_try <- 1
    n_max_retries
    while (nc_retry) {
        res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
            url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
                bbox[["xmax"]]), latitude = c(bbox[["ymin"]], 
                bbox[["ymax"]]), time = t_req_str, fmt = "nc", 
            store = rerddap::disk(path = dir_nc)))
        if (inherits(res, "try-error")) {
            err <- attr(res, "condition")
            msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
            nc_n_try <- nc_n_try + 1
            if (nc_n_try > n_max_retries) {
                stop(msg)
            }
            else {
                message(msg, "\nRETRYing...")
                Sys.sleep(1)
            }
        }
        else {
            nc_retry <- F
        }
    }
    i_req <- i_req + 1
}
debug: i_t_beg <- (i_req - 1) * n_t_per_req + 1
debug: i_t_end <- min(c(i_t_beg + n_t_per_req - 1, n_t))
debug: t_req <- times_todo[c(i_t_beg, i_t_end)]
debug: t_req_str <- format_ISO8601(t_req, usetz = "Z")
debug: if (verbose) message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
debug: message(glue("Fetching request {i_req} of {n_reqs} ({paste(as.Date(t_req), collapse = ' to ')}) ~ {format(Sys.time(), '%H:%M:%S %Z')}"))
Fetching request 1 of 1 (2025-01-01 to 2025-07-01) ~ 19:47:27 UTC
debug: ncs0 <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size == 
    0), nc)
debug: unlink(ncs0)
debug: nc_retry <- T
debug: nc_n_try <- 1
debug: n_max_retries
debug: while (nc_retry) {
    res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
        url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
            bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
        time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
    if (inherits(res, "try-error")) {
        err <- attr(res, "condition")
        msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
        nc_n_try <- nc_n_try + 1
        if (nc_n_try > n_max_retries) {
            stop(msg)
        }
        else {
            message(msg, "\nRETRYing...")
            Sys.sleep(1)
        }
    }
    else {
        nc_retry <- F
    }
}
debug: res <- try(rerddap::griddap(datasetx = attr(ed, "datasetid"), 
    url = ed$base_url, fields = var, longitude = c(bbox[["xmin"]], 
        bbox[["xmax"]]), latitude = c(bbox[["ymin"]], bbox[["ymax"]]), 
    time = t_req_str, fmt = "nc", store = rerddap::disk(path = dir_nc)))
debug: if (inherits(res, "try-error")) {
    err <- attr(res, "condition")
    msg <- glue::glue("  ERROR in calling {err$call}:\n {err$message}")
    nc_n_try <- nc_n_try + 1
    if (nc_n_try > n_max_retries) {
        stop(msg)
    }
    else {
        message(msg, "\nRETRYing...")
        Sys.sleep(1)
    }
} else {
    nc_retry <- F
}
debug: nc_retry <- F
debug: (while) nc_retry
debug: i_req <- i_req + 1
debug: (while) i_req <= n_reqs
debug: ncs <- dplyr::pull(dplyr::filter(dplyr::tibble(nc = list.files(dir_nc, 
    ".*\\.nc$", full.names = T), size = file.size(nc)), size > 
    0), nc)
debug: r <- terra::rast(ncs)
debug: stopifnot(all(class(terra::time(r)) %in% c("POSIXct", "POSIXt")))
debug: idx <- dplyr::pull(dplyr::filter(dplyr::arrange(dplyr::tibble(idx = 1:terra::nlyr(r), 
    time = terra::time(r)), time), !duplicated(time)), idx)
debug: r <- terra::subset(r, idx)
debug: stopifnot(terra::crs(r, proj = T) == wgs84)
debug: if (mask_tif) r <- terra::mask(r, sf_zones)
debug: lyrs <- glue("{var}|{terra::time(r)}")
debug: if (length(dims_other) > 0 && !all(length(dims[dims_other]) == 
    1)) stop(glue("Other dimensions not yet supported: {paste(dims_other, collapse = ',')}"))
debug: names(r) <- lyrs
debug: if (!is.null(rast_tif)) {
    if (fs::file_exists(rast_tif)) {
        r_tmp_tif <- tempfile(fileext = ".tif")
        r_tmp <- c(rast(rast_tif), r)
        r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
        terra::writeRaster(r_tmp, r_tmp_tif)
        fs::file_delete(rast_tif)
        fs::file_move(r_tmp_tif, rast_tif)
        rm(r)
        rm(r_tmp)
    }
    else {
        terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
    }
    r <- terra::rast(rast_tif)
}
debug: if (fs::file_exists(rast_tif)) {
    r_tmp_tif <- tempfile(fileext = ".tif")
    r_tmp <- c(rast(rast_tif), r)
    r_tmp <- terra::subset(r_tmp, which(!duplicated(names(r_tmp))))
    terra::writeRaster(r_tmp, r_tmp_tif)
    fs::file_delete(rast_tif)
    fs::file_move(r_tmp_tif, rast_tif)
    rm(r)
    rm(r_tmp)
} else {
    terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
}
debug: terra::writeRaster(r, rast_tif, overwrite = T, gdal = c("COMPRESS=DEFLATE"))
debug: r <- terra::rast(rast_tif)
debug: d_r <- mutate(tidyr::pivot_longer(sf::st_drop_geometry(sf::st_as_sf(terra::zonal(x = r, 
    z = terra::vect(dplyr::select(sf_zones, dplyr::all_of(fld_zones))), 
    fun = zonal_fun, exact = T, na.rm = T, as.polygons = T))), 
    cols = -dplyr::any_of(fld_zones), names_to = "lyr", values_to = zonal_fun), 
    time = readr::parse_datetime(str_replace(lyr, glue("{var}\\|(.*)"), 
        "\\1")))
debug: if (!is.null(zonal_csv)) write_csv(d_r, zonal_csv)
debug: write_csv(d_r, zonal_csv)
debug: if (!keep_nc) unlink(dir_nc, recursive = T)
debug: unlink(dir_nc, recursive = T)
debug: return(d_r)

4.1 Successes

Code
res |> 
  mutate(
    success = is.na(error)) |> 
  group_by(success) |> 
  summarize(
    n = n()) |> 
  datatable()

4.2 Errors (if any)

Code
# rast(glue("{dir_out}/{nms}/{yr}.tif")) |> names()

res |> 
  filter(!is.na(error)) |> 
  group_by(nms) |> 
  summarize(
    n_years = n(),
    errors  = unique(error) |> paste(collapse = "\n\n----\n\n")) |> 
  datatable()
Code
devtools::session_info()
─ Session info ───────────────────────────────────────────────────────────────
 setting  value
 version  R version 4.4.2 (2024-10-31)
 os       Ubuntu 24.04.1 LTS
 system   x86_64, linux-gnu
 ui       X11
 language (EN)
 collate  en_US.UTF-8
 ctype    en_US.UTF-8
 tz       Etc/UTC
 date     2026-01-08
 pandoc   3.5 @ /usr/bin/ (via rmarkdown)

─ Packages ───────────────────────────────────────────────────────────────────
 package           * version date (UTC) lib source
 base64enc           0.1-3   2015-07-28 [1] RSPM (R 4.4.0)
 bit                 4.6.0   2025-03-06 [1] RSPM (R 4.4.0)
 bit64               4.6.0-1 2025-01-16 [1] RSPM (R 4.4.0)
 brew                1.0-10  2023-12-16 [1] RSPM (R 4.4.0)
 bslib               0.9.0   2025-01-30 [1] RSPM (R 4.4.0)
 cachem              1.1.0   2024-05-16 [1] RSPM (R 4.4.0)
 class               7.3-22  2023-05-03 [2] CRAN (R 4.4.2)
 classInt            0.4-11  2025-01-08 [1] RSPM (R 4.4.0)
 cli                 3.6.5   2025-04-23 [1] RSPM (R 4.4.0)
 codetools           0.2-20  2024-03-31 [2] CRAN (R 4.4.2)
 crayon              1.5.3   2024-06-20 [1] RSPM (R 4.4.0)
 crosstalk           1.2.2   2025-08-26 [1] RSPM (R 4.4.0)
 crul                1.6.0   2025-07-23 [1] RSPM (R 4.4.0)
 curl                7.0.0   2025-08-19 [1] RSPM (R 4.4.0)
 data.table          1.18.0  2025-12-24 [1] RSPM (R 4.4.0)
 DBI                 1.2.3   2024-06-02 [1] RSPM (R 4.4.0)
 deldir              2.0-4   2024-02-28 [1] RSPM (R 4.4.0)
 devtools            2.4.5   2022-10-11 [1] RSPM (R 4.4.0)
 dichromat           2.0-0.1 2022-05-02 [1] RSPM (R 4.4.0)
 digest              0.6.39  2025-11-19 [1] RSPM (R 4.4.0)
 dplyr             * 1.1.4   2023-11-17 [1] RSPM (R 4.4.0)
 DT                * 0.33    2024-04-04 [1] RSPM (R 4.4.0)
 dygraphs            1.1.1.6 2018-07-11 [1] RSPM (R 4.4.0)
 e1071               1.7-17  2025-12-18 [1] RSPM (R 4.4.0)
 ellipsis            0.3.2   2021-04-29 [1] RSPM (R 4.4.0)
 evaluate            1.0.5   2025-08-27 [1] RSPM (R 4.4.0)
 extractr          * 0.1.9   2026-01-08 [1] Github (marinebon/extractr@b5dda6c)
 farver              2.1.2   2024-05-13 [1] RSPM (R 4.4.0)
 fastmap             1.2.0   2024-05-15 [1] RSPM (R 4.4.0)
 fs                * 1.6.6   2025-04-12 [1] RSPM (R 4.4.0)
 generics            0.1.4   2025-05-09 [1] RSPM (R 4.4.0)
 glue              * 1.8.0   2024-09-30 [1] RSPM (R 4.4.0)
 here              * 1.0.2   2025-09-15 [1] RSPM (R 4.4.0)
 hms                 1.1.4   2025-10-17 [1] RSPM (R 4.4.0)
 hoardr              0.5.5   2025-01-18 [1] RSPM (R 4.4.0)
 htmltools           0.5.9   2025-12-04 [1] RSPM (R 4.4.0)
 htmlwidgets         1.6.4   2023-12-06 [1] RSPM (R 4.4.0)
 httpcode            0.3.0   2020-04-10 [1] RSPM (R 4.4.0)
 httpuv              1.6.16  2025-04-16 [1] RSPM (R 4.4.0)
 jquerylib           0.1.4   2021-04-26 [1] RSPM (R 4.4.0)
 jsonlite            2.0.0   2025-03-27 [1] RSPM (R 4.4.0)
 KernSmooth          2.23-24 2024-05-17 [2] CRAN (R 4.4.2)
 knitr               1.51    2025-12-20 [1] RSPM (R 4.4.0)
 later               1.4.4   2025-08-27 [1] RSPM (R 4.4.0)
 lattice             0.22-6  2024-03-20 [2] CRAN (R 4.4.2)
 leafem              0.2.5   2025-08-28 [1] RSPM (R 4.4.0)
 leaflet             2.2.3   2025-09-04 [1] RSPM (R 4.4.0)
 leaflet.providers   2.0.0   2023-10-17 [1] RSPM (R 4.4.0)
 leafpop             0.1.0   2021-05-22 [1] RSPM (R 4.4.0)
 librarian           1.8.1   2021-07-12 [1] RSPM (R 4.4.0)
 lifecycle           1.0.4   2023-11-07 [1] RSPM (R 4.4.0)
 logger            * 0.4.0   2024-10-22 [1] RSPM (R 4.4.0)
 lubridate         * 1.9.4   2024-12-08 [1] RSPM (R 4.4.0)
 magrittr            2.0.4   2025-09-12 [1] RSPM (R 4.4.0)
 mapview           * 2.11.4  2025-09-08 [1] RSPM (R 4.4.0)
 Matrix              1.7-1   2024-10-18 [2] CRAN (R 4.4.2)
 memoise             2.0.1   2021-11-26 [1] RSPM (R 4.4.0)
 mime                0.13    2025-03-17 [1] RSPM (R 4.4.0)
 miniUI              0.1.1.1 2018-05-18 [1] RSPM (R 4.4.0)
 ncdf4               1.24    2025-03-25 [1] RSPM (R 4.4.0)
 otel                0.2.0   2025-08-29 [1] RSPM (R 4.4.0)
 pillar              1.11.1  2025-09-17 [1] RSPM (R 4.4.0)
 pkgbuild            1.4.5   2024-10-28 [1] RSPM (R 4.4.0)
 pkgconfig           2.0.3   2019-09-22 [1] RSPM (R 4.4.0)
 pkgload             1.4.0   2024-06-28 [1] RSPM (R 4.4.0)
 png                 0.1-8   2022-11-29 [1] RSPM (R 4.4.0)
 polyclip            1.10-7  2024-07-23 [1] RSPM (R 4.4.0)
 profvis             0.4.0   2024-09-20 [1] RSPM (R 4.4.0)
 promises            1.5.0   2025-11-01 [1] RSPM (R 4.4.0)
 proxy               0.4-29  2025-12-29 [1] RSPM (R 4.4.0)
 purrr             * 1.2.0   2025-11-04 [1] RSPM (R 4.4.0)
 R.methodsS3         1.8.2   2022-06-13 [1] RSPM (R 4.4.0)
 R.oo                1.27.1  2025-05-02 [1] RSPM (R 4.4.0)
 R.utils             2.13.0  2025-02-24 [1] RSPM (R 4.4.0)
 R6                  2.6.1   2025-02-15 [1] RSPM (R 4.4.0)
 rappdirs            0.3.3   2021-01-31 [1] RSPM (R 4.4.0)
 raster              3.6-32  2025-03-28 [1] RSPM (R 4.4.0)
 RColorBrewer      * 1.1-3   2022-04-03 [1] RSPM (R 4.4.0)
 Rcpp                1.1.0   2025-07-02 [1] RSPM (R 4.4.0)
 readr             * 2.1.6   2025-11-14 [1] RSPM (R 4.4.0)
 remotes             2.5.0   2024-03-17 [1] RSPM (R 4.4.0)
 rerddap             1.2.1   2025-03-19 [1] RSPM (R 4.4.0)
 rlang               1.1.6   2025-04-11 [1] RSPM (R 4.4.0)
 rmarkdown           2.30    2025-09-28 [1] RSPM (R 4.4.0)
 rprojroot           2.1.1   2025-08-26 [1] RSPM (R 4.4.0)
 rstudioapi          0.17.1  2024-10-22 [1] RSPM (R 4.4.0)
 s2                  1.1.9   2025-05-23 [1] RSPM (R 4.4.0)
 sass                0.4.10  2025-04-11 [1] RSPM (R 4.4.0)
 satellite           1.0.6   2025-08-21 [1] RSPM (R 4.4.0)
 scales              1.4.0   2025-04-24 [1] RSPM (R 4.4.0)
 sessioninfo         1.2.2   2021-12-06 [1] RSPM (R 4.4.0)
 sf                * 1.0-23  2025-11-28 [1] RSPM (R 4.4.0)
 shiny               1.10.0  2024-12-14 [1] RSPM (R 4.4.0)
 sp                  2.2-0   2025-02-01 [1] RSPM (R 4.4.0)
 spatstat.data       3.1-9   2025-10-18 [1] RSPM (R 4.4.0)
 spatstat.geom       3.6-1   2025-11-20 [1] RSPM (R 4.4.0)
 spatstat.univar     3.1-5   2025-11-17 [1] RSPM (R 4.4.0)
 spatstat.utils      3.2-0   2025-09-20 [1] RSPM (R 4.4.0)
 stringi             1.8.7   2025-03-27 [1] RSPM (R 4.4.0)
 stringr           * 1.6.0   2025-11-04 [1] RSPM (R 4.4.0)
 svglite             2.2.2   2025-10-21 [1] RSPM (R 4.4.0)
 systemfonts         1.3.1   2025-10-01 [1] RSPM (R 4.4.0)
 tabularaster        0.7.2   2023-11-01 [1] RSPM (R 4.4.0)
 terra             * 1.8-86  2025-11-28 [1] RSPM (R 4.4.0)
 textshaping         1.0.4   2025-10-10 [1] RSPM (R 4.4.0)
 tibble            * 3.3.0   2025-06-08 [1] RSPM (R 4.4.0)
 tidyr             * 1.3.2   2025-12-19 [1] RSPM (R 4.4.0)
 tidyselect          1.2.1   2024-03-11 [1] RSPM (R 4.4.0)
 timechange          0.3.0   2024-01-18 [1] RSPM (R 4.4.0)
 triebeard           0.4.1   2023-03-04 [1] RSPM (R 4.4.0)
 tzdb                0.5.0   2025-03-15 [1] RSPM (R 4.4.0)
 units             * 1.0-0   2025-10-09 [1] RSPM (R 4.4.0)
 urlchecker          1.0.1   2021-11-30 [1] RSPM (R 4.4.0)
 urltools            1.7.3.1 2025-06-12 [1] RSPM (R 4.4.0)
 usethis             3.1.0   2024-11-26 [1] RSPM (R 4.4.0)
 uuid                1.2-1   2024-07-29 [1] RSPM (R 4.4.0)
 vctrs               0.6.5   2023-12-01 [1] RSPM (R 4.4.0)
 vroom               1.6.7   2025-11-28 [1] RSPM (R 4.4.0)
 withr               3.0.2   2024-10-28 [1] RSPM (R 4.4.0)
 wk                  0.9.5   2025-12-18 [1] RSPM (R 4.4.0)
 xfun                0.55    2025-12-16 [1] RSPM (R 4.4.0)
 xml2                1.5.1   2025-12-01 [1] RSPM (R 4.4.0)
 xtable              1.8-4   2019-04-21 [1] RSPM (R 4.4.0)
 xts                 0.14.1  2024-10-15 [1] RSPM (R 4.4.0)
 yaml              * 2.3.12  2025-12-10 [1] RSPM (R 4.4.0)
 zoo                 1.8-15  2025-12-15 [1] RSPM (R 4.4.0)

 [1] /usr/local/lib/R/site-library
 [2] /usr/local/lib/R/library

──────────────────────────────────────────────────────────────────────────────